From fba1439021e9ad009157cc56dccc93b2e90b2c71 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Sat, 18 Nov 2017 13:59:40 -0800 Subject: Move some test cases that are testing `mill/discover/` code, into that package --- core/src/test/scala/mill/define/GraphTests.scala | 79 ---------------------- .../scala/mill/discover/ConsistencyTests.scala | 54 +++++++++++++++ .../test/scala/mill/discover/LabelingTests.scala | 53 +++++++++++++++ 3 files changed, 107 insertions(+), 79 deletions(-) create mode 100644 core/src/test/scala/mill/discover/ConsistencyTests.scala create mode 100644 core/src/test/scala/mill/discover/LabelingTests.scala (limited to 'core') diff --git a/core/src/test/scala/mill/define/GraphTests.scala b/core/src/test/scala/mill/define/GraphTests.scala index cc7bd3c2..a83f7a7b 100644 --- a/core/src/test/scala/mill/define/GraphTests.scala +++ b/core/src/test/scala/mill/define/GraphTests.scala @@ -12,47 +12,6 @@ object GraphTests extends TestSuite{ val graphs = new TestGraphs() import graphs._ - '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) - } - - '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[Task[_]], expected: OSet[Task[_]]) = { @@ -187,44 +146,6 @@ object GraphTests extends TestSuite{ ) } - 'labeling - { - - def check[T: Discovered](base: T, t: Task[_], relPath: Option[String]) = { - - - val names: Seq[(Task[_], Seq[String])] = Discovered.mapping(base).mapValues(_.segments).toSeq - val nameMap = names.toMap - - val targetLabel = nameMap.get(t).map(_.mkString(".")) - assert(targetLabel == relPath) - } - 'singleton - check(singleton, singleton.single, Some("single")) - 'pair - { - check(pair, pair.up, Some("up")) - check(pair, pair.down, Some("down")) - } - - 'anonTriple - { - check(anonTriple, anonTriple.up, Some("up")) - check(anonTriple, anonTriple.down.inputs(0), None) - check(anonTriple, anonTriple.down, Some("down")) - } - - 'diamond - { - check(diamond, diamond.up, Some("up")) - check(diamond, diamond.left, Some("left")) - check(diamond, diamond.right, Some("right")) - check(diamond, diamond.down, Some("down")) - } - - 'anonDiamond - { - check(anonDiamond, anonDiamond.up, Some("up")) - check(anonDiamond, anonDiamond.down.inputs(0), None) - check(anonDiamond, anonDiamond.down.inputs(1), None) - check(anonDiamond, anonDiamond.down, Some("down")) - } - - } } } diff --git a/core/src/test/scala/mill/discover/ConsistencyTests.scala b/core/src/test/scala/mill/discover/ConsistencyTests.scala new file mode 100644 index 00000000..67e22595 --- /dev/null +++ b/core/src/test/scala/mill/discover/ConsistencyTests.scala @@ -0,0 +1,54 @@ +package mill.discover + + +import mill.util.TestGraphs +import utest._ + +object ConsistencyTests extends TestSuite{ + + val tests = Tests{ + val graphs = new TestGraphs() + import graphs._ + '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) + } + + 'borkedCachedDiamond2 - { + val inconsistent = Discovered.consistencyCheck( + borkedCachedDiamond2, + Discovered[borkedCachedDiamond2.type] + ) + assert(inconsistent == expected) + } + 'borkedCachedDiamond3 - { + val inconsistent = Discovered.consistencyCheck( + borkedCachedDiamond3, + Discovered[borkedCachedDiamond3.type] + ) + assert(inconsistent == expected) + } + } + + } +} diff --git a/core/src/test/scala/mill/discover/LabelingTests.scala b/core/src/test/scala/mill/discover/LabelingTests.scala new file mode 100644 index 00000000..a37c090c --- /dev/null +++ b/core/src/test/scala/mill/discover/LabelingTests.scala @@ -0,0 +1,53 @@ +package mill.discover + +import mill.define.Task +import mill.util.TestGraphs +import utest._ + +object LabelingTests extends TestSuite{ + + val tests = Tests{ + val graphs = new TestGraphs() + import graphs._ + + 'labeling - { + + def check[T: Discovered](base: T, t: Task[_], relPath: Option[String]) = { + + + val names: Seq[(Task[_], Seq[String])] = Discovered.mapping(base).mapValues(_.segments).toSeq + val nameMap = names.toMap + + val targetLabel = nameMap.get(t).map(_.mkString(".")) + assert(targetLabel == relPath) + } + 'singleton - check(singleton, singleton.single, Some("single")) + 'pair - { + check(pair, pair.up, Some("up")) + check(pair, pair.down, Some("down")) + } + + 'anonTriple - { + check(anonTriple, anonTriple.up, Some("up")) + check(anonTriple, anonTriple.down.inputs(0), None) + check(anonTriple, anonTriple.down, Some("down")) + } + + 'diamond - { + check(diamond, diamond.up, Some("up")) + check(diamond, diamond.left, Some("left")) + check(diamond, diamond.right, Some("right")) + check(diamond, diamond.down, Some("down")) + } + + 'anonDiamond - { + check(anonDiamond, anonDiamond.up, Some("up")) + check(anonDiamond, anonDiamond.down.inputs(0), None) + check(anonDiamond, anonDiamond.down.inputs(1), None) + check(anonDiamond, anonDiamond.down, Some("down")) + } + + } + + } +} -- cgit v1.2.3