diff options
Diffstat (limited to 'core/test/src/mill/util/TestEvaluator.scala')
-rw-r--r-- | core/test/src/mill/util/TestEvaluator.scala | 38 |
1 files changed, 35 insertions, 3 deletions
diff --git a/core/test/src/mill/util/TestEvaluator.scala b/core/test/src/mill/util/TestEvaluator.scala index 41830d48..3b34e27d 100644 --- a/core/test/src/mill/util/TestEvaluator.scala +++ b/core/test/src/mill/util/TestEvaluator.scala @@ -1,19 +1,24 @@ package mill.util -import ammonite.ops.Path +import ammonite.ops.{Path, pwd} import mill.define.Discover.applyImpl import mill.define.{Discover, Input, Target, Task} import mill.eval.{Evaluator, Result} import mill.util.Strict.Agg +import utest.assert + import language.experimental.macros object TestEvaluator{ implicit def implicitDisover[T]: Discover[T] = macro applyImpl[T] + val externalBasePath = pwd / 'target / 'external } class TestEvaluator[T <: TestUtil.TestBuild](module: T, workspacePath: Path, basePath: Path) (implicit discover: Discover[T]){ - val evaluator = new Evaluator(workspacePath, basePath, module, discover, DummyLogger) + val evaluator = new Evaluator( + workspacePath, basePath, TestEvaluator.externalBasePath, module, discover, DummyLogger + ) // val evaluator = new Evaluator(workspacePath, basePath, module, discover, 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)) @@ -23,7 +28,9 @@ class TestEvaluator[T <: TestUtil.TestBuild](module: T, 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: Target[_] + if module.millInternal.targets.contains(t) + && !t.isInstanceOf[Input[_]] => t case t: mill.define.Command[_] => t }.size )) @@ -33,4 +40,29 @@ class TestEvaluator[T <: TestUtil.TestBuild](module: T, } } + def fail(target: Target[_], expectedFailCount: Int, expectedRawValues: Seq[Result[_]]) = { + + val res = evaluator.evaluate(Agg(target)) + + val cleaned = res.rawValues.map{ + case Result.Exception(ex, _) => Result.Exception(ex, Nil) + case x => x + } + + assert( + cleaned == expectedRawValues, + res.failing.keyCount == expectedFailCount + ) + + } + + def check(targets: Agg[Task[_]], expected: Agg[Task[_]]) = { + val evaluated = evaluator.evaluate(targets) + .evaluated + .flatMap(_.asTarget) + .filter(module.millInternal.targets.contains) + .filter(!_.isInstanceOf[Input[_]]) + assert(evaluated == expected) + } + } |