summaryrefslogtreecommitdiff
path: root/core/src/test/scala
diff options
context:
space:
mode:
authorNikolay Tatarinov <5min4eq.unity@gmail.com>2018-01-10 00:19:01 +0300
committerGitHub <noreply@github.com>2018-01-10 00:19:01 +0300
commit7abb8cd2ce9df949723ab6a47c92e73c4e54d0fa (patch)
treebafaf4a25aaec92e7e534687c30d83ffb1003bf7 /core/src/test/scala
parent4724f8c1477450fb584dda77bb3c2400a0c65868 (diff)
downloadmill-7abb8cd2ce9df949723ab6a47c92e73c4e54d0fa.tar.gz
mill-7abb8cd2ce9df949723ab6a47c92e73c4e54d0fa.tar.bz2
mill-7abb8cd2ce9df949723ab6a47c92e73c4e54d0fa.zip
ability to run multiple tasks via bash/zsh braces expansion (#104) fixes #31
Diffstat (limited to 'core/src/test/scala')
-rw-r--r--core/src/test/scala/mill/main/MainTests.scala6
-rw-r--r--core/src/test/scala/mill/main/ParseArgsTest.scala229
2 files changed, 232 insertions, 3 deletions
diff --git a/core/src/test/scala/mill/main/MainTests.scala b/core/src/test/scala/mill/main/MainTests.scala
index 013729ff..b4568267 100644
--- a/core/src/test/scala/mill/main/MainTests.scala
+++ b/core/src/test/scala/mill/main/MainTests.scala
@@ -13,9 +13,9 @@ object MainTests extends TestSuite{
expected: Either[String, Task[_]]) = {
val resolved = for{
- args <- mill.main.RunScript.parseArgs(selectorString)
- val crossSelectors = args.map{case Segment.Cross(x) => x.toList.map(_.toString) case _ => Nil}
- task <- mill.main.Resolve.resolve(args, mapping.mirror, mapping.base, Nil, crossSelectors, Nil)
+ selectors <- mill.main.ParseArgs(Seq(selectorString)).map(_._1.head)
+ val crossSelectors = selectors.map{case Segment.Cross(x) => x.toList.map(_.toString) case _ => Nil}
+ task <- mill.main.Resolve.resolve(selectors, mapping.mirror, mapping.base, Nil, crossSelectors, Nil)
} yield task
assert(resolved == expected)
}
diff --git a/core/src/test/scala/mill/main/ParseArgsTest.scala b/core/src/test/scala/mill/main/ParseArgsTest.scala
new file mode 100644
index 00000000..2ef07d36
--- /dev/null
+++ b/core/src/test/scala/mill/main/ParseArgsTest.scala
@@ -0,0 +1,229 @@
+package mill.main
+
+import mill.define.Segment
+import mill.define.Segment.{Cross, Label}
+import utest._
+
+object ParseArgsTest extends TestSuite {
+
+ val tests = Tests {
+ 'extractSelsAndArgs - {
+ def check(input: Seq[String],
+ expectedSelectors: Seq[String],
+ expectedArgs: Seq[String],
+ expectedIsMulti: Boolean) = {
+ val (selectors, args, isMulti) = ParseArgs.extractSelsAndArgs(input)
+
+ assert(
+ selectors == expectedSelectors,
+ args == expectedArgs,
+ isMulti == expectedIsMulti
+ )
+ }
+
+ 'empty - check(input = Seq.empty,
+ expectedSelectors = Seq.empty,
+ expectedArgs = Seq.empty,
+ expectedIsMulti = false)
+ 'singleSelector - check(
+ input = Seq("core.compile"),
+ expectedSelectors = Seq("core.compile"),
+ expectedArgs = Seq.empty,
+ expectedIsMulti = false
+ )
+ 'singleSelectorWithArgs - check(
+ input = Seq("application.run", "hello", "world"),
+ expectedSelectors = Seq("application.run"),
+ expectedArgs = Seq("hello", "world"),
+ expectedIsMulti = false
+ )
+ 'singleSelectorWithAllInArgs - check(
+ input = Seq("application.run", "hello", "world", "--all"),
+ expectedSelectors = Seq("application.run"),
+ expectedArgs = Seq("hello", "world", "--all"),
+ expectedIsMulti = false
+ )
+ 'multiSelectors - check(
+ input = Seq("--all", "core.jar", "core.docsJar", "core.sourcesJar"),
+ expectedSelectors = Seq("core.jar", "core.docsJar", "core.sourcesJar"),
+ expectedArgs = Seq.empty,
+ expectedIsMulti = true
+ )
+ 'multiSelectorsSeq - check(
+ input = Seq("--seq", "core.jar", "core.docsJar", "core.sourcesJar"),
+ expectedSelectors = Seq("core.jar", "core.docsJar", "core.sourcesJar"),
+ expectedArgs = Seq.empty,
+ expectedIsMulti = true
+ )
+ 'multiSelectorsWithArgs - check(
+ input = Seq("--all",
+ "core.compile",
+ "application.runMain",
+ "--",
+ "Main",
+ "hello",
+ "world"),
+ expectedSelectors = Seq("core.compile", "application.runMain"),
+ expectedArgs = Seq("Main", "hello", "world"),
+ expectedIsMulti = true
+ )
+ 'multiSelectorsWithArgsWithAllInArgs - check(
+ input = Seq("--all",
+ "core.compile",
+ "application.runMain",
+ "--",
+ "Main",
+ "--all",
+ "world"),
+ expectedSelectors = Seq("core.compile", "application.runMain"),
+ expectedArgs = Seq("Main", "--all", "world"),
+ expectedIsMulti = true
+ )
+ }
+ 'expandBraces - {
+ def check(input: String, expectedExpansion: List[String]) = {
+ val Right(expanded) = ParseArgs.expandBraces(input)
+
+ assert(expanded == expectedExpansion)
+ }
+
+ 'expandLeft - check(
+ "{application,core}.compile",
+ List("application.compile", "core.compile")
+ )
+ 'expandRight - check(
+ "application.{jar,docsJar,sourcesJar}",
+ List("application.jar", "application.docsJar", "application.sourcesJar")
+ )
+ 'expandBoth - check(
+ "{core,application}.{jar,docsJar}",
+ List(
+ "core.jar",
+ "core.docsJar",
+ "application.jar",
+ "application.docsJar"
+ )
+ )
+ 'expandNested - {
+ check("{hello,world.{cow,moo}}",
+ List("hello", "world.cow", "world.moo"))
+ check("{a,b{c,d}}", List("a", "bc", "bd"))
+ check("{a,b,{c,d}}", List("a", "b", "c", "d"))
+ check("{a,b{c,d{e,f}}}", List("a", "bc", "bde", "bdf"))
+ check("{a{b,c},d}", List("ab", "ac", "d"))
+ check("{a,{b,c}d}", List("a", "bd", "cd"))
+ check("{a{b,c},d{e,f}}", List("ab", "ac", "de", "df"))
+ check("{a,b{c,d},e{f,g}}", List("a", "bc", "bd", "ef", "eg"))
+ }
+ 'expandMixed - check(
+ "{a,b}.{c}.{}.e",
+ List("a.{c}.{}.e", "b.{c}.{}.e")
+ )
+ 'malformed - {
+ val malformed = Seq("core.{compile", "core.{compile,test]")
+
+ malformed.foreach { m =>
+ val Left(error) = ParseArgs.expandBraces(m)
+ assert(error.contains("Parsing exception"))
+ }
+ }
+ 'dontExpand - {
+ check("core.compile", List("core.compile"))
+ check("{}.compile", List("{}.compile"))
+ check("{core}.compile", List("{core}.compile"))
+ }
+ 'keepUnknownSymbols - {
+ check("{a,b}.e<>", List("a.e<>", "b.e<>"))
+ check("a[99]&&", List("a[99]&&"))
+ check(
+ "{a,b}.<%%>.{c,d}",
+ List("a.<%%>.c", "a.<%%>.d", "b.<%%>.c", "b.<%%>.d")
+ )
+ }
+ }
+
+ 'apply - {
+ def check(input: Seq[String],
+ expectedSelectors: List[List[Segment]],
+ expectedArgs: Seq[String]) = {
+ val Right((selectors, args)) = ParseArgs(input)
+
+ assert(
+ selectors == expectedSelectors,
+ args == expectedArgs
+ )
+ }
+
+ 'rejectEmpty {
+ assert(ParseArgs(Seq.empty) == Left("Selector cannot be empty"))
+ }
+ 'singleSelector - check(
+ input = Seq("core.compile"),
+ expectedSelectors = List(
+ List(Label("core"), Label("compile"))
+ ),
+ expectedArgs = Seq.empty
+ )
+ 'singleSelectorWithArgs - check(
+ input = Seq("application.run", "hello", "world"),
+ expectedSelectors = List(
+ List(Label("application"), Label("run"))
+ ),
+ expectedArgs = Seq("hello", "world")
+ )
+ 'singleSelectorWithCross - check(
+ input = Seq("bridges[2.12.4,jvm].compile"),
+ expectedSelectors = List(
+ List(Label("bridges"), Cross(Seq("2.12.4", "jvm")), Label("compile"))
+ ),
+ expectedArgs = Seq.empty
+ )
+ 'multiSelectorsBraceExpansion - check(
+ input = Seq("--all", "{core,application}.compile"),
+ expectedSelectors = List(
+ List(Label("core"), Label("compile")),
+ List(Label("application"), Label("compile"))
+ ),
+ expectedArgs = Seq.empty
+ )
+ 'multiSelectorsBraceExpansionWithArgs - check(
+ input = Seq("--all", "{core,application}.run", "--", "hello", "world"),
+ expectedSelectors = List(
+ List(Label("core"), Label("run")),
+ List(Label("application"), Label("run"))
+ ),
+ expectedArgs = Seq("hello", "world")
+ )
+ 'multiSelectorsBraceExpansionWithCross - check(
+ input = Seq("--all", "bridges[2.12.4,jvm].{test,jar}"),
+ expectedSelectors = List(
+ List(Label("bridges"), Cross(Seq("2.12.4", "jvm")), Label("test")),
+ List(Label("bridges"), Cross(Seq("2.12.4", "jvm")), Label("jar"))
+ ),
+ expectedArgs = Seq.empty
+ )
+ 'multiSelectorsBraceExpansionInsideCross - check(
+ input = Seq("--all", "bridges[{2.11.11,2.11.8}].jar"),
+ expectedSelectors = List(
+ List(Label("bridges"), Cross(Seq("2.11.11")), Label("jar")),
+ List(Label("bridges"), Cross(Seq("2.11.8")), Label("jar"))
+ ),
+ expectedArgs = Seq.empty
+ )
+ 'multiSelectorsBraceExpansionWithoutAll - {
+ assert(
+ ParseArgs(Seq("{core,application}.compile")) == Left(
+ "Please use --all flag to run multiple tasks")
+ )
+ }
+ 'multiSelectorsWithoutAllAsSingle - check( // this is how it works when we pass multiple tasks without --all flag
+ input = Seq("core.compile", "application.compile"),
+ expectedSelectors = List(
+ List(Label("core"), Label("compile"))
+ ),
+ expectedArgs = Seq("application.compile")
+ )
+ }
+ }
+
+}