diff options
Diffstat (limited to 'core/src/test/scala')
-rw-r--r-- | core/src/test/scala/forge/CacherTests.scala | 6 | ||||
-rw-r--r-- | core/src/test/scala/forge/EvaluationTests.scala | 6 | ||||
-rw-r--r-- | core/src/test/scala/forge/GraphTests.scala | 35 | ||||
-rw-r--r-- | core/src/test/scala/forge/JavaCompileJarTests.scala | 21 | ||||
-rw-r--r-- | core/src/test/scala/forge/MacroErrorTests.scala | 42 | ||||
-rw-r--r-- | core/src/test/scala/forge/TestGraphs.scala | 8 | ||||
-rw-r--r-- | core/src/test/scala/forge/TestUtil.scala | 12 |
7 files changed, 69 insertions, 61 deletions
diff --git a/core/src/test/scala/forge/CacherTests.scala b/core/src/test/scala/forge/CacherTests.scala index 24a540ff..5f40ee20 100644 --- a/core/src/test/scala/forge/CacherTests.scala +++ b/core/src/test/scala/forge/CacherTests.scala @@ -1,6 +1,6 @@ package forge -import forge.define.Target +import forge.define.Task import forge.discover.Discovered import forge.eval.Evaluator import forge.util.OSet @@ -9,7 +9,7 @@ import utest.framework.TestPath object CacherTests extends TestSuite{ object Base extends Base - trait Base extends Target.Cacher{ + trait Base extends Task.Cacher{ def value = T{ 1 } } object Middle extends Middle @@ -25,7 +25,7 @@ object CacherTests extends TestSuite{ val tests = Tests{ - def eval[T: Discovered, V](base: T, v: Target[V])(implicit tp: TestPath) = { + def eval[T: Discovered, V](base: T, v: Task[V])(implicit tp: TestPath) = { val workspace = ammonite.ops.pwd / 'target / 'workspace / tp.value val evaluator = new Evaluator(workspace, Discovered.mapping(base)) evaluator.evaluate(OSet(v)).values(0) diff --git a/core/src/test/scala/forge/EvaluationTests.scala b/core/src/test/scala/forge/EvaluationTests.scala index 66fe7b8d..72b7deff 100644 --- a/core/src/test/scala/forge/EvaluationTests.scala +++ b/core/src/test/scala/forge/EvaluationTests.scala @@ -1,7 +1,7 @@ package forge -import forge.define.Target +import forge.define.Task import forge.discover.Discovered import forge.eval.Evaluator import forge.util.OSet @@ -24,8 +24,8 @@ object EvaluationTests extends TestSuite{ Discovered.mapping(base) ) - def apply(target: Target[_], expValue: Any, - expEvaled: OSet[Target[_]], + def apply(target: Task[_], expValue: Any, + expEvaled: OSet[Task[_]], extraEvaled: Int = 0) = { val Evaluator.Results(returnedValues, returnedEvaluated) = evaluator.evaluate(OSet(target)) diff --git a/core/src/test/scala/forge/GraphTests.scala b/core/src/test/scala/forge/GraphTests.scala index 1b542882..db522fff 100644 --- a/core/src/test/scala/forge/GraphTests.scala +++ b/core/src/test/scala/forge/GraphTests.scala @@ -2,7 +2,7 @@ package forge import utest._ import TestUtil.test -import forge.define.Target +import forge.define.Task import forge.discover.Discovered import forge.eval.Evaluator import forge.util.OSet @@ -64,14 +64,7 @@ object GraphTests extends TestSuite{ assert(inconsistent == Nil) } - 'borkedCachedDiamond1 - { - val inconsistent = Discovered.consistencyCheck( - borkedCachedDiamond1, - Discovered[borkedCachedDiamond1.type] - ) - assert(inconsistent == expected) - } 'borkedCachedDiamond2 - { val inconsistent = Discovered.consistencyCheck( borkedCachedDiamond2, @@ -90,7 +83,7 @@ object GraphTests extends TestSuite{ 'topoSortedTransitiveTargets - { - def check(targets: OSet[Target[_]], expected: OSet[Target[_]]) = { + def check(targets: OSet[Task[_]], expected: OSet[Task[_]]) = { val result = Evaluator.topoSortedTransitiveTargets(targets).values TestUtil.checkTopological(result) assert(result == expected) @@ -124,9 +117,13 @@ object GraphTests extends TestSuite{ 'defCachedDiamond - check( targets = OSet(defCachedDiamond.down), expected = OSet( + defCachedDiamond.up.inputs(0), defCachedDiamond.up, + defCachedDiamond.down.inputs(0).inputs(0).inputs(0), + defCachedDiamond.down.inputs(0).inputs(0), + defCachedDiamond.down.inputs(0).inputs(1).inputs(0), + defCachedDiamond.down.inputs(0).inputs(1), defCachedDiamond.down.inputs(0), - defCachedDiamond.down.inputs(1), defCachedDiamond.down ) ) @@ -138,9 +135,9 @@ object GraphTests extends TestSuite{ } 'groupAroundNamedTargets - { - def check[T: Discovered, R <: Target[Int]](base: T, - target: R, - expected: OSet[(OSet[R], Int)]) = { + def check[T: Discovered, R <: Task[Int]](base: T, + target: R, + expected: OSet[(OSet[R], Int)]) = { val mapping = Discovered.mapping(base) val topoSortedTransitive = Evaluator.topoSortedTransitiveTargets(OSet(target)) @@ -187,10 +184,10 @@ object GraphTests extends TestSuite{ defCachedDiamond, defCachedDiamond.down, OSet( - OSet(defCachedDiamond.up) -> 1, - OSet(defCachedDiamond.left) -> 1, - OSet(defCachedDiamond.right) -> 1, - OSet(defCachedDiamond.down) -> 1 + OSet(defCachedDiamond.up) -> 2, + OSet(defCachedDiamond.left) -> 2, + OSet(defCachedDiamond.right) -> 2, + OSet(defCachedDiamond.down) -> 2 ) ) @@ -218,10 +215,10 @@ object GraphTests extends TestSuite{ 'labeling - { - def check[T: Discovered](base: T, t: Target[_], relPath: Option[String]) = { + def check[T: Discovered](base: T, t: Task[_], relPath: Option[String]) = { - val names: Seq[(Target[_], Seq[String])] = Discovered.mapping(base).mapValues(_.segments).toSeq + val names: Seq[(Task[_], Seq[String])] = Discovered.mapping(base).mapValues(_.segments).toSeq val nameMap = names.toMap val targetLabel = nameMap.get(t).map(_.mkString(".")) diff --git a/core/src/test/scala/forge/JavaCompileJarTests.scala b/core/src/test/scala/forge/JavaCompileJarTests.scala index 4c3ce06c..fcd81588 100644 --- a/core/src/test/scala/forge/JavaCompileJarTests.scala +++ b/core/src/test/scala/forge/JavaCompileJarTests.scala @@ -3,7 +3,7 @@ package forge import ammonite.ops._ import ImplicitWd._ -import forge.define.Target +import forge.define.Task import forge.discover.Discovered import forge.eval.{Evaluator, PathRef} import forge.modules.Jvm.jarUp @@ -30,7 +30,7 @@ object JavaCompileJarTests extends TestSuite{ mkdir(pwd / 'target / 'workspace / 'javac) cp(javacSrcPath, javacDestPath) - object Build extends Target.Cacher{ + object Build extends Task.Cacher{ def sourceRootPath = javacDestPath / 'src def resourceRootPath = javacDestPath / 'resources @@ -38,26 +38,29 @@ object JavaCompileJarTests extends TestSuite{ // | // v // resourceRoot ----> jar - def sourceRoot = T{ Target.path(sourceRootPath) } - def resourceRoot = T{ Target.path(resourceRootPath) } + def sourceRoot = T{ Task.path(sourceRootPath) } + def resourceRoot = T{ Task.path(resourceRootPath) } def allSources = T{ ls.rec(sourceRoot().path).map(PathRef(_)) } - def classFiles = T{ compileAll(Target.ctx().dest, allSources()) } + def classFiles = T{ compileAll(Task.ctx().dest, allSources()) } def jar = T{ jarUp(resourceRoot, classFiles) } @forge.discover.Router.main - def run(mainClsName: String): Target[CommandResult] = T.command{ + def run(mainClsName: String): Task[CommandResult] = T.cmd{ %%('java, "-cp", classFiles().path, mainClsName) } } import Build._ val mapping = Discovered.mapping(Build) - def eval[T](t: Target[T]): (T, Int) = { + def eval[T](t: Task[T]): (T, Int) = { val evaluator = new Evaluator(workspacePath, mapping) val evaluated = evaluator.evaluate(OSet(t)) - (evaluated.values(0).asInstanceOf[T], evaluated.targets.size) + Tuple2( + evaluated.values(0).asInstanceOf[T], + evaluated.targets.filter(x => mapping.contains(x) || x.isInstanceOf[forge.define.Command[_]]).size + ) } - def check(targets: OSet[Target[_]], expected: OSet[Target[_]]) = { + def check(targets: OSet[Task[_]], expected: OSet[Task[_]]) = { val evaluator = new Evaluator(workspacePath, mapping) val evaluated = evaluator.evaluate(targets).targets.filter(mapping.contains) diff --git a/core/src/test/scala/forge/MacroErrorTests.scala b/core/src/test/scala/forge/MacroErrorTests.scala index 9f41fadc..6e76cd17 100644 --- a/core/src/test/scala/forge/MacroErrorTests.scala +++ b/core/src/test/scala/forge/MacroErrorTests.scala @@ -8,7 +8,7 @@ object MacroErrorTests extends TestSuite{ 'errors{ val expectedMsg = - "T{} members defined in a Cacher class/trait/object body must be defs" + "T{} members must be defs defined in a Cacher class/trait/object body" val err = compileError("object Foo extends forge.define.Target.Cacher{ val x = T{1} }") assert(err.msg == expectedMsg) @@ -19,23 +19,26 @@ object MacroErrorTests extends TestSuite{ // of our `Target#apply()` calls, but we cannot reference any values that // come from inside the T{...} block 'pos - { - val a = T{ 1 } - val arr = Array(a) - val b = { - val c = 0 - T{ - arr(c)() + val e = compileError(""" + val a = T{ 1 } + val arr = Array(a) + val b = { + val c = 0 + T{ + arr(c)() + } } - } + """) + assert(e.msg.contains("must be defs")) } 'neg - { val expectedMsg = "Target#apply() call cannot use `value n` defined within the T{...} block" - val err = compileError("""{ - val a = T{ 1 } + val err = compileError("""new forge.define.Target.Cacher{ + def a = T{ 1 } val arr = Array(a) - val b = { + def b = { T{ val n = 0 arr(n)() @@ -48,10 +51,10 @@ object MacroErrorTests extends TestSuite{ val expectedMsg = "Target#apply() call cannot use `value x` defined within the T{...} block" - val err = compileError("""{ - val a = T{ 1 } + val err = compileError("""new forge.define.Target.Cacher{ + def a = T{ 1 } val arr = Array(a) - val b = { + def b = { T{ arr.map{x => x()} } @@ -59,6 +62,17 @@ object MacroErrorTests extends TestSuite{ }""") assert(err.msg == expectedMsg) } + 'neg3{ + val borkedCachedDiamond1 = utest.compileError(""" + object borkedCachedDiamond1 { + def up = T{ TestUtil.test() } + def left = T{ TestUtil.test(up) } + def right = T{ TestUtil.test(up) } + def down = T{ TestUtil.test(left, right) } + } + """) + assert(borkedCachedDiamond1.msg.contains("must be defs")) + } } } } diff --git a/core/src/test/scala/forge/TestGraphs.scala b/core/src/test/scala/forge/TestGraphs.scala index 5c30f948..9709979d 100644 --- a/core/src/test/scala/forge/TestGraphs.scala +++ b/core/src/test/scala/forge/TestGraphs.scala @@ -1,6 +1,6 @@ package forge -import forge.define.Target.Cacher +import forge.define.Task.Cacher import forge.TestUtil.test class TestGraphs(){ @@ -50,12 +50,6 @@ class TestGraphs(){ def down = T{ test(left, right) } } - object borkedCachedDiamond1 { - def up = T{ test() } - def left = T{ test(up) } - def right = T{ test(up) } - def down = T{ test(left, right) } - } object borkedCachedDiamond2 extends Cacher { def up = test() diff --git a/core/src/test/scala/forge/TestUtil.scala b/core/src/test/scala/forge/TestUtil.scala index 005bcfef..91dc3da9 100644 --- a/core/src/test/scala/forge/TestUtil.scala +++ b/core/src/test/scala/forge/TestUtil.scala @@ -1,13 +1,13 @@ package forge -import forge.define.Target +import forge.define.Task import forge.util.{Args, OSet} import utest.assert import scala.collection.mutable object TestUtil { - def test(inputs: Target[Int]*) = { + def test(inputs: Task[Int]*) = { new Test(inputs, pure = inputs.nonEmpty) } @@ -16,8 +16,8 @@ object TestUtil { * controlled externally, so you can construct arbitrary dataflow graphs and * test how changes propagate. */ - class Test(val inputs: Seq[Target[Int]], - val pure: Boolean) extends Target[Int]{ + class Test(val inputs: Seq[Task[Int]], + val pure: Boolean) extends Task[Int]{ var counter = 0 def evaluate(args: Args) = { counter + args.args.map(_.asInstanceOf[Int]).sum @@ -25,8 +25,8 @@ object TestUtil { override def sideHash = counter } - def checkTopological(targets: OSet[Target[_]]) = { - val seen = mutable.Set.empty[Target[_]] + def checkTopological(targets: OSet[Task[_]]) = { + val seen = mutable.Set.empty[Task[_]] for(t <- targets.items.reverseIterator){ seen.add(t) for(upstream <- t.inputs){ |