diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-25 09:25:28 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-25 09:27:16 -0800 |
commit | 60d7b68ed6c1d0a86d05668f040f73ee619ddde8 (patch) | |
tree | ffe6f0cd26b2603e2603ee38287ea0ebf84c9be5 /core/src/test | |
parent | ff852a7a7602030b57af6f7fa499742b5c76d771 (diff) | |
download | mill-60d7b68ed6c1d0a86d05668f040f73ee619ddde8.tar.gz mill-60d7b68ed6c1d0a86d05668f040f73ee619ddde8.tar.bz2 mill-60d7b68ed6c1d0a86d05668f040f73ee619ddde8.zip |
Unit tests for `Main.resolve`
Diffstat (limited to 'core/src/test')
-rw-r--r-- | core/src/test/scala/mill/main/MainTests.scala | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/core/src/test/scala/mill/main/MainTests.scala b/core/src/test/scala/mill/main/MainTests.scala new file mode 100644 index 00000000..de7cfd7d --- /dev/null +++ b/core/src/test/scala/mill/main/MainTests.scala @@ -0,0 +1,49 @@ +package mill.main + +import mill.Module +import mill.define.Task +import mill.discover.Discovered +import mill.util.TestUtil.test +import utest._ + +object MainTests extends TestSuite{ + def check[T: Discovered](obj: T, + selectorString: String, + expected: Either[String, Task[_]]) = { + val resolved = for{ + args <- mill.Main.parseArgs(selectorString) + task <- mill.Main.resolve(args, implicitly[Discovered[T]].mirror, obj, Nil, Nil, Nil) + } yield task + assert(resolved == expected) + } + val tests = Tests{ + val graphs = new mill.util.TestGraphs() + import graphs._ + 'single - { + 'pos - check(singleton, "single", Right(singleton.single)) + 'neg1 - check(singleton, "doesntExist", Left("Cannot resolve task doesntExist")) + 'neg2 - check(singleton, "single.doesntExist", Left("Cannot resolve module single")) + 'neg3 - check(singleton, "", Left("Selector cannot be empty")) + } + 'nested - { + class CanNest extends Module{ + val single = test() + } + object outer { + val single = test() + object nested extends Module{ + val single = test() + } + val classInstance = new CanNest + + } + 'pos1 - check(outer, "single", Right(outer.single)) + 'pos2 - check(outer, "nested.single", Right(outer.nested.single)) + 'pos3 - check(outer, "classInstance.single", Right(outer.classInstance.single)) + 'neg1 - check(outer, "doesntExist", Left("Cannot resolve task doesntExist")) + 'neg2 - check(outer, "single.doesntExist", Left("Cannot resolve module single")) + 'neg3 - check(outer, "nested.doesntExist", Left("Cannot resolve task nested.doesntExist")) + 'neg4 - check(outer, "classInstance.doesntExist", Left("Cannot resolve task classInstance.doesntExist")) + } + } +} |