summaryrefslogtreecommitdiff
path: root/scalalib/src
diff options
context:
space:
mode:
authorVadim Chelyshov <qtankle@gmail.com>2018-01-09 05:45:57 +0300
committerLi Haoyi <haoyi.sg@gmail.com>2018-01-08 18:45:57 -0800
commit4724f8c1477450fb584dda77bb3c2400a0c65868 (patch)
tree7e59105e4e6b51d63e1cc68da5d5382d1db656b4 /scalalib/src
parentb4cabadf8071d12749805cd7ea160b54b26e1b30 (diff)
downloadmill-4724f8c1477450fb584dda77bb3c2400a0c65868.tar.gz
mill-4724f8c1477450fb584dda77bb3c2400a0c65868.tar.bz2
mill-4724f8c1477450fb584dda77bb3c2400a0c65868.zip
prepare ci builds - fix tests (#107)
Diffstat (limited to 'scalalib/src')
-rw-r--r--scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala66
1 files changed, 54 insertions, 12 deletions
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",