diff options
Diffstat (limited to 'scalalib')
-rw-r--r-- | scalalib/src/test/scala/mill/scalalib/HelloWorldTests.scala | 66 |
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", |