diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2018-02-09 00:14:47 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2018-02-09 08:17:47 -0800 |
commit | 8ddd2fa054bc8639c28db2e95b7903e2954fdb7d (patch) | |
tree | aa985f1e715f07eb279e6facad61de8a187e316c /main/test/src/mill/util/TestEvaluator.scala | |
parent | 90d0a3388d280554eaa51371f666d2f7a965a8af (diff) | |
download | mill-8ddd2fa054bc8639c28db2e95b7903e2954fdb7d.tar.gz mill-8ddd2fa054bc8639c28db2e95b7903e2954fdb7d.tar.bz2 mill-8ddd2fa054bc8639c28db2e95b7903e2954fdb7d.zip |
.
Diffstat (limited to 'main/test/src/mill/util/TestEvaluator.scala')
-rw-r--r-- | main/test/src/mill/util/TestEvaluator.scala | 83 |
1 files changed, 83 insertions, 0 deletions
diff --git a/main/test/src/mill/util/TestEvaluator.scala b/main/test/src/mill/util/TestEvaluator.scala new file mode 100644 index 00000000..a5be0488 --- /dev/null +++ b/main/test/src/mill/util/TestEvaluator.scala @@ -0,0 +1,83 @@ +package mill.util + +import ammonite.ops.{Path, pwd} +import mill.define.Discover.applyImpl +import mill.define.{Discover, Input, Target, Task} +import mill.eval.Result.OuterStack +import mill.eval.{Evaluator, Result} +import mill.util.Strict.Agg +import utest.assert +import utest.framework.TestPath + +import language.experimental.macros +object TestEvaluator{ + implicit def implicitDisover[T]: Discover[T] = macro applyImpl[T] + val externalOutPath = pwd / 'target / 'external + + + def static[T <: TestUtil.BaseModule](module: T) + (implicit discover: Discover[T], + fullName: sourcecode.FullName) = { + new TestEvaluator[T](module)(discover, fullName, TestPath(Nil)) + } +} + +class TestEvaluator[T <: TestUtil.BaseModule](module: T) + (implicit discover: Discover[T], + fullName: sourcecode.FullName, + tp: TestPath){ + val outPath = TestUtil.getOutPath() + + val logger = DummyLogger +// val logger = new PrintLogger(true, ammonite.util.Colors.Default, System.out, System.out, System.err) + val evaluator = new Evaluator(outPath, TestEvaluator.externalOutPath, module, discover, logger) + + def apply[T](t: Task[T]): Either[Result.Failing[T], (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.ctx.external => t + case t: mill.define.Command[_] => t + }.size + )) + } else { + Left( + evaluated.failing.lookupKey(evaluated.failing.keys().next).items.next() + .asInstanceOf[Result.Failing[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, new OuterStack(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) + } + +} |