diff options
Diffstat (limited to 'scalaplugin/src')
6 files changed, 41 insertions, 47 deletions
diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/GenIdea.scala b/scalaplugin/src/main/scala/mill/scalaplugin/GenIdea.scala index 07a9e998..86e33d8d 100644 --- a/scalaplugin/src/main/scala/mill/scalaplugin/GenIdea.scala +++ b/scalaplugin/src/main/scala/mill/scalaplugin/GenIdea.scala @@ -16,20 +16,19 @@ object GenIdea { val workspacePath = pwd / 'out - val evaluator = new Evaluator(workspacePath, mapping.value, new PrintLogger(true)) + val evaluator = new Evaluator(workspacePath, mapping, new PrintLogger(true)) for((relPath, xml) <- xmlFileLayout(mapping, evaluator)){ write.over(pwd/relPath, pp.format(xml)) } } - def xmlFileLayout[T](mapping: Discovered.Mapping[T], - evaluator: Evaluator): Seq[(RelPath, scala.xml.Node)] = { + def xmlFileLayout[T](evaluator: Evaluator): Seq[(RelPath, scala.xml.Node)] = { val modules = Mirror - .traverse(mapping.base, mapping.mirror){ (h, p) => - h.node(mapping.base, p.reverse.map{case Mirror.Segment.Cross(vs) => vs.toList case _ => Nil}.toList) match { + .traverse(evaluator.mapping.base, evaluator.mapping.mirror){ (h, p) => + h.node(evaluator.mapping.base, p.reverse.map{case Mirror.Segment.Cross(vs) => vs.toList case _ => Nil}.toList) match { case m: ScalaModule => Seq(p -> m) case _ => Nil } diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala b/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala index 42d93c2a..71bf5213 100644 --- a/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala +++ b/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala @@ -53,15 +53,10 @@ object AcyclicTests extends TestSuite{ mkdir(workspacePath/up) cp(srcPath, workspacePath) val mapping = Discovered.mapping(AcyclicBuild) - def eval[T](t: Task[T]) = TestEvaluator.eval(mapping.value, workspacePath)(t) + val eval = new TestEvaluator(mapping, workspacePath) val packageScala = workspacePath/'src/'main/'scala/'acyclic/"package.scala" - 'scala210 - check("2.10.6", full = false) - 'scala211 - check("2.11.8", full = false) - 'scala2123 - check("2.12.3", full = true) - 'scala2124 - check("2.12.4", full = false) - val allBinaryVersions = Seq("2.10", "2.11", "2.12") def check(scalaVersion: String, full: Boolean) = { // Dependencies are right; make sure every dependency is of the correct @@ -115,5 +110,10 @@ object AcyclicTests extends TestSuite{ } } + 'scala210 - check("2.10.6", full = false) + 'scala211 - check("2.11.8", full = false) + 'scala2123 - check("2.12.3", full = true) + 'scala2124 - check("2.12.4", full = false) + } } diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/BetterFilesTests.scala b/scalaplugin/src/test/scala/mill/scalaplugin/BetterFilesTests.scala index c9c8618c..84e83a02 100644 --- a/scalaplugin/src/test/scala/mill/scalaplugin/BetterFilesTests.scala +++ b/scalaplugin/src/test/scala/mill/scalaplugin/BetterFilesTests.scala @@ -97,7 +97,7 @@ object BetterFilesTests extends TestSuite{ mkdir(workspacePath/up) cp(srcPath, workspacePath) val mapping = Discovered.mapping(BetterFilesBuild) - def eval[T](t: Task[T]) = TestEvaluator.eval(mapping.value, workspacePath)(t) + val eval = new TestEvaluator(mapping, workspacePath) 'test - { diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala b/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala index 41783efb..2ada6463 100644 --- a/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala +++ b/scalaplugin/src/test/scala/mill/scalaplugin/HelloWorldTests.scala @@ -6,7 +6,7 @@ import mill._ import mill.define.{Target, Task} import mill.discover.Discovered import mill.discover.Mirror.LabelledTarget -import mill.eval.Result +import mill.eval.{Evaluator, Result} import mill.scalaplugin.publish._ import sbt.internal.inc.CompileFailed import utest._ @@ -57,8 +57,10 @@ object HelloWorldTests extends TestSuite { val outputPath = workspacePath / 'out val mainObject = workspacePath / 'src / 'main / 'scala / "Main.scala" - def eval[T](t: Task[T], mapping: Map[Target[_], LabelledTarget[_]]) = - TestEvaluator.eval(mapping, outputPath)(t) + def eval[T](t: Task[T], mapping: Discovered.Mapping[_]) = { + val eval = new TestEvaluator(mapping, workspacePath) + eval(t) + } val helloWorldMapping = Discovered.mapping(HelloWorld) val helloWorldWithMainMapping = Discovered.mapping(HelloWorldWithMain) @@ -68,7 +70,7 @@ object HelloWorldTests extends TestSuite { 'scalaVersion - { 'fromBuild - { val Right((result, evalCount)) = - eval(HelloWorld.scalaVersion, helloWorldMapping.value) + eval(HelloWorld.scalaVersion, helloWorldMapping) assert( result == "2.12.4", @@ -82,7 +84,7 @@ object HelloWorldTests extends TestSuite { val Right((result, evalCount)) = eval(HelloWorldScalaOverride.scalaVersion, - Discovered.mapping(HelloWorldScalaOverride).value) + Discovered.mapping(HelloWorldScalaOverride)) assert( result == "2.11.11", @@ -93,7 +95,7 @@ object HelloWorldTests extends TestSuite { 'scalacOptions - { 'emptyByDefault - { val Right((result, evalCount)) = - eval(HelloWorld.scalacOptions, helloWorldMapping.value) + eval(HelloWorld.scalacOptions, helloWorldMapping) assert( result.isEmpty, @@ -103,7 +105,7 @@ object HelloWorldTests extends TestSuite { 'override - { val Right((result, evalCount)) = eval(HelloWorldFatalWarnings.scalacOptions, - Discovered.mapping(HelloWorldFatalWarnings).value) + Discovered.mapping(HelloWorldFatalWarnings)) assert( result == Seq("-Ywarn-unused", "-Xfatal-warnings"), @@ -114,7 +116,7 @@ object HelloWorldTests extends TestSuite { 'compile - { 'fromScratch - { val Right((result, evalCount)) = - eval(HelloWorld.compile, helloWorldMapping.value) + eval(HelloWorld.compile, helloWorldMapping) val outPath = result.classes.path val analysisFile = result.analysisFile @@ -131,31 +133,30 @@ object HelloWorldTests extends TestSuite { // don't recompile if nothing changed val Right((_, unchangedEvalCount)) = - eval(HelloWorld.compile, helloWorldMapping.value) + eval(HelloWorld.compile, helloWorldMapping) assert(unchangedEvalCount == 0) } 'recompileOnChange - { val Right((_, freshCount)) = - eval(HelloWorld.compile, helloWorldMapping.value) + eval(HelloWorld.compile, helloWorldMapping) assert(freshCount > 0) write.append(mainObject, "\n") val Right((_, incCompileCount)) = - eval(HelloWorld.compile, helloWorldMapping.value) + eval(HelloWorld.compile, helloWorldMapping) assert(incCompileCount > 0, incCompileCount < freshCount) } 'failOnError - { write.append(mainObject, "val x: ") val Left(Result.Exception(err)) = - eval(HelloWorld.compile, helloWorldMapping.value) + eval(HelloWorld.compile, helloWorldMapping) assert(err.isInstanceOf[CompileFailed]) val (compilePath, compileMetadataPath) = - TestEvaluator.resolveDestPaths(outputPath)( - helloWorldMapping.value(HelloWorld.compile)) + Evaluator.resolveDestPaths(outputPath, helloWorldMapping.value(HelloWorld.compile)) assert( ls.rec(compilePath / 'classes).isEmpty, @@ -166,7 +167,7 @@ object HelloWorldTests extends TestSuite { // compilation fails because of "-Xfatal-warnings" flag val Left(Result.Exception(err)) = eval(HelloWorldFatalWarnings.compile, - Discovered.mapping(HelloWorldFatalWarnings).value) + Discovered.mapping(HelloWorldFatalWarnings)) assert(err.isInstanceOf[CompileFailed]) } @@ -174,7 +175,7 @@ object HelloWorldTests extends TestSuite { 'runMain - { 'runMainObject - { val Right((_, evalCount)) = - eval(HelloWorld.runMain("Main"), helloWorldMapping.value) + eval(HelloWorld.runMain("Main"), helloWorldMapping) assert(evalCount > 0) @@ -186,7 +187,7 @@ object HelloWorldTests extends TestSuite { } 'notRunInvalidMainObject - { val Left(Result.Exception(err)) = - eval(HelloWorld.runMain("Invalid"), helloWorldMapping.value) + eval(HelloWorld.runMain("Invalid"), helloWorldMapping) assert( err.isInstanceOf[InteractiveShelloutException] @@ -196,7 +197,7 @@ object HelloWorldTests extends TestSuite { write.append(mainObject, "val x: ") val Left(Result.Exception(err)) = - eval(HelloWorld.runMain("Main"), helloWorldMapping.value) + eval(HelloWorld.runMain("Main"), helloWorldMapping) assert( err.isInstanceOf[CompileFailed] @@ -206,7 +207,7 @@ object HelloWorldTests extends TestSuite { 'run - { 'runIfMainClassProvided - { val Right((_, evalCount)) = - eval(HelloWorldWithMain.run(), helloWorldWithMainMapping.value) + eval(HelloWorldWithMain.run(), helloWorldWithMainMapping) assert(evalCount > 0) @@ -218,7 +219,7 @@ object HelloWorldTests extends TestSuite { } 'notRunWithoutMainClass - { val Left(Result.Exception(err)) = - eval(HelloWorld.run(), helloWorldMapping.value) + eval(HelloWorld.run(), helloWorldMapping) assert( err.isInstanceOf[RuntimeException] @@ -228,7 +229,7 @@ object HelloWorldTests extends TestSuite { 'jar - { 'nonEmpty - { val Right((result, evalCount)) = - eval(HelloWorld.jar, helloWorldMapping.value) + eval(HelloWorld.jar, helloWorldMapping) assert( exists(result.path), @@ -253,7 +254,7 @@ object HelloWorldTests extends TestSuite { } 'runJar - { val Right((result, evalCount)) = - eval(HelloWorldWithMain.jar, helloWorldWithMainMapping.value) + eval(HelloWorldWithMain.jar, helloWorldWithMainMapping) assert( exists(result.path), @@ -269,7 +270,7 @@ object HelloWorldTests extends TestSuite { ) } 'logOutputToFile { - eval(HelloWorld.compile, helloWorldMapping.value) + eval(HelloWorld.compile, helloWorldMapping) val logFile = outputPath / "compile.log" assert(exists(logFile)) diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/JawnTests.scala b/scalaplugin/src/test/scala/mill/scalaplugin/JawnTests.scala index 892857c9..97dff017 100644 --- a/scalaplugin/src/test/scala/mill/scalaplugin/JawnTests.scala +++ b/scalaplugin/src/test/scala/mill/scalaplugin/JawnTests.scala @@ -74,7 +74,7 @@ object JawnTests extends TestSuite{ mkdir(workspacePath/up) cp(srcPath, workspacePath) val mapping = Discovered.mapping(JawnBuild) - def eval[T](t: Task[T]) = TestEvaluator.eval(mapping.value, workspacePath)(t) + val eval = new TestEvaluator(mapping, workspacePath) 'test - { def compileOutput = workspacePath / 'jawn / "2.12.3" / 'Parser / 'compile diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/TestEvaluator.scala b/scalaplugin/src/test/scala/mill/scalaplugin/TestEvaluator.scala index 58e4f5f3..05d53e8d 100644 --- a/scalaplugin/src/test/scala/mill/scalaplugin/TestEvaluator.scala +++ b/scalaplugin/src/test/scala/mill/scalaplugin/TestEvaluator.scala @@ -2,20 +2,14 @@ package mill.scalaplugin import ammonite.ops.Path import mill.define.{Target, Task} -import mill.discover.Mirror +import mill.discover.{Discovered, Mirror} import mill.eval.{Evaluator, Result} import mill.util.{DummyLogger, OSet, PrintLogger} -object TestEvaluator { +class TestEvaluator(mapping: Discovered.Mapping[_], workspacePath: Path){ + val evaluator = new Evaluator(workspacePath, mapping, DummyLogger) - - def resolveDestPaths(workspacePath: Path)(t: Mirror.LabelledTarget[_]): (Path, Path) = { - new Evaluator(workspacePath, Map.empty, DummyLogger).resolveDestPaths(t) - } - - def eval[T](mapping: Map[Target[_], Mirror.LabelledTarget[_]], - workspacePath: Path)(t: Task[T]): Either[Result.Failing, (T, Int)] = { - val evaluator = new Evaluator(workspacePath, mapping, DummyLogger) + def apply[T](t: Task[T]): Either[Result.Failing, (T, Int)] = { val evaluated = evaluator.evaluate(OSet(t)) if (evaluated.failing.keyCount == 0) { @@ -23,7 +17,7 @@ object TestEvaluator { Tuple2( evaluated.rawValues.head.asInstanceOf[Result.Success[T]].value, evaluated.evaluated.collect { - case t: Target[_] if mapping.contains(t) => t + case t: Target[_] if mapping.value.contains(t) => t case t: mill.define.Command[_] => t }.size )) |