diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-10-22 17:12:42 -0700 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-10-22 17:12:42 -0700 |
commit | 0ed7e0472b9a82ab749e8d3be5795506e53451ab (patch) | |
tree | fb9e06ad2c4a511a1555fee2adf7a98c252bb45c /src | |
parent | 58daff70ac26cab4833ed4b5e57e13f60f440bc0 (diff) | |
download | mill-0ed7e0472b9a82ab749e8d3be5795506e53451ab.tar.gz mill-0ed7e0472b9a82ab749e8d3be5795506e53451ab.tar.bz2 mill-0ed7e0472b9a82ab749e8d3be5795506e53451ab.zip |
- `Target.Noop -> Target.Test`
- `Target.Test`'s output now depends on its upstream targets, and is now configurable, so you can use it to test change propagations
- Move `ForgeTests`'s targets inside the `Tests` block, since they're now mutable and so shouldn't remain global
Diffstat (limited to 'src')
-rw-r--r-- | src/main/scala/forge/Target.scala | 17 | ||||
-rw-r--r-- | src/test/scala/forge/ForgeTests.scala | 53 |
2 files changed, 43 insertions, 27 deletions
diff --git a/src/main/scala/forge/Target.scala b/src/main/scala/forge/Target.scala index 80ff98c4..b2f837a7 100644 --- a/src/main/scala/forge/Target.scala +++ b/src/main/scala/forge/Target.scala @@ -5,6 +5,10 @@ import java.nio.{file => jnio} trait Target[T]{ val defCtx: DefCtx + override def toString = defCtx.staticEnclosing match{ + case None => this.getClass.getSimpleName + "@" + Integer.toHexString(System.identityHashCode(this)) + case Some(s) => this.getClass.getName + "@" + s + } val inputs: Seq[Target[_]] def evaluate(args: Args): T @@ -22,9 +26,16 @@ trait Target[T]{ } object Target{ - def noop(inputs: Target[_]*)(implicit defCtx: DefCtx) = NoopTarget(inputs, defCtx) - case class NoopTarget(inputs: Seq[Target[_]], defCtx: DefCtx) extends Target[Unit]{ - def evaluate(args: Args) = () + def test(inputs: Target[Int]*)(implicit defCtx: DefCtx) = Test(inputs, defCtx) + + /** + * 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. + */ + case class Test(inputs: Seq[Target[Int]], defCtx: DefCtx) extends Target[Int]{ + var counter = 1 + def evaluate(args: Args) = counter + args.args.map(_.asInstanceOf[Int]).sum } def traverse[T](source: Seq[Target[T]])(implicit defCtx: DefCtx) = { Traverse[T](source, defCtx) diff --git a/src/test/scala/forge/ForgeTests.scala b/src/test/scala/forge/ForgeTests.scala index 0ad15a59..b6e003f3 100644 --- a/src/test/scala/forge/ForgeTests.scala +++ b/src/test/scala/forge/ForgeTests.scala @@ -1,31 +1,31 @@ package forge import utest._ -import Target.noop +import Target.test import java.nio.{file => jnio} object ForgeTests extends TestSuite{ - val evaluator = new Evaluator( - jnio.Paths.get("target/workspace"), - implicitly - ) - object Singleton { - val single = noop() - } - object Pair { - val up = noop() - val down = noop(up) - } - object Diamond{ - val up = noop() - val left = noop(up) - val right = noop(up) - val down = noop(left, right) - } - object AnonymousDiamond{ - val up = noop() - val down = noop(noop(up), noop(up)) - } + val tests = Tests{ + implicit def fakeStaticContext = DefCtx.StaticContext(true) + val evaluator = new Evaluator(jnio.Paths.get("target/workspace"), implicitly) + object Singleton { + val single = test() + } + object Pair { + val up = test() + val down = test(up) + } + object Diamond{ + val up = test() + val left = test(up) + val right = test(up) + val down = test(left, right) + } + object AnonymousDiamond{ + val up = test() + val down = test(test(up), test(up)) + } + 'topoSortedTransitiveTargets - { def check(targets: Seq[Target[_]], expected: Seq[Target[_]]) = { val result = evaluator.topoSortedTransitiveTargets(targets) @@ -41,11 +41,16 @@ object ForgeTests extends TestSuite{ ) 'diamond - check( targets = Seq(Diamond.down), - expected = Seq(Diamond.up, Diamond.right, Diamond.left, Diamond.down) + expected = Seq(Diamond.up, Diamond.left, Diamond.right, Diamond.down) ) 'anonDiamond - check( targets = Seq(Diamond.down), - expected = Seq(Diamond.up, Diamond.down.inputs(1), Diamond.down.inputs(0), Diamond.down) + expected = Seq( + Diamond.up, + Diamond.down.inputs(0), + Diamond.down.inputs(1), + Diamond.down + ) ) } |