From fb7d39ad7f6dee1580bd30ec96ae494d97f146f1 Mon Sep 17 00:00:00 2001 From: Li Haoyi Date: Sat, 10 Feb 2018 00:21:42 -0800 Subject: fix tests --- .../test/src/mill/integration/AmmoniteTests.scala | 2 +- main/src/mill/main/Resolve.scala | 17 +++++++++------ main/test/src/mill/main/MainTests.scala | 24 +++++++++++----------- main/test/src/mill/util/ParseArgsTest.scala | 23 ++++++++++++--------- main/test/src/mill/util/ScriptTestSuite.scala | 5 ++--- 5 files changed, 39 insertions(+), 32 deletions(-) diff --git a/integration/test/src/mill/integration/AmmoniteTests.scala b/integration/test/src/mill/integration/AmmoniteTests.scala index 22bd3cb8..f5906dd2 100644 --- a/integration/test/src/mill/integration/AmmoniteTests.scala +++ b/integration/test/src/mill/integration/AmmoniteTests.scala @@ -19,7 +19,7 @@ object AmmoniteTests extends IntegrationTestSuite("MILL_AMMONITE_REPO", "ammonit ) val compileResult = eval( - "--all", s"{shell,sshd,amm,integration}[$scalaVersion].test.compile" + "all", s"{shell,sshd,amm,integration}[$scalaVersion].test.compile" ) assert( diff --git a/main/src/mill/main/Resolve.scala b/main/src/mill/main/Resolve.scala index 507b06a3..95fff5f1 100644 --- a/main/src/mill/main/Resolve.scala +++ b/main/src/mill/main/Resolve.scala @@ -101,7 +101,7 @@ object Resolve extends Resolve[NamedTask[Any]]{ val command = invokeCommand(obj, last).headOption command orElse target orElse runDefault.flatten.headOption match { - case None => Left("Cannot resolve task " + + case None => Left("Cannot resolve " + Segments((Segment.Label(last) :: revSelectorsSoFar).reverse: _*).render ) // Contents of `either` *must* be a `Task`, because we only select @@ -130,19 +130,24 @@ abstract class Resolve[R: ClassTag] { case Segment.Label(last) :: Nil => endResolve(obj, revSelectorsSoFar, last, discover, rest) - case head :: tail => val newRevSelectorsSoFar = head :: revSelectorsSoFar + def resolveFailureMsg = Left( - "Cannot resolve module " + Segments(newRevSelectorsSoFar.reverse:_*).render + "Cannot resolve " + Segments(newRevSelectorsSoFar.reverse:_*).render ) def recurse(searchModules: Seq[Module]) = { val matching = searchModules .map(resolve(tail, _, discover, rest, remainingCrossSelectors, newRevSelectorsSoFar)) - .collect{case Right(vs) => vs}.flatten - if (matching.nonEmpty)Right(matching) - else resolveFailureMsg + matching match{ + case Seq(Left(err)) => Left(err) + case items => + items.collect{case Right(v) => v} match{ + case Nil => resolveFailureMsg + case values => Right(values.flatten) + } + } } head match{ case Segment.Label(singleLabel) => diff --git a/main/test/src/mill/main/MainTests.scala b/main/test/src/mill/main/MainTests.scala index d4b90b2f..87b3f7ab 100644 --- a/main/test/src/mill/main/MainTests.scala +++ b/main/test/src/mill/main/MainTests.scala @@ -27,8 +27,8 @@ object MainTests extends TestSuite{ 'single - { val check = MainTests.check(singleton) _ 'pos - check("single", Right(Seq(_.single))) - 'neg1 - check("doesntExist", Left("Cannot resolve task doesntExist")) - 'neg2 - check("single.doesntExist", Left("Cannot resolve module single")) + 'neg1 - check("doesntExist", Left("Cannot resolve doesntExist")) + 'neg2 - check("single.doesntExist", Left("Cannot resolve single")) 'neg3 - check("", Left("Selector cannot be empty")) } 'nested - { @@ -36,10 +36,10 @@ object MainTests extends TestSuite{ 'pos1 - check("single", Right(Seq(_.single))) 'pos2 - check("nested.single", Right(Seq(_.nested.single))) 'pos3 - check("classInstance.single", Right(Seq(_.classInstance.single))) - 'neg1 - check("doesntExist", Left("Cannot resolve task doesntExist")) - 'neg2 - check("single.doesntExist", Left("Cannot resolve module single")) - 'neg3 - check("nested.doesntExist", Left("Cannot resolve task nested.doesntExist")) - 'neg4 - check("classInstance.doesntExist", Left("Cannot resolve task classInstance.doesntExist")) + 'neg1 - check("doesntExist", Left("Cannot resolve doesntExist")) + 'neg2 - check("single.doesntExist", Left("Cannot resolve single")) + 'neg3 - check("nested.doesntExist", Left("Cannot resolve nested.doesntExist")) + 'neg4 - check("classInstance.doesntExist", Left("Cannot resolve classInstance.doesntExist")) 'wildcard - check( "_.single", Right(Seq( @@ -49,11 +49,11 @@ object MainTests extends TestSuite{ ) 'wildcardNeg - check( "_._.single", - Left("Cannot resolve module _") + Left("Cannot resolve _") ) 'wildcardNeg2 - check( "_._.__", - Left("Cannot resolve module _") + Left("Cannot resolve _") ) 'wildcard2 - check( "__.single", @@ -78,9 +78,9 @@ object MainTests extends TestSuite{ val check = MainTests.check(singleCross) _ 'pos1 - check("cross[210].suffix", Right(Seq(_.cross("210").suffix))) 'pos2 - check("cross[211].suffix", Right(Seq(_.cross("211").suffix))) - 'neg1 - check("cross[210].doesntExist", Left("Cannot resolve task cross[210].doesntExist")) - 'neg2 - check("cross[doesntExist].doesntExist", Left("Cannot resolve cross cross[doesntExist]")) - 'neg2 - check("cross[doesntExist].suffix", Left("Cannot resolve cross cross[doesntExist]")) + 'neg1 - check("cross[210].doesntExist", Left("Cannot resolve cross[210].doesntExist")) + 'neg2 - check("cross[doesntExist].doesntExist", Left("Cannot resolve cross[doesntExist]")) + 'neg2 - check("cross[doesntExist].suffix", Left("Cannot resolve cross[doesntExist]")) 'wildcard - check( "cross[_].suffix", Right(Seq( @@ -111,7 +111,7 @@ object MainTests extends TestSuite{ 'wildcard - { 'labelNeg - check( "_.suffix", - Left("Cannot resolve module _") + Left("Cannot resolve _.suffix") ) 'labelPos - check( "__.suffix", diff --git a/main/test/src/mill/util/ParseArgsTest.scala b/main/test/src/mill/util/ParseArgsTest.scala index 3c12525e..caa1afec 100644 --- a/main/test/src/mill/util/ParseArgsTest.scala +++ b/main/test/src/mill/util/ParseArgsTest.scala @@ -1,6 +1,6 @@ package mill.util -import mill.define.Segment +import mill.define.{Segment, Segments} import mill.define.Segment.{Cross, Label} import utest._ @@ -43,20 +43,19 @@ object ParseArgsTest extends TestSuite { multiSelect = false ) 'multiSelectors - check( - input = Seq("--all", "core.jar", "core.docsJar", "core.sourcesJar"), + input = Seq("core.jar", "core.docsJar", "core.sourcesJar"), expectedSelectors = Seq("core.jar", "core.docsJar", "core.sourcesJar"), expectedArgs = Seq.empty, multiSelect = true ) 'multiSelectorsSeq - check( - input = Seq("--seq", "core.jar", "core.docsJar", "core.sourcesJar"), + input = Seq("core.jar", "core.docsJar", "core.sourcesJar"), expectedSelectors = Seq("core.jar", "core.docsJar", "core.sourcesJar"), expectedArgs = Seq.empty, multiSelect = true ) 'multiSelectorsWithArgs - check( - input = Seq("--all", - "core.compile", + input = Seq("core.compile", "application.runMain", "--", "Main", @@ -67,8 +66,7 @@ object ParseArgsTest extends TestSuite { multiSelect = true ) 'multiSelectorsWithArgsWithAllInArgs - check( - input = Seq("--all", - "core.compile", + input = Seq("core.compile", "application.runMain", "--", "Main", @@ -230,10 +228,15 @@ object ParseArgsTest extends TestSuite { multiSelect = true ) 'multiSelectorsBraceExpansionWithoutAll - { - assert( - ParseArgs(Seq("{core,application}.compile"), multiSelect = false) == Left( - "Please use --all flag to run multiple tasks") + val res = ParseArgs(Seq("{core,application}.compile"), multiSelect = false) + val expected = Right( + List( + None -> Segments(Label("core"), Label("compile")), + None -> Segments(Label("application"), Label("compile")) + ), + Nil ) + assert(res == expected) } 'multiSelectorsWithoutAllAsSingle - check( // this is how it works when we pass multiple tasks without --all flag diff --git a/main/test/src/mill/util/ScriptTestSuite.scala b/main/test/src/mill/util/ScriptTestSuite.scala index a613d1dc..0d1ff43a 100644 --- a/main/test/src/mill/util/ScriptTestSuite.scala +++ b/main/test/src/mill/util/ScriptTestSuite.scala @@ -3,7 +3,6 @@ package mill.util import java.io.{ByteArrayInputStream, ByteArrayOutputStream, PrintStream} import ammonite.ops._ -import mill.util.ParseArgs import utest._ abstract class ScriptTestSuite extends TestSuite{ @@ -11,8 +10,8 @@ abstract class ScriptTestSuite extends TestSuite{ def scriptSourcePath: Path val workspacePath = pwd / 'target / 'workspace / workspaceSlug - val stdOutErr = new PrintStream(new ByteArrayOutputStream()) -// val stdOutErr = new PrintStream(System.out) +// val stdOutErr = new PrintStream(new ByteArrayOutputStream()) + val stdOutErr = new PrintStream(System.out) val stdIn = new ByteArrayInputStream(Array()) val runner = new mill.main.MainRunner( ammonite.main.Cli.Config(wd = workspacePath), -- cgit v1.2.3