diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-17 01:01:11 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-17 01:01:11 -0800 |
commit | f5224324f20e7720e01a2f59b43f4151fac0c899 (patch) | |
tree | 93c9074e60533db07d617cb9e5abd5bb12688588 /core/src/test | |
parent | 2aaf1500277e75d50471f03e6e80af8c8fba6281 (diff) | |
download | mill-f5224324f20e7720e01a2f59b43f4151fac0c899.tar.gz mill-f5224324f20e7720e01a2f59b43f4151fac0c899.tar.bz2 mill-f5224324f20e7720e01a2f59b43f4151fac0c899.zip |
Tests appear to pass using the new `Hierarchy`-first `Discovered` data format
Diffstat (limited to 'core/src/test')
-rw-r--r-- | core/src/test/scala/mill/DiscoveredTests.scala | 54 | ||||
-rw-r--r-- | core/src/test/scala/mill/GraphTests.scala | 40 |
2 files changed, 55 insertions, 39 deletions
diff --git a/core/src/test/scala/mill/DiscoveredTests.scala b/core/src/test/scala/mill/DiscoveredTests.scala new file mode 100644 index 00000000..87d2e340 --- /dev/null +++ b/core/src/test/scala/mill/DiscoveredTests.scala @@ -0,0 +1,54 @@ +package mill + +import utest._ +import TestUtil.test +import mill.define.Task.Module +import mill.discover.{Discovered, Hierarchy} + +object DiscoveredTests extends TestSuite{ + + val tests = Tests{ + + 'discovery{ + class CanNest extends Module{ + val single = test() + val invisible: Any = test() + } + object outer { + val single = test() + val invisible: Any = test() + object nested extends Module{ + val single = test() + val invisible: Any = test() + + } + val classInstance = new CanNest + + } + + val discovered = Discovered[outer.type] + + + def flatten(h: Hierarchy[outer.type, _]): Seq[Any] = { + h.node(outer) :: h.children.flatMap{case (label, c) => flatten(c)} + } + val flattenedHierarchy = flatten(discovered.hierarchy) + + val expectedHierarchy = Seq( + outer, + outer.classInstance, + outer.nested, + ) + assert(flattenedHierarchy == expectedHierarchy) + + val mapped = discovered.targets(outer).map(x => x.segments -> x.target) + + val expected = Seq( + (List("classInstance", "single"), outer.classInstance.single), + (List("nested", "single"), outer.nested.single), + (List("single"), outer.single) + ) + assert(mapped.toSet == expected.toSet) + } + } +} diff --git a/core/src/test/scala/mill/GraphTests.scala b/core/src/test/scala/mill/GraphTests.scala index a3eeb62f..7d4caaac 100644 --- a/core/src/test/scala/mill/GraphTests.scala +++ b/core/src/test/scala/mill/GraphTests.scala @@ -3,6 +3,7 @@ package mill import utest._ import TestUtil.test import mill.define.Task +import mill.define.Task.Module import mill.discover.{Discovered, Hierarchy} import mill.eval.Evaluator import mill.util.OSet @@ -15,45 +16,6 @@ object GraphTests extends TestSuite{ val graphs = new TestGraphs() import graphs._ - 'discovery{ - class CanNest{ - val single = test() - val invisible: Any = test() - } - object outer { - val single = test() - val invisible: Any = test() - object nested{ - val single = test() - val invisible: Any = test() - - } - val classInstance = new CanNest - - } - val discovered = Discovered[outer.type] - - val mapped = discovered.apply(outer).map(x => (x._1, x._3)) - def flatten(h: Hierarchy[outer.type]): Seq[Any] = { - h.node(outer) :: h.children.flatMap(flatten) - } - val flattenedHierarchy = flatten(discovered.hierarchy) - - val expectedHierarchy = Seq( - outer, - outer.classInstance, - outer.nested, - ) - assert(flattenedHierarchy == expectedHierarchy) - - val expected = Seq( - (List("classInstance", "single"), outer.classInstance.single), - (List("nested", "single"), outer.nested.single), - (List("single"), outer.single) - ) - assert(mapped == expected) - } - 'failConsistencyChecks - { // Make sure these fail because `def`s without `Cacher` will re-evaluate // each time, returning different sets of targets. |