diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-05 14:12:48 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-05 14:12:48 -0800 |
commit | 44bd42587532755439fcdc175eb95604966bbea8 (patch) | |
tree | 400e2a16dc02f6b60ab9af30907fd7b3d96d053c | |
parent | 2fd4c498cc005182ef65a20db30f461f0893508a (diff) | |
download | mill-44bd42587532755439fcdc175eb95604966bbea8.tar.gz mill-44bd42587532755439fcdc175eb95604966bbea8.tar.bz2 mill-44bd42587532755439fcdc175eb95604966bbea8.zip |
Add a simple consistency checker on `Discovered` to test if any of the observable `Target`s in the given base are not being properly cached
-rw-r--r-- | core/src/main/scala/forge/discover/Discovered.scala | 7 | ||||
-rw-r--r-- | core/src/test/scala/forge/GraphTests.scala | 87 |
2 files changed, 55 insertions, 39 deletions
diff --git a/core/src/main/scala/forge/discover/Discovered.scala b/core/src/main/scala/forge/discover/Discovered.scala index 964732be..8d340569 100644 --- a/core/src/main/scala/forge/discover/Discovered.scala +++ b/core/src/main/scala/forge/discover/Discovered.scala @@ -12,6 +12,13 @@ class Discovered[T](val value: Seq[(Seq[String], Format[_], T => Target[_])]){ } object Discovered { + def consistencyCheck[T](base: T, d: Discovered[T]) = { + val inconsistent = for{ + (path, formatter, targetGen) <- d.value + if targetGen(base) ne targetGen(base) + } yield path + inconsistent + } def makeTuple[T, V](path: Seq[String], func: T => Target[V])(implicit f: Format[V]) = { (path, f, func) } diff --git a/core/src/test/scala/forge/GraphTests.scala b/core/src/test/scala/forge/GraphTests.scala index e608c877..1b542882 100644 --- a/core/src/test/scala/forge/GraphTests.scala +++ b/core/src/test/scala/forge/GraphTests.scala @@ -40,6 +40,54 @@ object GraphTests extends TestSuite{ assert(discovered == expected) } + 'failConsistencyChecks - { + // 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 + + val expected = List(List("down"), List("right"), List("left"), List("up")) + + 'diamond - { + val inconsistent = Discovered.consistencyCheck( + diamond, + Discovered[diamond.type] + ) + + assert(inconsistent == Nil) + } + 'anonDiamond - { + val inconsistent = Discovered.consistencyCheck( + anonDiamond, + Discovered[anonDiamond.type] + ) + + assert(inconsistent == Nil) + } + 'borkedCachedDiamond1 - { + val inconsistent = Discovered.consistencyCheck( + borkedCachedDiamond1, + Discovered[borkedCachedDiamond1.type] + ) + + assert(inconsistent == expected) + } + 'borkedCachedDiamond2 - { + val inconsistent = Discovered.consistencyCheck( + borkedCachedDiamond2, + Discovered[borkedCachedDiamond2.type] + ) + assert(inconsistent == expected) + } + 'borkedCachedDiamond3 - { + val inconsistent = Discovered.consistencyCheck( + borkedCachedDiamond3, + Discovered[borkedCachedDiamond3.type] + ) + assert(inconsistent == expected) + } + } + 'topoSortedTransitiveTargets - { def check(targets: OSet[Target[_]], expected: OSet[Target[_]]) = { @@ -82,45 +130,6 @@ object GraphTests extends TestSuite{ 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) |