summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--integration/src/test/scala/mill/integration/BetterFilesTests.scala2
-rw-r--r--scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala66
-rwxr-xr-xtest.sh6
3 files changed, 59 insertions, 15 deletions
diff --git a/integration/src/test/scala/mill/integration/BetterFilesTests.scala b/integration/src/test/scala/mill/integration/BetterFilesTests.scala
index 82b66fba..a6207d87 100644
--- a/integration/src/test/scala/mill/integration/BetterFilesTests.scala
+++ b/integration/src/test/scala/mill/integration/BetterFilesTests.scala
@@ -11,7 +11,7 @@ object BetterFilesTests extends IntegrationTestSuite("MILL_BETTERFILES_REPO", "b
assert(eval("core.test"))
assert(eval("akka.test"))
- val coreTestMeta = meta("Core.test.test")
+ val coreTestMeta = meta("core.test.test")
assert(coreTestMeta.contains("better.files.FileSpec"))
assert(coreTestMeta.contains("files should handle BOM"))
diff --git a/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala b/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala
index 567d5bd8..8cc4632e 100644
--- a/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala
+++ b/scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala
@@ -32,6 +32,17 @@ object HelloWorldWithMain extends TestUtil.BaseModule with HelloWorldModule {
def mainClass = Some("Main")
}
+object HelloWorldWithMainAssembly extends TestUtil.BaseModule with HelloWorldModule {
+ def mainClass = Some("Main")
+ def assembly = T{
+ modules.Jvm.createAssembly(
+ assemblyClasspath().map(_.path).filter(exists),
+ prependShellScript = prependShellScript(),
+ mainClass = mainClass()
+ )
+ }
+}
+
object HelloWorldWarnUnused extends TestUtil.BaseModule with HelloWorldModule {
def scalacOptions = T(Seq("-Ywarn-unused"))
}
@@ -83,6 +94,11 @@ object HelloWorldTests extends TestSuite {
outPath,
workingSrcPath
)
+ val helloWorldWithMainAssemblyEvaluator = new TestEvaluator(
+ Discovered.mapping(HelloWorldWithMainAssembly),
+ outPath,
+ workingSrcPath
+ )
val helloWorldFatalEvaluator = new TestEvaluator(
Discovered.mapping(HelloWorldFatalWarnings),
outPath,
@@ -272,14 +288,15 @@ object HelloWorldTests extends TestSuite {
}
'jar - {
'nonEmpty - {
- val Right((result, evalCount)) = helloWorldEvaluator(HelloWorld.jar)
+ val Right((result, evalCount)) = helloWorldWithMainEvaluator(HelloWorldWithMain.jar)
assert(
exists(result.path),
evalCount > 0
)
- val entries = new JarFile(result.path.toIO).entries().asScala.map(_.getName).toSet
+ val jarFile = new JarFile(result.path.toIO)
+ val entries = jarFile.entries().asScala.map(_.getName).toSet
val manifestFiles = Seq[RelPath](
"META-INF" / "MANIFEST.MF"
@@ -290,33 +307,58 @@ object HelloWorldTests extends TestSuite {
entries.nonEmpty,
entries == expectedFiles.map(_.toString()).toSet
)
+
+ val mainClass = jarMainClass(jarFile)
+ assert(mainClass.contains("Main"))
}
- 'runJar - {
- val Right((result, evalCount)) = helloWorldWithMainEvaluator(HelloWorldWithMain.jar)
+ 'logOutputToFile {
+ helloWorldEvaluator(HelloWorld.compile)
+ val logFile = outPath / 'compile / 'log
+ assert(exists(logFile))
+ }
+ }
+ 'assembly - {
+ 'assembly - {
+ val Right((result, evalCount)) = helloWorldWithMainAssemblyEvaluator(HelloWorldWithMainAssembly.assembly)
assert(
exists(result.path),
evalCount > 0
)
- val runResult = basePath / "hello-mill"
+ val jarFile = new JarFile(result.path.toIO)
+ val entries = jarFile.entries().asScala.map(_.getName).toSet
- %("scala", result.path, runResult)(wd = basePath)
+ assert(entries.contains("Main.class"))
+ assert(entries.exists(s => s.contains("scala/Predef.class")))
+ val mainClass = jarMainClass(jarFile)
+ assert(mainClass.contains("Main"))
+ }
+ 'run - {
+ val Right((result, evalCount)) = helloWorldWithMainAssemblyEvaluator(HelloWorldWithMainAssembly.assembly)
+
+ assert(
+ exists(result.path),
+ evalCount > 0
+ )
+ val runResult = basePath / "hello-mill"
+
+ %%("java", "-jar", result.path, runResult)(wd = basePath)
assert(
exists(runResult),
read(runResult) == "hello rockjam, your age is: 25"
)
}
- 'logOutputToFile {
- helloWorldEvaluator(HelloWorld.compile)
-
- val logFile = outPath / 'compile / 'log
- assert(exists(logFile))
- }
}
}
+ 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",
diff --git a/test.sh b/test.sh
index c49bf082..916a5d78 100755
--- a/test.sh
+++ b/test.sh
@@ -6,7 +6,9 @@ set -eux
git clean -xdf
# First build & run tests using SBT
-sbt core/test scalalib/test scalajslib/test integration/test bin/test:assembly
+sbt core/test scalalib/test scalajslib/test
+sbt integration/test
+sbt bin/test:assembly
# Build Mill using SBT
bin/target/mill devAssembly
@@ -16,4 +18,4 @@ out/devAssembly/dest core.test
out/devAssembly/dest scalalib.test
out/devAssembly/dest scalajslib.test
out/devAssembly/dest integration.test
-out/devAssembly/dest devAssembly \ No newline at end of file
+out/devAssembly/dest devAssembly