diff options
-rw-r--r-- | core/test/resources/examples/javac/build.sc | 23 | ||||
-rw-r--r-- | core/test/src/mill/main/JavaCompileJarTests.scala | 66 | ||||
-rw-r--r-- | core/test/src/mill/util/ScriptTestSuite.scala | 38 | ||||
-rw-r--r-- | integration/test/src/mill/integration/IntegrationTestSuite.scala | 35 |
4 files changed, 138 insertions, 24 deletions
diff --git a/core/test/resources/examples/javac/build.sc b/core/test/resources/examples/javac/build.sc new file mode 100644 index 00000000..4a0882c6 --- /dev/null +++ b/core/test/resources/examples/javac/build.sc @@ -0,0 +1,23 @@ +import ammonite.ops._ +import mill.T +import mill.eval.JavaCompileJarTests.compileAll +import mill.eval.PathRef +import mill.modules.Jvm +import mill.util.Loose + +def sourceRootPath = basePath / 'src +def resourceRootPath = basePath / 'resources + +// sourceRoot -> allSources -> classFiles +// | +// v +// resourceRoot ----> jar +def sourceRoot = T.source{ sourceRootPath } +def resourceRoot = T.source{ resourceRootPath } +def allSources = T{ ls.rec(sourceRoot().path).map(PathRef(_)) } +def classFiles = T{ compileAll(allSources()) } +def jar = T{ Jvm.createJar(Loose.Agg(resourceRoot().path, classFiles().path)) } + +def run(mainClsName: String) = T.command{ + %%('java, "-cp", classFiles().path, mainClsName)(T.ctx().dest) +} diff --git a/core/test/src/mill/main/JavaCompileJarTests.scala b/core/test/src/mill/main/JavaCompileJarTests.scala new file mode 100644 index 00000000..a4c9fafe --- /dev/null +++ b/core/test/src/mill/main/JavaCompileJarTests.scala @@ -0,0 +1,66 @@ +package mill.main + +import ammonite.ops._ +import mill.util.ScriptTestSuite +import utest._ + +object JavaCompileJarTests extends ScriptTestSuite { + def workspaceSlug = "java-compile-jar" + def scriptSourcePath = pwd / 'core / 'test / 'resources / 'examples / 'javac + val tests = Tests{ + initWorkspace() + 'test - { + // Basic target evaluation works + assert(eval("classFiles")) + assert(eval("jar")) + + val classFiles1 = meta("classFiles") + val jar1 = meta("jar") + + assert(eval("classFiles")) + assert(eval("jar")) + + // Repeated evaluation has the same results + val classFiles2 = meta("classFiles") + val jar2 = meta("jar") + + assert( + jar1 == jar2, + classFiles1 == classFiles2 + ) + + // If we update resources, classFiles are unchanged but jar changes + for(scalaFile <- ls.rec(workspacePath).filter(_.ext == "txt")){ + write.append(scalaFile, "\n") + } + + assert(eval("classFiles")) + assert(eval("jar")) + + val classFiles3 = meta("classFiles") + val jar3 = meta("jar") + + assert( + jar2 != jar3, + classFiles2 == classFiles3 + ) + + // We can intentionally break the code, have the targets break, then + // fix the code and have them recover. + for(scalaFile <- ls.rec(workspacePath).filter(_.ext == "java")){ + write.append(scalaFile, "\n}") + } + + assert(!eval("classFiles")) + assert(!eval("jar")) + + for(scalaFile <- ls.rec(workspacePath).filter(_.ext == "java")){ + write.over(scalaFile, read(scalaFile).dropRight(2)) + } + + assert(eval("classFiles")) + assert(eval("jar")) + } + } +} + diff --git a/core/test/src/mill/util/ScriptTestSuite.scala b/core/test/src/mill/util/ScriptTestSuite.scala new file mode 100644 index 00000000..7a963ef9 --- /dev/null +++ b/core/test/src/mill/util/ScriptTestSuite.scala @@ -0,0 +1,38 @@ +package mill.util + +import java.io.{ByteArrayInputStream, ByteArrayOutputStream, PrintStream} + +import ammonite.ops._ +import mill.main.ParseArgs +import utest._ + +abstract class ScriptTestSuite extends TestSuite{ + def workspaceSlug: String + def scriptSourcePath: Path + + val workspacePath = pwd / 'target / 'workspace / workspaceSlug + 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), false, + stdOutErr, stdOutErr, stdIn + ) + def eval(s: String*) = runner.runScript(workspacePath / "build.sc", s.toList) + def meta(s: String) = { + val (List(selector), args) = ParseArgs.apply(Seq(s)).right.get + + read(workspacePath / "out" / selector.flatMap(_.pathSegments) / "meta.json") + } + + + def initWorkspace() = { + rm(workspacePath) + mkdir(workspacePath / up) + // The unzipped git repo snapshots we get from github come with a + // wrapper-folder inside the zip file, so copy the wrapper folder to the + // destination instead of the folder containing the wrapper. + + cp(scriptSourcePath, workspacePath) + } +} diff --git a/integration/test/src/mill/integration/IntegrationTestSuite.scala b/integration/test/src/mill/integration/IntegrationTestSuite.scala index 043e4afa..4edecbe5 100644 --- a/integration/test/src/mill/integration/IntegrationTestSuite.scala +++ b/integration/test/src/mill/integration/IntegrationTestSuite.scala @@ -1,38 +1,25 @@ package mill.integration -import java.io.{ByteArrayInputStream, ByteArrayOutputStream, InputStream, PrintStream} - import ammonite.ops._ -import mill.define.Segments -import mill.main.ParseArgs +import mill.util.ScriptTestSuite import utest._ -abstract class IntegrationTestSuite(repoKey: String, workspaceSlug: String) extends TestSuite{ - val workspacePath = pwd / 'target / 'workspace / workspaceSlug +abstract class IntegrationTestSuite(repoKey: String, val workspaceSlug: String) + extends ScriptTestSuite{ val buildFilePath = pwd / 'integration / 'test / 'resources / workspaceSlug - 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), false, - stdOutErr, stdOutErr, stdIn - ) - def eval(s: String*) = runner.runScript(workspacePath / "build.sc", s.toList) - def meta(s: String) = { - val (List(selector), args) = ParseArgs.apply(Seq(s)).right.get - - read(workspacePath / "out" / selector.flatMap(_.pathSegments) / "meta.json") - } - def initWorkspace() = { - rm(workspacePath) - mkdir(workspacePath / up) + def scriptSourcePath = { // The unzipped git repo snapshots we get from github come with a // wrapper-folder inside the zip file, so copy the wrapper folder to the // destination instead of the folder containing the wrapper. + val path = sys.props(repoKey) val Seq(wrapper) = ls(Path(path)) - cp(wrapper, workspacePath) - cp(buildFilePath / "build.sc", workspacePath / "build.sc") + wrapper + } + + override def initWorkspace() = { + super.initWorkspace() + cp.over(buildFilePath / "build.sc", workspacePath / "build.sc") assert(!ls.rec(workspacePath).exists(_.ext == "class")) } } |