summaryrefslogtreecommitdiff
path: root/core/test/src/mill/util/TestEvaluator.scala
blob: 10483aae237a43d55de348127c9c07c2f1afb31f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package mill.util

import ammonite.ops.Path
import mill.define.{Discover, Input, Target, Task}
import mill.eval.{Evaluator, Result}
import mill.util.Strict.Agg
class TestEvaluator(module: mill.Module,
                    discover: Discover,
                    workspacePath: Path,
                    basePath: Path){
  val evaluator = new Evaluator(workspacePath, basePath, module, discover, DummyLogger)
  //val evaluator = new Evaluator(workspacePath, basePath, module, new PrintLogger(true, ammonite.util.Colors.Default, System.out, System.out, System.err))
  def apply[T](t: Task[T]): Either[Result.Failing, (T, Int)] = {
    val evaluated = evaluator.evaluate(Agg(t))

    if (evaluated.failing.keyCount == 0) {
      Right(
        Tuple2(
          evaluated.rawValues.head.asInstanceOf[Result.Success[T]].value,
          evaluated.evaluated.collect {
            case t: Target[_] if module.millInternal.targets.contains(t) && !t.isInstanceOf[Input[_]] => t
            case t: mill.define.Command[_]           => t
          }.size
        ))
    } else {
      Left(
        evaluated.failing.lookupKey(evaluated.failing.keys().next).items.next())
    }
  }

}