summaryrefslogtreecommitdiff
path: root/core/src/test/scala
diff options
context:
space:
mode:
Diffstat (limited to 'core/src/test/scala')
-rw-r--r--core/src/test/scala/forge/GraphTests.scala66
-rw-r--r--core/src/test/scala/forge/JavaCompileJarTests.scala19
-rw-r--r--core/src/test/scala/forge/TestGraphs.scala29
3 files changed, 101 insertions, 13 deletions
diff --git a/core/src/test/scala/forge/GraphTests.scala b/core/src/test/scala/forge/GraphTests.scala
index 572e459e..ca825683 100644
--- a/core/src/test/scala/forge/GraphTests.scala
+++ b/core/src/test/scala/forge/GraphTests.scala
@@ -70,6 +70,54 @@ object GraphTests extends TestSuite{
diamond.down
)
)
+ 'defCachedDiamond - check(
+ targets = OSet(defCachedDiamond.down),
+ expected = OSet(
+ defCachedDiamond.up,
+ defCachedDiamond.down.inputs(0),
+ defCachedDiamond.down.inputs(1),
+ defCachedDiamond.down
+ )
+ )
+ 'borkedCachedDiamond - {
+ // Make sure these fail because `def`s without `Cacher` will re-evaluate
+ // each time, returning different sets of targets.
+ //
+ // Maybe later we can convert them into compile errors somehow
+ * - intercept[Throwable]{
+ check(
+ targets = OSet(borkedCachedDiamond1.down),
+ expected = OSet(
+ borkedCachedDiamond1.up,
+ borkedCachedDiamond1.down.inputs(0),
+ borkedCachedDiamond1.down.inputs(1),
+ borkedCachedDiamond1.down
+ )
+ )
+ }
+ * - intercept[Throwable]{
+ check(
+ targets = OSet(borkedCachedDiamond2.down),
+ expected = OSet(
+ borkedCachedDiamond2.up,
+ borkedCachedDiamond2.down.inputs(0),
+ borkedCachedDiamond2.down.inputs(1),
+ borkedCachedDiamond2.down
+ )
+ )
+ }
+ * - intercept[Throwable]{
+ check(
+ targets = OSet(borkedCachedDiamond3.down),
+ expected = OSet(
+ borkedCachedDiamond3.up,
+ borkedCachedDiamond3.down.inputs(0),
+ borkedCachedDiamond3.down.inputs(1),
+ borkedCachedDiamond3.down
+ )
+ )
+ }
+ }
'bigSingleTerminal - {
val result = Evaluator.topoSortedTransitiveTargets(OSet(bigSingleTerminal.j)).values
TestUtil.checkTopological(result)
@@ -78,9 +126,9 @@ object GraphTests extends TestSuite{
}
'groupAroundNamedTargets - {
- def check[T: Discovered](base: T,
- target: TestUtil.Test,
- expected: OSet[(OSet[TestUtil.Test], Int)]) = {
+ def check[T: Discovered, R <: Target[Int]](base: T,
+ target: R,
+ expected: OSet[(OSet[R], Int)]) = {
val mapping = Discovered.mapping(base)
val topoSortedTransitive = Evaluator.topoSortedTransitiveTargets(OSet(target))
@@ -122,6 +170,18 @@ object GraphTests extends TestSuite{
OSet(diamond.down) -> 1
)
)
+
+ 'defCachedDiamond - check(
+ defCachedDiamond,
+ defCachedDiamond.down,
+ OSet(
+ OSet(defCachedDiamond.up) -> 1,
+ OSet(defCachedDiamond.left) -> 1,
+ OSet(defCachedDiamond.right) -> 1,
+ OSet(defCachedDiamond.down) -> 1
+ )
+ )
+
'anonDiamond - check(
anonDiamond,
anonDiamond.down,
diff --git a/core/src/test/scala/forge/JavaCompileJarTests.scala b/core/src/test/scala/forge/JavaCompileJarTests.scala
index c1a055ea..8b292a88 100644
--- a/core/src/test/scala/forge/JavaCompileJarTests.scala
+++ b/core/src/test/scala/forge/JavaCompileJarTests.scala
@@ -50,27 +50,26 @@ object JavaCompileJarTests extends TestSuite{
mkdir(pwd / 'target / 'workspace / 'javac)
cp(javacSrcPath, javacDestPath)
- object Build {
- val sourceRootPath = javacDestPath / 'src
- val resourceRootPath = javacDestPath / 'resources
+ object Build extends Target.Cacher{
+ def sourceRootPath = javacDestPath / 'src
+ def resourceRootPath = javacDestPath / 'resources
// sourceRoot -> allSources -> classFiles
// |
// v
// resourceRoot ----> jar
- val sourceRoot = Target.path(sourceRootPath)
- val resourceRoot = Target.path(resourceRootPath)
- val allSources = T{
- ls.rec(sourceRoot().path).map(PathRef(_))
- }
- val classFiles = compileAll(allSources)
- val jar = jarUp(resourceRoot, classFiles)
+ def sourceRoot = T{ Target.path(sourceRootPath) }
+ def resourceRoot = T{ Target.path(resourceRootPath) }
+ def allSources = T{ ls.rec(sourceRoot().path).map(PathRef(_)) }
+ def classFiles = T{ compileAll(allSources) }
+ def jar = T{ jarUp(resourceRoot, classFiles) }
}
import Build._
val mapping = Discovered.mapping(Build)
def check(targets: OSet[Target[_]], expected: OSet[Target[_]]) = {
val evaluator = new Evaluator(workspacePath, mapping)
+
val evaluated = evaluator.evaluate(targets).evaluated.filter(mapping.contains)
assert(evaluated == expected)
}
diff --git a/core/src/test/scala/forge/TestGraphs.scala b/core/src/test/scala/forge/TestGraphs.scala
index 0ee48a18..5960ed4c 100644
--- a/core/src/test/scala/forge/TestGraphs.scala
+++ b/core/src/test/scala/forge/TestGraphs.scala
@@ -1,5 +1,6 @@
package forge
+import forge.Target.Cacher
import forge.TestUtil.test
class TestGraphs(){
@@ -42,6 +43,34 @@ class TestGraphs(){
val down = test(test(up), test(up))
}
+ object defCachedDiamond extends Cacher{
+ def up = T{ test() }
+ def left = T{ test(up) }
+ def right = T{ test(up) }
+ 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()
+ def left = test(up)
+ def right = test(up)
+ def down = test(left, right)
+ }
+
+ object borkedCachedDiamond3 {
+ def up = test()
+ def left = test(up)
+ def right = test(up)
+ def down = test(left, right)
+ }
+
// o g-----o
// \ \ \
// o o h-----I---o