diff options
Diffstat (limited to 'core/src/test')
5 files changed, 58 insertions, 39 deletions
diff --git a/core/src/test/scala/mill/define/MacroErrorTests.scala b/core/src/test/scala/mill/define/MacroErrorTests.scala index b0d687fe..7fc79f62 100644 --- a/core/src/test/scala/mill/define/MacroErrorTests.scala +++ b/core/src/test/scala/mill/define/MacroErrorTests.scala @@ -72,7 +72,7 @@ object MacroErrorTests extends TestSuite{ def down = T{ TestUtil.test(left, right) } } """) - assert(borkedCachedDiamond1.msg.contains("must be defs")) + assert(borkedCachedDiamond1.msg.contains("required: mill.Module")) } } } diff --git a/core/src/test/scala/mill/discover/DiscoveredTests.scala b/core/src/test/scala/mill/discover/DiscoveredTests.scala index 0f73074f..31d6119e 100644 --- a/core/src/test/scala/mill/discover/DiscoveredTests.scala +++ b/core/src/test/scala/mill/discover/DiscoveredTests.scala @@ -49,7 +49,7 @@ object DiscoveredTests extends TestSuite{ } 'commands - { - object outer { + object outer extends mill.Module{ def hello() = T.command{ println("Hello") } @@ -89,14 +89,15 @@ object DiscoveredTests extends TestSuite{ 'compileError - { 'unserializableTarget - { + object outer extends Module { - def single = mill.T{ new InputStreamReader(System.in) } + val error = compileError("def single = mill.T{ new InputStreamReader(System.in) }") } - val error = compileError("Discovered.make[outer.type]") + assert( - error.msg.contains("uPickle does not know how to read"), - error.pos.contains("def single = mill.T{ new InputStreamReader(System.in) }") + outer.error.msg.contains("uPickle does not know how to read"), + outer.error.pos.contains("def single = mill.T{ new InputStreamReader(System.in) }") ) } diff --git a/core/src/test/scala/mill/eval/EvaluationTests.scala b/core/src/test/scala/mill/eval/EvaluationTests.scala index 8b13987b..2b40724a 100644 --- a/core/src/test/scala/mill/eval/EvaluationTests.scala +++ b/core/src/test/scala/mill/eval/EvaluationTests.scala @@ -209,7 +209,7 @@ object EvaluationTests extends TestSuite{ var leftCount = 0 var rightCount = 0 var middleCount = 0 - def up = T{ test() } + def up = T{ test.anon() } def left = T.task{ leftCount += 1; up() + 1 } def middle = T.task{ middleCount += 1; 100 } def right = T{ rightCount += 1; 10000 } diff --git a/core/src/test/scala/mill/util/TestGraphs.scala b/core/src/test/scala/mill/util/TestGraphs.scala index a69221da..86d331bb 100644 --- a/core/src/test/scala/mill/util/TestGraphs.scala +++ b/core/src/test/scala/mill/util/TestGraphs.scala @@ -15,20 +15,20 @@ import mill.{Module, T} */ class TestGraphs(){ // single - object singleton { + object singleton extends Module{ val single = test() } // up---down - object pair { + object pair extends Module { val up = test() val down = test(up) } // up---o---down - object anonTriple{ + object anonTriple extends Module{ val up = test() - val down = test(test(up)) + val down = test(test.anon(up)) } // left @@ -36,7 +36,7 @@ class TestGraphs(){ // up down // \ / // right - object diamond{ + object diamond extends Module{ val up = test() val left = test(up) val right = test(up) @@ -48,9 +48,9 @@ class TestGraphs(){ // up down // \ / // o - object anonDiamond{ + object anonDiamond extends Module{ val up = test() - val down = test(test(up), test(up)) + val down = test(test.anon(up), test.anon(up)) } object defCachedDiamond extends Module{ @@ -68,7 +68,7 @@ class TestGraphs(){ def down = test(left, right) } - object borkedCachedDiamond3 { + object borkedCachedDiamond3 extends Module { def up = test() def left = test(up) def right = test(up) @@ -86,22 +86,22 @@ class TestGraphs(){ // o o---F---o // / / // o--B o - object bigSingleTerminal{ - val a = test(test(), test()) - val b = test(test()) + object bigSingleTerminal extends Module{ + val a = test(test.anon(), test.anon()) + val b = test(test.anon()) val e = { - val c = test(a) - val d = test(a) - test(test(test(), test(c)), test(test(c, test(d, b)))) + val c = test.anon(a) + val d = test.anon(a) + test(test.anon(test.anon(), test.anon(c)), test.anon(test.anon(c, test.anon(d, b)))) } - val f = test(test(test(), test(e))) + val f = test(test.anon(test.anon(), test.anon(e))) val i = { - val g = test() - val h = test(g, e) - test(test(g), test(test(h))) + val g = test.anon() + val h = test.anon(g, e) + test(test.anon(g), test.anon(test.anon(h))) } - val j = test(test(i), test(i, f), test(f)) + val j = test(test.anon(i), test.anon(i, f), test.anon(f)) } } object TestGraphs{ diff --git a/core/src/test/scala/mill/util/TestUtil.scala b/core/src/test/scala/mill/util/TestUtil.scala index a456b22b..8adbc87a 100644 --- a/core/src/test/scala/mill/util/TestUtil.scala +++ b/core/src/test/scala/mill/util/TestUtil.scala @@ -1,34 +1,52 @@ package mill.util -import mill.define.{Target, Task} +import mill.define.{Caller, Target, Task} import mill.eval.Result import utest.assert import scala.collection.mutable object TestUtil { - def test(inputs: Task[Int]*) = { - new Test(inputs, pure = inputs.nonEmpty) + object test{ + + def anon(inputs: Task[Int]*) = new Test(inputs) + def apply(inputs: Task[Int]*) + (implicit enclosing0: sourcecode.Enclosing, + owner0: Caller[mill.Module], + name0: sourcecode.Name)= { + new TestTarget(inputs, pure = inputs.nonEmpty) + } } - /** - * A dummy target that takes any number of inputs, and whose output can be - * controlled externally, so you can construct arbitrary dataflow graphs and - * test how changes propagate. - */ - class Test(override val inputs: Seq[Task[Int]], - val pure: Boolean) extends Target[Int]{ + class Test(val inputs: Seq[Task[Int]]) extends Task[Int]{ var counter = 0 var failure = Option.empty[String] var exception = Option.empty[Throwable] override def evaluate(args: Ctx) = { failure.map(Result.Failure) orElse - exception.map(Result.Exception) getOrElse - Result.Success(counter + args.args.map(_.asInstanceOf[Int]).sum) + exception.map(Result.Exception) getOrElse + Result.Success(counter + args.args.map(_.asInstanceOf[Int]).sum) } - override def sideHash = counter + failure.hashCode() + exception.hashCode() } + /** + * A dummy target that takes any number of inputs, and whose output can be + * controlled externally, so you can construct arbitrary dataflow graphs and + * test how changes propagate. + */ + class TestTarget(inputs: Seq[Task[Int]], + val pure: Boolean) + (implicit enclosing0: sourcecode.Enclosing, + owner0: Caller[mill.Module], + name0: sourcecode.Name) + extends Test(inputs) with Target[Int]{ + val enclosing = enclosing0.value + val owner = owner0.value + val name = name0.value + val readWrite = upickle.default.IntRW + + + } def checkTopological(targets: OSet[Task[_]]) = { val seen = mutable.Set.empty[Task[_]] for(t <- targets.indexed.reverseIterator){ |