diff options
-rw-r--r-- | core/src/main/scala/mill/define/Cross.scala | 4 | ||||
-rw-r--r-- | core/src/test/scala/mill/main/MainTests.scala | 67 |
2 files changed, 68 insertions, 3 deletions
diff --git a/core/src/main/scala/mill/define/Cross.scala b/core/src/main/scala/mill/define/Cross.scala index 6c69db9f..ac1ee966 100644 --- a/core/src/main/scala/mill/define/Cross.scala +++ b/core/src/main/scala/mill/define/Cross.scala @@ -10,7 +10,9 @@ case class Cross[+T](items: List[(List[Any], T)]){ def withFilter(f: T => Boolean): Cross[T] = new Cross(items.filter(t => f(t._2))) def applyOpt(input: List[Any]): Option[T] = items.find(_._1 == input).map(_._2) - def apply(input: List[Any]): T = applyOpt(input).get + def apply(input: List[Any]): T = applyOpt(input).getOrElse( + throw new Exception("Unknown set of cross values: " + input + " not in known values\n" + items.map(_._1).mkString("\n")) + ) } object Cross{ def apply[T](t: T*) = new Cross(t.map(i => List(i) -> i).toList) diff --git a/core/src/test/scala/mill/main/MainTests.scala b/core/src/test/scala/mill/main/MainTests.scala index de7cfd7d..845e0970 100644 --- a/core/src/test/scala/mill/main/MainTests.scala +++ b/core/src/test/scala/mill/main/MainTests.scala @@ -10,9 +10,11 @@ object MainTests extends TestSuite{ def check[T: Discovered](obj: T, selectorString: String, expected: Either[String, Task[_]]) = { + val mirror = implicitly[Discovered[T]].mirror val resolved = for{ args <- mill.Main.parseArgs(selectorString) - task <- mill.Main.resolve(args, implicitly[Discovered[T]].mirror, obj, Nil, Nil, Nil) + crossSelectors = args.collect{case Right(x) => x.toList} + task <- mill.Main.resolve(args, mirror, obj, Nil, crossSelectors, Nil) } yield task assert(resolved == expected) } @@ -35,7 +37,6 @@ object MainTests extends TestSuite{ val single = test() } val classInstance = new CanNest - } 'pos1 - check(outer, "single", Right(outer.single)) 'pos2 - check(outer, "nested.single", Right(outer.nested.single)) @@ -45,5 +46,67 @@ object MainTests extends TestSuite{ 'neg3 - check(outer, "nested.doesntExist", Left("Cannot resolve task nested.doesntExist")) 'neg4 - check(outer, "classInstance.doesntExist", Left("Cannot resolve task classInstance.doesntExist")) } + 'cross - { + 'single - { + object outer{ + val cross = + for(jarLabel <- mill.define.Cross("jarA", "jarB", "jarC")) + yield new mill.Module{ + val target = test() + } + } + 'pos1 - check(outer, "cross[jarA].target", Right(outer.cross(List("jarA")).target)) + 'pos2 - check(outer, "cross[jarB].target", Right(outer.cross(List("jarB")).target)) + 'neg1 - check(outer, "cross[jarA].doesntExist", Left("Cannot resolve task cross[jarA].doesntExist")) + // 'neg2 - check(outer, "cross[doesntExist].doesntExist", Left("Cannot resolve cross cross[doesntExist]")) + // 'neg2 - check(outer, "cross[doesntExist].target", Left("Cannot resolve cross cross[doesntExist]")) + } + 'double - { + object outer{ + val cross = + for{ + jarLabel <- mill.define.Cross("jarA", "jarB", "jarC") + tag <- mill.define.Cross("jvm", "js", "native") + } yield new mill.Module{ + val target = test() + } + } + 'pos1 - check( + outer, + "cross[jvm,jarA].target", + Right(outer.cross(List("jvm", "jarA")).target) + ) + 'pos2 - check( + outer, + "cross[jvm,jarB].target", + Right(outer.cross(List("jvm", "jarB")).target) + ) + } + 'nested - { + object outer{ + val cross = + for(jarLabel <- mill.define.Cross("jarA", "jarB", "jarC")) + yield new mill.Module{ + val cross2 = + for(tag <- mill.define.Cross("jvm", "js", "native")) + yield new mill.Module{ + val target = test() + } + + } + } + 'pos1 - check( + outer, + "cross[jarA].cross2[js].target", + Right(outer.cross(List("jarA")).cross2(List("js")).target) + ) + 'pos2 - check( + outer, + "cross[jarB].cross2[jvm].target", + Right(outer.cross(List("jarB")).cross2(List("jvm")).target) + ) + } + } + } } |