summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLi Haoyi <haoyi.sg@gmail.com>2018-02-03 09:52:00 -0800
committerLi Haoyi <haoyi.sg@gmail.com>2018-02-03 11:37:40 -0800
commit45fbcbb71b991335d84069b45bbcff3961c1ba15 (patch)
tree8da416d2f2e4faa66e2403301dc2d1fa50b2bcff
parentbfd64f104a283b70ad57a66c8ac7d4dc3bda9e6f (diff)
downloadmill-45fbcbb71b991335d84069b45bbcff3961c1ba15.tar.gz
mill-45fbcbb71b991335d84069b45bbcff3961c1ba15.tar.bz2
mill-45fbcbb71b991335d84069b45bbcff3961c1ba15.zip
fix scalalib tests
-rw-r--r--core/src/mill/eval/Evaluator.scala5
-rw-r--r--core/src/mill/modules/Jvm.scala8
-rw-r--r--core/test/src/mill/define/BasePathTests.scala33
-rw-r--r--core/test/src/mill/eval/JavaCompileJarTests.scala2
-rw-r--r--core/test/src/mill/util/TestEvaluator.scala16
-rw-r--r--core/test/src/mill/util/TestUtil.scala20
-rw-r--r--scalajslib/src/mill/scalajslib/ScalaJSBridge.scala5
-rw-r--r--scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala7
-rw-r--r--scalalib/src/mill/scalalib/ScalaModule.scala3
-rw-r--r--scalalib/test/resources/gen-idea/idea_modules/iml10
-rw-r--r--scalalib/test/src/mill/scalalib/GenIdeaTests.scala5
-rw-r--r--scalalib/test/src/mill/scalalib/HelloWorldTests.scala205
12 files changed, 167 insertions, 152 deletions
diff --git a/core/src/mill/eval/Evaluator.scala b/core/src/mill/eval/Evaluator.scala
index 78317474..9d65e95f 100644
--- a/core/src/mill/eval/Evaluator.scala
+++ b/core/src/mill/eval/Evaluator.scala
@@ -45,6 +45,7 @@ class Evaluator[T](val outPath: Path,
val finalTaskOverrides = t match{
case t: Target[_] =>
rootModule.millInternal.segmentsToTargets.get(segments).fold(0)(_.ctx.overrides)
+
case c: mill.define.Command[_] =>
def findMatching(cls: Class[_]): Option[Seq[(Int, EntryPoint[_])]] = {
discover.value.get(cls) match{
@@ -56,8 +57,8 @@ class Evaluator[T](val outPath: Path,
}
}
}
- val public = findMatching(c.cls).get.find(_._2.name == c.ctx.segment.pathSegments.head).get._1
- public
+ findMatching(c.cls).get.find(_._2.name == c.ctx.segment.pathSegments.head).get._1
+
case c: mill.define.Worker[_] => 0
}
diff --git a/core/src/mill/modules/Jvm.scala b/core/src/mill/modules/Jvm.scala
index 4ac03a97..297dcf1f 100644
--- a/core/src/mill/modules/Jvm.scala
+++ b/core/src/mill/modules/Jvm.scala
@@ -67,9 +67,7 @@ object Jvm {
body: ClassLoader => T): T = {
val cl = if (classLoaderOverrideSbtTesting) {
val outerClassLoader = getClass.getClassLoader
- new URLClassLoader(
- classPath.map(_.toIO.toURI.toURL).toArray,
- ClassLoader.getSystemClassLoader().getParent()){
+ new URLClassLoader(classPath.map(_.toIO.toURI.toURL).toArray, null){
override def findClass(name: String) = {
if (name.startsWith("sbt.testing.")){
outerClassLoader.loadClass(name)
@@ -79,9 +77,7 @@ object Jvm {
}
}
} else {
- new URLClassLoader(
- classPath.map(_.toIO.toURI.toURL).toArray,
- ClassLoader.getSystemClassLoader().getParent())
+ new URLClassLoader(classPath.map(_.toIO.toURI.toURL).toArray, null)
}
val oldCl = Thread.currentThread().getContextClassLoader
Thread.currentThread().setContextClassLoader(cl)
diff --git a/core/test/src/mill/define/BasePathTests.scala b/core/test/src/mill/define/BasePathTests.scala
index f7a1afa7..1f5b4037 100644
--- a/core/test/src/mill/define/BasePathTests.scala
+++ b/core/test/src/mill/define/BasePathTests.scala
@@ -7,41 +7,42 @@ import mill.{Module, T}
object BasePathTests extends TestSuite{
val testGraphs = new TestGraphs
val tests = Tests{
- def check(m: Module, segments: String*) = {
- val remaining = m.millSourcePath.relativeTo(pwd).segments.drop(1)
+ def check[T <: Module](m: T)(f: T => Module, segments: String*) = {
+ val remaining = f(m).millSourcePath.relativeTo(m.millSourcePath).segments
assert(remaining == segments)
}
'singleton - {
- check(testGraphs.singleton)
+ check(testGraphs.singleton)(identity)
}
'separateGroups - {
- check(TestGraphs.triangleTask)
+ check(TestGraphs.triangleTask)(identity)
}
'TraitWithModuleObject - {
- check(TestGraphs.TraitWithModuleObject.TraitModule,
+ check(TestGraphs.TraitWithModuleObject)(
+ _.TraitModule,
"TraitModule"
)
}
'nestedModuleNested - {
- check(TestGraphs.nestedModule.nested, "nested")
+ check(TestGraphs.nestedModule)(_.nested, "nested")
}
'nestedModuleInstance - {
- check(TestGraphs.nestedModule.classInstance, "classInstance")
+ check(TestGraphs.nestedModule)(_.classInstance, "classInstance")
}
'singleCross - {
- check(TestGraphs.singleCross.cross, "cross")
- check(TestGraphs.singleCross.cross("210"), "cross", "210")
- check(TestGraphs.singleCross.cross("211"), "cross", "211")
+ check(TestGraphs.singleCross)(_.cross, "cross")
+ check(TestGraphs.singleCross)(_.cross("210"), "cross", "210")
+ check(TestGraphs.singleCross)(_.cross("211"), "cross", "211")
}
'doubleCross - {
- check(TestGraphs.doubleCross.cross, "cross")
- check(TestGraphs.doubleCross.cross("210", "jvm"), "cross", "210", "jvm")
- check(TestGraphs.doubleCross.cross("212", "js"), "cross", "212", "js")
+ check(TestGraphs.doubleCross)(_.cross, "cross")
+ check(TestGraphs.doubleCross)(_.cross("210", "jvm"), "cross", "210", "jvm")
+ check(TestGraphs.doubleCross)(_.cross("212", "js"), "cross", "212", "js")
}
'nestedCrosses - {
- check(TestGraphs.nestedCrosses.cross, "cross")
- check(
- TestGraphs.nestedCrosses.cross("210").cross2("js"),
+ check(TestGraphs.nestedCrosses)(_.cross, "cross")
+ check(TestGraphs.nestedCrosses)(
+ _.cross("210").cross2("js"),
"cross", "210", "cross2", "js"
)
}
diff --git a/core/test/src/mill/eval/JavaCompileJarTests.scala b/core/test/src/mill/eval/JavaCompileJarTests.scala
index 9d1134b8..a67d669d 100644
--- a/core/test/src/mill/eval/JavaCompileJarTests.scala
+++ b/core/test/src/mill/eval/JavaCompileJarTests.scala
@@ -22,7 +22,7 @@ object JavaCompileJarTests extends TestSuite{
val tests = Tests{
'javac {
val javacSrcPath = pwd / 'core / 'test / 'resources / 'examples / 'javac
- val javacDestPath = TestEvaluator.getOutPath() / 'src
+ val javacDestPath = TestUtil.getOutPath() / 'src
mkdir(javacDestPath / up)
cp(javacSrcPath, javacDestPath)
diff --git a/core/test/src/mill/util/TestEvaluator.scala b/core/test/src/mill/util/TestEvaluator.scala
index 5684b4fd..ee92c2c2 100644
--- a/core/test/src/mill/util/TestEvaluator.scala
+++ b/core/test/src/mill/util/TestEvaluator.scala
@@ -13,13 +13,6 @@ object TestEvaluator{
implicit def implicitDisover[T]: Discover[T] = macro applyImpl[T]
val externalOutPath = pwd / 'target / 'external
- def getOutPath()(implicit fullName: sourcecode.FullName,
- tp: TestPath) = {
- pwd / 'target / 'workspace / (fullName.value.split('.') ++ tp.value)
- }
- def getOutPathStatic()(implicit fullName: sourcecode.FullName) = {
- pwd / 'target / 'workspace / fullName.value.split('.')
- }
def static[T <: TestUtil.TestBuild](module: T)
(implicit discover: Discover[T],
@@ -32,10 +25,10 @@ class TestEvaluator[T <: TestUtil.TestBuild](module: T)
(implicit discover: Discover[T],
fullName: sourcecode.FullName,
tp: TestPath){
- val outPath = TestEvaluator.getOutPath()
+ val outPath = TestUtil.getOutPath()
-// val logger = DummyLogger
- val logger = new PrintLogger(true, ammonite.util.Colors.Default, System.out, System.out, System.err)
+ val logger = DummyLogger
+// val logger = new PrintLogger(true, ammonite.util.Colors.Default, System.out, System.out, System.err)
val evaluator = new Evaluator(outPath, TestEvaluator.externalOutPath, module, discover, logger)
def apply[T](t: Task[T]): Either[Result.Failing, (T, Int)] = {
@@ -48,7 +41,8 @@ class TestEvaluator[T <: TestUtil.TestBuild](module: T)
evaluated.evaluated.collect {
case t: Target[_]
if module.millInternal.targets.contains(t)
- && !t.isInstanceOf[Input[_]] => t
+ && !t.isInstanceOf[Input[_]]
+ && !t.ctx.external => t
case t: mill.define.Command[_] => t
}.size
))
diff --git a/core/test/src/mill/util/TestUtil.scala b/core/test/src/mill/util/TestUtil.scala
index 3a025a91..1413e9c6 100644
--- a/core/test/src/mill/util/TestUtil.scala
+++ b/core/test/src/mill/util/TestUtil.scala
@@ -1,19 +1,37 @@
package mill.util
import ammonite.main.Router.Overrides
+import ammonite.ops.pwd
import mill.define._
import mill.eval.Result
import utest.assert
import mill.util.Strict.Agg
+import utest.framework.TestPath
+
import scala.collection.mutable
object TestUtil {
+ def getOutPath()(implicit fullName: sourcecode.FullName,
+ tp: TestPath) = {
+ pwd / 'target / 'workspace / (fullName.value.split('.') ++ tp.value)
+ }
+ def getOutPathStatic()(implicit fullName: sourcecode.FullName) = {
+ pwd / 'target / 'workspace / fullName.value.split('.')
+ }
+
+ def getSrcPathStatic()(implicit fullName: sourcecode.FullName) = {
+ pwd / 'target / 'worksources / fullName.value.split('.')
+ }
+ def getSrcPathBase() = {
+ pwd / 'target / 'worksources
+ }
+
trait TestBuild extends mill.define.Module
class BaseModule(implicit millModuleEnclosing0: sourcecode.Enclosing,
millModuleLine0: sourcecode.Line,
millName0: sourcecode.Name,
overrides: Overrides)
- extends mill.define.BaseModule(ammonite.ops.pwd / millModuleEnclosing0.value)
+ extends mill.define.BaseModule(getSrcPathBase() / millModuleEnclosing0.value.split("\\.| |#"))
with TestBuild
object test{
diff --git a/scalajslib/src/mill/scalajslib/ScalaJSBridge.scala b/scalajslib/src/mill/scalajslib/ScalaJSBridge.scala
index 6b471164..8152d3d1 100644
--- a/scalajslib/src/mill/scalajslib/ScalaJSBridge.scala
+++ b/scalajslib/src/mill/scalajslib/ScalaJSBridge.scala
@@ -20,7 +20,10 @@ class ScalaJSWorker {
scalaInstanceCache match {
case Some((sig, bridge)) if sig == classloaderSig => bridge
case _ =>
- val cl = new URLClassLoader(toolsClasspath.map(_.toIO.toURI.toURL).toArray)
+ val cl = new URLClassLoader(
+ toolsClasspath.map(_.toIO.toURI.toURL).toArray,
+ getClass.getClassLoader
+ )
val bridge = cl
.loadClass("mill.scalajslib.bridge.ScalaJSBridge")
.getDeclaredConstructor()
diff --git a/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala b/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala
index 18fbc269..12102666 100644
--- a/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala
+++ b/scalajslib/test/src/mill/scalajslib/HelloJSWorldTests.scala
@@ -17,7 +17,7 @@ import scala.collection.JavaConverters._
object HelloJSWorldTests extends TestSuite {
- val workspacePath = TestEvaluator.getOutPathStatic()
+ val workspacePath = TestUtil.getOutPathStatic() / "hello-js-world"
trait HelloJSWorldModule extends ScalaJSModule with PublishModule {
override def millSourcePath = workspacePath
@@ -89,10 +89,11 @@ object HelloJSWorldTests extends TestSuite {
}
def runJS(path: Path): String = {
- val engineManager = new ScriptEngineManager
+ val engineManager = new ScriptEngineManager(null)
val engine = engineManager.getEngineByName("nashorn")
val console = new Console
- engine.getBindings(ScriptContext.ENGINE_SCOPE).put("console", console)
+ val bindings = engine.getBindings(ScriptContext.ENGINE_SCOPE)
+ bindings.put("console", console)
engine.eval(new FileReader(path.toIO))
console.out.toString
}
diff --git a/scalalib/src/mill/scalalib/ScalaModule.scala b/scalalib/src/mill/scalalib/ScalaModule.scala
index 32d4b259..92068487 100644
--- a/scalalib/src/mill/scalalib/ScalaModule.scala
+++ b/scalalib/src/mill/scalalib/ScalaModule.scala
@@ -193,7 +193,7 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
}
def sourcesJar = T {
- createJar((allSources() ++ resources()).map(_.path).filter(exists))(T.ctx().dest / "sources.jar")
+ createJar((allSources() ++ resources()).map(_.path).filter(exists))
}
def forkArgs = T{ Seq.empty[String] }
@@ -250,6 +250,7 @@ trait ScalaModule extends mill.Module with TaskModule { outer =>
def crossFullScalaVersion: T[Boolean] = false
def artifactName: T[String] = millSourcePath.last.toString
+
def artifactScalaVersion: T[String] = T {
if (crossFullScalaVersion()) scalaVersion()
else Lib.scalaBinaryVersion(scalaVersion())
diff --git a/scalalib/test/resources/gen-idea/idea_modules/iml b/scalalib/test/resources/gen-idea/idea_modules/iml
index 548865f1..c221343e 100644
--- a/scalalib/test/resources/gen-idea/idea_modules/iml
+++ b/scalalib/test/resources/gen-idea/idea_modules/iml
@@ -1,12 +1,12 @@
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager">
- <output url="file://$MODULE_DIR$/../target/workspace/gen-idea/out/compile/dest/classes"/>
+ <output url="file://$MODULE_DIR$/../target/workspace/mill/scalalib/GenIdeaTests/helloWorldEvaluator/compile/dest/classes"/>
<exclude-output/>
- <content url="file://$MODULE_DIR$/../target/workspace/hello-world/src/src">
- <sourceFolder url="file://$MODULE_DIR$/../target/workspace/hello-world/src/src" isTestSource="false"/>
+ <content url="file://$MODULE_DIR$/../target/workspace/gen-idea/src">
+ <sourceFolder url="file://$MODULE_DIR$/../target/workspace/gen-idea/src" isTestSource="false"/>
</content>
- <content url="file://$MODULE_DIR$/../target/workspace/hello-world/src/resources">
- <sourceFolder url="file://$MODULE_DIR$/../target/workspace/hello-world/src/resources" isTestSource="false" type="java-resource"/>
+ <content url="file://$MODULE_DIR$/../target/workspace/gen-idea/resources">
+ <sourceFolder url="file://$MODULE_DIR$/../target/workspace/gen-idea/resources" isTestSource="false" type="java-resource"/>
</content>
<orderEntry type="inheritedJdk"/>
<orderEntry type="sourceFolder" forTests="false"/>
diff --git a/scalalib/test/src/mill/scalalib/GenIdeaTests.scala b/scalalib/test/src/mill/scalalib/GenIdeaTests.scala
index 13c988bc..e5183c49 100644
--- a/scalalib/test/src/mill/scalalib/GenIdeaTests.scala
+++ b/scalalib/test/src/mill/scalalib/GenIdeaTests.scala
@@ -9,12 +9,10 @@ import mill.util.TestEvaluator.implicitDisover
object GenIdeaTests extends TestSuite {
val millSourcePath = pwd / 'target / 'workspace / "gen-idea"
- val outPath = millSourcePath / 'out
- val workingSrcPath = millSourcePath / 'src
trait HelloWorldModule extends scalalib.ScalaModule {
def scalaVersion = "2.12.4"
- def millSourcePath = HelloWorldTests.workingSrcPath
+ def millSourcePath = GenIdeaTests.millSourcePath
}
object HelloWorld extends TestUtil.BaseModule with HelloWorldModule
@@ -23,7 +21,6 @@ object GenIdeaTests extends TestSuite {
def tests: Tests = Tests {
'genIdeaTests - {
- helloWorldEvaluator(HelloWorld.scalaVersion)
val pp = new scala.xml.PrettyPrinter(999, 4)
val layout = GenIdea.xmlFileLayout(helloWorldEvaluator.evaluator, HelloWorld, fetchMillModules = false)
diff --git a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala
index a56bc66e..6afcef5e 100644
--- a/scalalib/test/src/mill/scalalib/HelloWorldTests.scala
+++ b/scalalib/test/src/mill/scalalib/HelloWorldTests.scala
@@ -11,28 +11,33 @@ import mill.scalalib.publish._
import mill.util.{TestEvaluator, TestUtil}
import utest._
import mill.util.TestEvaluator.implicitDisover
+import utest.framework.TestPath
+
import scala.collection.JavaConverters._
object HelloWorldTests extends TestSuite {
- trait HelloWorldModule extends scalalib.ScalaModule {
+ trait HelloWorldModule
+ extends TestUtil.BaseModule with scalalib.ScalaModule {
def scalaVersion = "2.12.4"
- def millSourcePath = HelloWorldTests.workingSrcPath
+ def millSourcePath = TestUtil.getSrcPathBase() / millOuterCtx.enclosing.split('.')
}
- object HelloWorld extends TestUtil.BaseModule with HelloWorldModule
+
+ object HelloWorld extends HelloWorldModule
object CrossHelloWorld extends TestUtil.BaseModule {
object cross extends Cross[HelloWorldCross]("2.10.6", "2.11.11", "2.12.3", "2.12.4")
class HelloWorldCross(v: String) extends HelloWorldModule {
+ def millSourcePath = super.millSourcePath / up
def scalaVersion = v
}
}
- object HelloWorldWithMain extends TestUtil.BaseModule with HelloWorldModule {
+ object HelloWorldWithMain extends HelloWorldModule {
def mainClass = Some("Main")
}
- object HelloWorldWithMainAssembly extends TestUtil.BaseModule with HelloWorldModule {
+ object HelloWorldWithMainAssembly extends HelloWorldModule {
def mainClass = Some("Main")
def assembly = T{
mill.modules.Jvm.createAssembly(
@@ -43,15 +48,15 @@ object HelloWorldTests extends TestSuite {
}
}
- object HelloWorldWarnUnused extends TestUtil.BaseModule with HelloWorldModule {
+ object HelloWorldWarnUnused extends HelloWorldModule {
def scalacOptions = T(Seq("-Ywarn-unused"))
}
- object HelloWorldFatalWarnings extends TestUtil.BaseModule with HelloWorldModule {
+ object HelloWorldFatalWarnings extends HelloWorldModule {
def scalacOptions = T(Seq("-Ywarn-unused", "-Xfatal-warnings"))
}
- object HelloWorldWithPublish extends TestUtil.BaseModule with HelloWorldModule with PublishModule {
+ object HelloWorldWithPublish extends HelloWorldModule with PublishModule {
def artifactName = "hello-world"
def publishVersion = "0.0.1"
@@ -70,39 +75,52 @@ object HelloWorldTests extends TestSuite {
Seq(Developer("lihaoyi", "Li Haoyi", "https://github.com/lihaoyi"))
)
}
- object HelloWorldScalaOverride extends TestUtil.BaseModule with HelloWorldModule {
+ object HelloWorldScalaOverride extends HelloWorldModule {
override def scalaVersion: Target[String] = "2.11.11"
}
val resourcePath = pwd / 'scalalib / 'test / 'resources / "hello-world"
- val millSourcePath = pwd / 'target / 'workspace / "hello-world"
- val workingSrcPath = millSourcePath / 'src
- val outPath = millSourcePath / 'out
- val mainObject = workingSrcPath / 'src / "Main.scala"
+ def jarMainClass(jar: JarFile): Option[String] = {
+ import java.util.jar.Attributes._
+ val attrs = jar.getManifest.getMainAttributes.asScala
+ attrs.get(Name.MAIN_CLASS).map(_.asInstanceOf[String])
+ }
+ def compileClassfiles = Seq[RelPath](
+ "Main.class",
+ "Main$.class",
+ "Main$delayedInit$body.class",
+ "Person.class",
+ "Person$.class"
+ )
+ def workspaceTest[T, M <: TestUtil.TestBuild: Discover](m: M)
+ (t: TestEvaluator[M] => T)
+ (implicit tp: TestPath): T = {
+ val eval = new TestEvaluator(m)
+ rm(m.millSourcePath)
+ rm(eval.outPath)
+ mkdir(m.millSourcePath / up)
+ cp(resourcePath, m.millSourcePath)
+ t(eval)
+ }
+
- val helloWorldEvaluator = TestEvaluator.static(HelloWorld)
- val helloWorldWithMainEvaluator = TestEvaluator.static(HelloWorldWithMain)
- val helloWorldWithMainAssemblyEvaluator = TestEvaluator.static(HelloWorldWithMainAssembly)
- val helloWorldFatalEvaluator = TestEvaluator.static(HelloWorldFatalWarnings)
- val helloWorldOverrideEvaluator = TestEvaluator.static(HelloWorldScalaOverride)
- val helloWorldCrossEvaluator = TestEvaluator.static(CrossHelloWorld)
def tests: Tests = Tests {
- prepareWorkspace()
'scalaVersion - {
- 'fromBuild - {
- val Right((result, evalCount)) = helloWorldEvaluator(HelloWorld.scalaVersion)
+
+ 'fromBuild - workspaceTest(HelloWorld){eval =>
+ val Right((result, evalCount)) = eval.apply(HelloWorld.scalaVersion)
assert(
result == "2.12.4",
evalCount > 0
)
}
- 'override - {
- val Right((result, evalCount)) = helloWorldOverrideEvaluator(HelloWorldScalaOverride.scalaVersion)
+ 'override - workspaceTest(HelloWorldScalaOverride){eval =>
+ val Right((result, evalCount)) = eval.apply(HelloWorldScalaOverride.scalaVersion)
assert(
result == "2.11.11",
@@ -111,16 +129,16 @@ object HelloWorldTests extends TestSuite {
}
}
'scalacOptions - {
- 'emptyByDefault - {
- val Right((result, evalCount)) = helloWorldEvaluator(HelloWorld.scalacOptions)
+ 'emptyByDefault - workspaceTest(HelloWorld){eval =>
+ val Right((result, evalCount)) = eval.apply(HelloWorld.scalacOptions)
assert(
result.isEmpty,
evalCount > 0
)
}
- 'override - {
- val Right((result, evalCount)) = helloWorldFatalEvaluator(HelloWorldFatalWarnings.scalacOptions)
+ 'override - workspaceTest(HelloWorldFatalWarnings){ eval =>
+ val Right((result, evalCount)) = eval.apply(HelloWorldFatalWarnings.scalacOptions)
assert(
result == Seq("-Ywarn-unused", "-Xfatal-warnings"),
@@ -129,14 +147,14 @@ object HelloWorldTests extends TestSuite {
}
}
'compile - {
- 'fromScratch - {
- val Right((result, evalCount)) = helloWorldEvaluator(HelloWorld.compile)
+ 'fromScratch - workspaceTest(HelloWorld){eval =>
+ val Right((result, evalCount)) = eval.apply(HelloWorld.compile)
val analysisFile = result.analysisFile
val outputFiles = ls.rec(result.classes.path)
- val expectedClassfiles = compileClassfiles.map(outPath / 'compile / 'dest / 'classes / _)
+ val expectedClassfiles = compileClassfiles.map(eval.outPath / 'compile / 'dest / 'classes / _)
assert(
- result.classes.path == outPath / 'compile / 'dest / 'classes,
+ result.classes.path == eval.outPath / 'compile / 'dest / 'classes,
exists(analysisFile),
outputFiles.nonEmpty,
outputFiles.forall(expectedClassfiles.contains),
@@ -144,28 +162,28 @@ object HelloWorldTests extends TestSuite {
)
// don't recompile if nothing changed
- val Right((_, unchangedEvalCount)) = helloWorldEvaluator(HelloWorld.compile)
+ val Right((_, unchangedEvalCount)) = eval.apply(HelloWorld.compile)
assert(unchangedEvalCount == 0)
}
- 'recompileOnChange - {
- val Right((_, freshCount)) = helloWorldEvaluator(HelloWorld.compile)
+ 'recompileOnChange - workspaceTest(HelloWorld){eval =>
+ val Right((_, freshCount)) = eval.apply(HelloWorld.compile)
assert(freshCount > 0)
- write.append(mainObject, "\n")
+ write.append(HelloWorld.millSourcePath / 'src / "Main.scala", "\n")
- val Right((_, incCompileCount)) = helloWorldEvaluator(HelloWorld.compile)
+ val Right((_, incCompileCount)) = eval.apply(HelloWorld.compile)
assert(incCompileCount > 0, incCompileCount < freshCount)
}
- 'failOnError - {
- write.append(mainObject, "val x: ")
+ 'failOnError - workspaceTest(HelloWorld){eval =>
+ write.append(HelloWorld.millSourcePath / 'src / "Main.scala", "val x: ")
- val Left(Result.Exception(err, _)) = helloWorldEvaluator(HelloWorld.compile)
+ val Left(Result.Exception(err, _)) = eval.apply(HelloWorld.compile)
// assert(err.isInstanceOf[CompileFailed])
val paths = Evaluator.resolveDestPaths(
- outPath,
+ eval.outPath,
HelloWorld.compile.ctx.segments
)
@@ -174,22 +192,25 @@ object HelloWorldTests extends TestSuite {
!exists(paths.meta)
)
// Works when fixed
- write.over(mainObject, read(mainObject).dropRight("val x: ".length))
+ write.over(
+ HelloWorld.millSourcePath / 'src / "Main.scala",
+ read(HelloWorld.millSourcePath / 'src / "Main.scala").dropRight("val x: ".length)
+ )
- val Right((result, evalCount)) = helloWorldEvaluator(HelloWorld.compile)
+ val Right((result, evalCount)) = eval.apply(HelloWorld.compile)
}
- 'passScalacOptions - {
+ 'passScalacOptions - workspaceTest(HelloWorldFatalWarnings){ eval =>
// compilation fails because of "-Xfatal-warnings" flag
- val Left(Result.Exception(err, _)) = helloWorldFatalEvaluator(HelloWorldFatalWarnings.compile)
+ val Left(Result.Exception(err, _)) = eval.apply(HelloWorldFatalWarnings.compile)
// assert(err.isInstanceOf[CompileFailed])
}
}
'runMain - {
- 'runMainObject - {
- val runResult = millSourcePath / 'out / 'runMain / 'dest / "hello-mill"
+ 'runMainObject - workspaceTest(HelloWorld){eval =>
+ val runResult = eval.outPath/ 'runMain / 'dest / "hello-mill"
- val Right((_, evalCount)) = helloWorldEvaluator(HelloWorld.runMain("Main", runResult.toString))
+ val Right((_, evalCount)) = eval.apply(HelloWorld.runMain("Main", runResult.toString))
assert(evalCount > 0)
assert(
@@ -197,12 +218,12 @@ object HelloWorldTests extends TestSuite {
read(runResult) == "hello rockjam, your age is: 25"
)
}
- 'runCross{
- def cross(v: String) {
+ 'runCross - {
+ def cross(eval: TestEvaluator[_], v: String) {
- val runResult = millSourcePath / 'out / 'cross / v / 'runMain / 'dest / "hello-mill"
+ val runResult = eval.outPath / 'cross / v / 'runMain / 'dest / "hello-mill"
- val Right((_, evalCount)) = helloWorldCrossEvaluator(
+ val Right((_, evalCount)) = eval.apply(
CrossHelloWorld.cross(v).runMain("Main", runResult.toString)
)
@@ -214,24 +235,24 @@ object HelloWorldTests extends TestSuite {
read(runResult) == "hello rockjam, your age is: 25"
)
}
- 'v210 - cross("2.10.6")
- 'v211 - cross("2.11.11")
- 'v2123 - cross("2.12.3")
- 'v2124 - cross("2.12.4")
+ 'v210 - workspaceTest(CrossHelloWorld)(cross(_, "2.10.6"))
+ 'v211 - workspaceTest(CrossHelloWorld)(cross(_, "2.11.11"))
+ 'v2123 - workspaceTest(CrossHelloWorld)(cross(_, "2.12.3"))
+ 'v2124 - workspaceTest(CrossHelloWorld)(cross(_, "2.12.4"))
}
- 'notRunInvalidMainObject - {
- val Left(Result.Exception(err, _)) = helloWorldEvaluator(HelloWorld.runMain("Invalid"))
+ 'notRunInvalidMainObject - workspaceTest(HelloWorld){eval =>
+ val Left(Result.Exception(err, _)) = eval.apply(HelloWorld.runMain("Invalid"))
assert(
err.isInstanceOf[InteractiveShelloutException]
)
}
- 'notRunWhenComplileFailed - {
- write.append(mainObject, "val x: ")
+ 'notRunWhenComplileFailed - workspaceTest(HelloWorld){eval =>
+ write.append(HelloWorld.millSourcePath / 'src / "Main.scala", "val x: ")
- val Left(Result.Exception(err, _)) = helloWorldEvaluator(HelloWorld.runMain("Main"))
+ val Left(Result.Exception(err, _)) = eval.apply(HelloWorld.runMain("Main"))
// assert(
// err.isInstanceOf[CompileFailed]
@@ -240,9 +261,9 @@ object HelloWorldTests extends TestSuite {
}
'forkRun - {
- 'runIfMainClassProvided - {
- val runResult = millSourcePath / 'out / 'run / 'dest / "hello-mill"
- val Right((_, evalCount)) = helloWorldWithMainEvaluator(
+ 'runIfMainClassProvided - workspaceTest(HelloWorldWithMain){eval =>
+ val runResult = eval.outPath / 'run / 'dest / "hello-mill"
+ val Right((_, evalCount)) = eval.apply(
HelloWorldWithMain.run(runResult.toString)
)
@@ -254,8 +275,8 @@ object HelloWorldTests extends TestSuite {
read(runResult) == "hello rockjam, your age is: 25"
)
}
- 'notRunWithoutMainClass - {
- val Left(Result.Exception(err, _)) = helloWorldEvaluator(HelloWorld.run())
+ 'notRunWithoutMainClass - workspaceTest(HelloWorld){eval =>
+ val Left(Result.Exception(err, _)) = eval.apply(HelloWorld.run())
assert(
err.isInstanceOf[RuntimeException]
@@ -263,9 +284,9 @@ object HelloWorldTests extends TestSuite {
}
}
'run - {
- 'runIfMainClassProvided - {
- val runResult = millSourcePath / 'out / 'run / 'dest / "hello-mill"
- val Right((_, evalCount)) = helloWorldWithMainEvaluator(
+ 'runIfMainClassProvided - workspaceTest(HelloWorldWithMain){eval =>
+ val runResult = eval.outPath / 'run / 'dest / "hello-mill"
+ val Right((_, evalCount)) = eval.apply(
HelloWorldWithMain.runLocal(runResult.toString)
)
@@ -277,8 +298,8 @@ object HelloWorldTests extends TestSuite {
read(runResult) == "hello rockjam, your age is: 25"
)
}
- 'notRunWithoutMainClass - {
- val Left(Result.Exception(err, _)) = helloWorldEvaluator(HelloWorld.runLocal())
+ 'notRunWithoutMainClass - workspaceTest(HelloWorld){eval =>
+ val Left(Result.Exception(err, _)) = eval.apply(HelloWorld.runLocal())
assert(
err.isInstanceOf[RuntimeException]
@@ -286,8 +307,8 @@ object HelloWorldTests extends TestSuite {
}
}
'jar - {
- 'nonEmpty - {
- val Right((result, evalCount)) = helloWorldWithMainEvaluator(HelloWorldWithMain.jar)
+ 'nonEmpty - workspaceTest(HelloWorldWithMain){eval =>
+ val Right((result, evalCount)) = eval.apply(HelloWorldWithMain.jar)
assert(
exists(result.path),
@@ -310,16 +331,18 @@ object HelloWorldTests extends TestSuite {
val mainClass = jarMainClass(jarFile)
assert(mainClass.contains("Main"))
}
- 'logOutputToFile {
- helloWorldEvaluator(HelloWorld.compile)
+ 'logOutputToFile - workspaceTest(HelloWorld){eval =>
+ val outPath = eval.outPath
+ eval.apply(HelloWorld.compile)
val logFile = outPath / 'compile / 'log
assert(exists(logFile))
}
}
+
'assembly - {
- 'assembly - {
- val Right((result, evalCount)) = helloWorldWithMainAssemblyEvaluator(HelloWorldWithMainAssembly.assembly)
+ 'assembly - workspaceTest(HelloWorldWithMainAssembly){ eval =>
+ val Right((result, evalCount)) = eval.apply(HelloWorldWithMainAssembly.assembly)
assert(
exists(result.path),
evalCount > 0
@@ -333,16 +356,16 @@ object HelloWorldTests extends TestSuite {
val mainClass = jarMainClass(jarFile)
assert(mainClass.contains("Main"))
}
- 'run - {
- val Right((result, evalCount)) = helloWorldWithMainAssemblyEvaluator(HelloWorldWithMainAssembly.assembly)
+ 'run - workspaceTest(HelloWorldWithMainAssembly){eval =>
+ val Right((result, evalCount)) = eval.apply(HelloWorldWithMainAssembly.assembly)
assert(
exists(result.path),
evalCount > 0
)
- val runResult = millSourcePath / "hello-mill"
+ val runResult = eval.outPath / "hello-mill"
- %%("java", "-jar", result.path, runResult)(wd = millSourcePath)
+ %%("java", "-jar", result.path, runResult)(wd = eval.outPath)
assert(
exists(runResult),
@@ -352,25 +375,5 @@ object HelloWorldTests extends TestSuite {
}
}
- def jarMainClass(jar: JarFile): Option[String] = {
- import java.util.jar.Attributes._
- val attrs = jar.getManifest.getMainAttributes.asScala
- attrs.get(Name.MAIN_CLASS).map(_.asInstanceOf[String])
- }
-
- def compileClassfiles = Seq[RelPath](
- "Main.class",
- "Main$.class",
- "Main$delayedInit$body.class",
- "Person.class",
- "Person$.class"
- )
-
- def prepareWorkspace(): Unit = {
- rm(outPath)
- rm(workingSrcPath)
- mkdir(outPath)
- cp(resourcePath, workingSrcPath)
- }
}