summaryrefslogtreecommitdiff
path: root/core/src
diff options
context:
space:
mode:
Diffstat (limited to 'core/src')
-rw-r--r--core/src/test/scala/mill/util/TestEvaluator.scala29
1 files changed, 29 insertions, 0 deletions
diff --git a/core/src/test/scala/mill/util/TestEvaluator.scala b/core/src/test/scala/mill/util/TestEvaluator.scala
new file mode 100644
index 00000000..5d16de43
--- /dev/null
+++ b/core/src/test/scala/mill/util/TestEvaluator.scala
@@ -0,0 +1,29 @@
+package mill.util
+
+import ammonite.ops.Path
+import mill.define.{Target, Task}
+import mill.discover.{Discovered, Mirror}
+import mill.eval.{Evaluator, Result}
+
+class TestEvaluator(mapping: Discovered.Mapping[_], workspacePath: Path){
+ val evaluator = new Evaluator(workspacePath, mapping, DummyLogger)
+
+ def apply[T](t: Task[T]): Either[Result.Failing, (T, Int)] = {
+ val evaluated = evaluator.evaluate(OSet(t))
+
+ if (evaluated.failing.keyCount == 0) {
+ Right(
+ Tuple2(
+ evaluated.rawValues.head.asInstanceOf[Result.Success[T]].value,
+ evaluated.evaluated.collect {
+ case t: Target[_] if mapping.targets.contains(t) => t
+ case t: mill.define.Command[_] => t
+ }.size
+ ))
+ } else {
+ Left(
+ evaluated.failing.lookupKey(evaluated.failing.keys().next).items.next())
+ }
+ }
+
+}