diff options
author | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-26 15:49:17 -0800 |
---|---|---|
committer | Li Haoyi <haoyi.sg@gmail.com> | 2017-11-26 15:49:17 -0800 |
commit | b12833e99e1e0939ec35ec31a15631e777cd7446 (patch) | |
tree | 210cc3ad55e31dbadd02844e71bf508258873484 /scalaplugin | |
parent | 4219303cb85c5f892c548b129d6350a20df51518 (diff) | |
download | mill-b12833e99e1e0939ec35ec31a15631e777cd7446.tar.gz mill-b12833e99e1e0939ec35ec31a15631e777cd7446.tar.bz2 mill-b12833e99e1e0939ec35ec31a15631e777cd7446.zip |
Acyclic test suite works now that we can fork and set a proper working directory, but only when run alone (???)
Diffstat (limited to 'scalaplugin')
3 files changed, 85 insertions, 32 deletions
diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala index 53c98be1..504fe93e 100644 --- a/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala +++ b/scalaplugin/src/main/scala/mill/scalaplugin/ScalaModule.scala @@ -2,19 +2,21 @@ package mill package scalaplugin import java.io.File +import java.net.URLClassLoader import java.util.Optional import ammonite.ops._ import coursier.{Cache, Fetch, MavenRepository, Repository, Resolution} import mill.define.Task import mill.define.Task.{Module, TaskModule} -import mill.eval.PathRef +import mill.eval.{PathRef, Result} +import mill.modules.Jvm import mill.modules.Jvm.{createAssembly, createJar, subprocess} import sbt.internal.inc._ import sbt.internal.util.{ConsoleOut, MainAppender} import sbt.util.{InterfaceUtil, LogExchange} import xsbti.compile.{CompilerCache => _, FileAnalysisStore => _, ScalaInstance => _, _} - +import mill.util.JsonFormatters._ @@ -165,13 +167,39 @@ import ScalaModule._ trait TestScalaModule extends ScalaModule with TaskModule { override def defaultCommandName() = "test" def testFramework: T[String] + + def forkWorkingDir = ammonite.ops.pwd + def forkTest(args: String*) = T.command{ + val outputPath = tmp.dir()/"out.json" + Jvm.subprocess( + "mill.scalaplugin.TestRunner", + getClass.getClassLoader.asInstanceOf[URLClassLoader].getURLs.toList.map( + u => Path(new java.io.File(u.toURI)) + ), + Seq( + testFramework(), + (runDepClasspath().map(_.path) :+ compile().path).mkString(" "), + Seq(compile().path).mkString(" "), + args.mkString(" "), + outputPath.toString + ), + workingDir = forkWorkingDir + ) + upickle.default.read[Option[String]](ammonite.ops.read(outputPath)) match{ + case Some(errMsg) => Result.Failure(errMsg) + case None => Result.Success(()) + } + } def test(args: String*) = T.command{ TestRunner( testFramework(), runDepClasspath().map(_.path) :+ compile().path, Seq(compile().path), args - ) + ) match{ + case Some(errMsg) => Result.Failure(errMsg) + case None => Result.Success(()) + } } } trait ScalaModule extends Module with TaskModule{ outer => diff --git a/scalaplugin/src/main/scala/mill/scalaplugin/TestRunner.scala b/scalaplugin/src/main/scala/mill/scalaplugin/TestRunner.scala index 09e41a74..03292b68 100644 --- a/scalaplugin/src/main/scala/mill/scalaplugin/TestRunner.scala +++ b/scalaplugin/src/main/scala/mill/scalaplugin/TestRunner.scala @@ -37,11 +37,20 @@ object TestRunner { } testClasses } - + def main(args: Array[String]): Unit = { + val result = apply( + frameworkName = args(0), + entireClasspath = args(1).split(" ").map(Path(_)), + testClassfilePath = args(2).split(" ").map(Path(_)), + args = args(3) match{ case "" => Nil case x => x.split(" ").toList } + ) + val outputPath = args(4) + ammonite.ops.write(Path(outputPath), upickle.default.write(result)) + } def apply(frameworkName: String, entireClasspath: Seq[Path], testClassfilePath: Seq[Path], - args: Seq[String]): mill.eval.Result[Unit] = { + args: Seq[String]): Option[String] = { val outerClassLoader = getClass.getClassLoader val cl = new URLClassLoader( entireClasspath.map(_.toIO.toURI.toURL).toArray, @@ -93,13 +102,13 @@ object TestRunner { } val doneMsg = runner.done() val msg = - if (doneMsg.trim.nonEmpty)doneMsg + if (doneMsg.trim.nonEmpty) doneMsg else{ val grouped = events.groupBy(x => x).mapValues(_.length).filter(_._2 != 0).toList.sorted grouped.map{case (k, v) => k + ": " + v}.mkString(",") } println(msg) - if (events.count(Set(Status.Error, Status.Failure)) == 0) mill.eval.Result.Success(()) - else mill.eval.Result.Failure(msg) + if (events.count(Set(Status.Error, Status.Failure)) == 0) None + else Some(msg) } } diff --git a/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala b/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala index 0fc7d4af..61da0a47 100644 --- a/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala +++ b/scalaplugin/src/test/scala/mill/scalaplugin/AcyclicTests.scala @@ -26,6 +26,7 @@ object AcyclicBuild{ ) object test extends this.Tests{ def basePath = AcyclicTests.workspacePath + override def forkWorkingDir = pwd/'scalaplugin/'src/'test/'resource/'acyclic override def ivyDeps = Seq( Dep("com.lihaoyi", "utest", "0.6.0") ) @@ -38,28 +39,29 @@ object AcyclicTests extends TestSuite{ val workspacePath = pwd / 'target / 'workspace / 'acyclic val srcPath = pwd / 'scalaplugin / 'src / 'test / 'resource / 'acyclic val tests = Tests{ - 'acyclic - { - rm(workspacePath) - mkdir(workspacePath/up) - cp(srcPath, workspacePath) - val mapping = Discovered.mapping(AcyclicBuild) - def eval[T](t: Task[T]): Either[Result.Failing, (T, Int)] = { - val evaluator = new Evaluator(workspacePath, mapping, _ => ()) - val evaluated = evaluator.evaluate(OSet(t)) - - if (evaluated.failing.keyCount == 0){ - Right(Tuple2( - evaluated.rawValues(0).asInstanceOf[Result.Success[T]].value, - evaluated.evaluated.collect{ - case t: Target[_] if mapping.contains(t) => t - case t: mill.define.Command[_] => t - }.size - )) - }else{ - Left(evaluated.failing.lookupKey(evaluated.failing.keys().next).items.next()) - } + rm(workspacePath) + mkdir(workspacePath/up) + cp(srcPath, workspacePath) + val mapping = Discovered.mapping(AcyclicBuild) + def eval[T](t: Task[T]): Either[Result.Failing, (T, Int)] = { + val evaluator = new Evaluator(workspacePath, mapping, _ => ()) + val evaluated = evaluator.evaluate(OSet(t)) + + if (evaluated.failing.keyCount == 0){ + Right(Tuple2( + evaluated.rawValues(0).asInstanceOf[Result.Success[T]].value, + evaluated.evaluated.collect{ + case t: Target[_] if mapping.contains(t) => t + case t: mill.define.Command[_] => t + }.size + )) + }else{ + Left(evaluated.failing.lookupKey(evaluated.failing.keys().next).items.next()) } + } + val packageScala = workspacePath/'src/'main/'scala/'acyclic/"package.scala" + 'acyclic - { // We can compile val Right((pathRef, evalCount)) = eval(AcyclicBuild.acyclic("2.12.4").compile) val outputPath = pathRef.path @@ -74,7 +76,6 @@ object AcyclicTests extends TestSuite{ val Right((_, evalCount2)) = eval(AcyclicBuild.acyclic("2.12.4").compile) assert(evalCount2 == 0) - val packageScala = workspacePath/'src/'main/'scala/'acyclic/"package.scala" write.append(packageScala, "\n") // Caches are invalidated if code is changed @@ -89,10 +90,25 @@ object AcyclicTests extends TestSuite{ write.write(packageScala, read(packageScala).dropRight(3)) - val Right((_, _)) = eval(AcyclicBuild.acyclic("2.12.4").compile) + val Right(_) = eval(AcyclicBuild.acyclic("2.12.4").compile) + + // Still doesn't work =( + // val Right(_) = eval(AcyclicBuild.acyclic("2.12.4").test.forkTest()) + } + + 'tests - { + // Tests can run + val Right(_) = eval(AcyclicBuild.acyclic("2.12.4").test.forkTest()) + + // Be broken + write.append(packageScala, "\n}}") + eval(AcyclicBuild.acyclic("2.12.4").test.compile) + val Left(_) = eval(AcyclicBuild.acyclic("2.12.4").test.forkTest()) + + // And run again when fixed + write.write(packageScala, read(packageScala).dropRight(3)) -// Tests can run -// val Right((_, _)) = eval(AcyclicBuild.acyclic("2.12.4").test.test()) + val Right(_) = eval(AcyclicBuild.acyclic("2.12.4").test.forkTest()) } } } |