Skip to content

Commit

Permalink
Run some extra tests for Java 8, 11, 17, 21 & 23
Browse files Browse the repository at this point in the history
  • Loading branch information
Gedochao committed Dec 18, 2024
1 parent c33a316 commit c1bd77a
Show file tree
Hide file tree
Showing 4 changed files with 107 additions and 1 deletion.
4 changes: 4 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -1030,7 +1030,11 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
|
|/** Build-time constants. Generated by mill. */
|object Constants {
| def allJavaVersions = Seq(${Java.allJavaVersions.sorted.mkString(", ")})
| def bspVersion = "${Deps.bsp4j.dep.version}"
| def bloopMinimumJvmVersion = ${Java.minimumBloopJava}
| def minimumInternalJvmVersion = ${Java.minimumInternalJava}
| def defaultJvmVersion = ${Java.defaultJava}
| def scala212 = "${Scala.scala212}"
| def scala213 = "${Scala.scala213}"
| def scalaSnapshot213 = "${TestDeps.scalaSnapshot213}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package scala.cli.integration

import com.eed3si9n.expecty.Expecty.expect

import scala.util.Properties

trait RunJdkTestDefinitions { _: RunTestDefinitions =>
def javaIndex(javaVersion: Int): String =
// TODO just passing the version number on arm64 should be enough, needs a fix in cs
if (Properties.isMac && TestUtil.isM1 && (javaVersion < 11 || javaVersion == 16))
s"zulu:$javaVersion"
else javaVersion.toString

for {
javaVersion <- Constants.allJavaVersions
index = javaIndex(javaVersion)
} {
test(s"correct JVM is picked up when JAVA_HOME set to $index") {
TestUtil.retryOnCi() {
TestInputs(
os.rel / "check_java_home.sc" ->
s"""assert(
| System.getProperty("java.version").startsWith("$javaVersion") ||
| System.getProperty("java.version").startsWith("1.$javaVersion")
|)
|println(System.getProperty("java.home"))""".stripMargin
).fromRoot { root =>
val javaHome =
os.Path(
os.proc(TestUtil.cs, "java-home", "--jvm", index).call().out.trim(),
os.pwd
)
val res = os.proc(TestUtil.cli, "run", ".", extraOptions)
.call(cwd = root, env = Map("JAVA_HOME" -> javaHome.toString))
expect(res.out.trim().contains(javaHome.toString))
}
}
}

test(s"hello world with --jvm $index") {
val expectedMessage = "Hello, world!"
TestInputs(
os.rel / "hello_world.sc" -> s"println(\"$expectedMessage\")"
).fromRoot { root =>
val res = os.proc(TestUtil.cli, "run", ".", extraOptions, "--jvm", javaVersion)
.call(cwd = root)
expect(res.out.trim() == expectedMessage)
}
}

test(s"correct JVM is picked up when Java $index is passed with --java-home") {
TestUtil.retryOnCi() {
TestInputs(
os.rel / "check_java_home.sc" ->
s"""assert(
| System.getProperty("java.version").startsWith("$javaVersion") ||
| System.getProperty("java.version").startsWith("1.$javaVersion")
|)
|println(System.getProperty("java.home"))""".stripMargin
).fromRoot { root =>
val javaHome =
os.Path(
os.proc(TestUtil.cs, "java-home", "--jvm", index).call().out.trim(),
os.pwd
)
val res =
os.proc(TestUtil.cli, "run", ".", extraOptions, "--java-home", javaHome.toString)
.call(cwd = root)
expect(res.out.trim().contains(javaHome.toString))
}
}
}

if (javaVersion >= Constants.bloopMinimumJvmVersion)
test(s"Bloop runs correctly on JVM $index") {
TestUtil.retryOnCi() {
val expectedMessage = "Hello, world!"
TestInputs(os.rel / "check_java_home.sc" -> s"""println("$expectedMessage")""")
.fromRoot { root =>
os.proc(TestUtil.cli, "bloop", "exit", "--power").call(cwd = root)
val res = os.proc(
TestUtil.cli,
"run",
".",
extraOptions,
"--bloop-jvm",
index,
"--jvm",
index
)
.call(cwd = root, stderr = os.Pipe)
expect(res.err.trim().contains(javaVersion.toString))
expect(res.out.trim() == expectedMessage)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ abstract class RunTestDefinitions
with RunScalacCompatTestDefinitions
with RunSnippetTestDefinitions
with RunScalaPyTestDefinitions
with RunZipTestDefinitions { _: TestScalaVersion =>
with RunZipTestDefinitions
with RunJdkTestDefinitions { _: TestScalaVersion =>
protected lazy val extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions
protected val emptyInputs: TestInputs = TestInputs(os.rel / ".placeholder" -> "")

Expand Down
3 changes: 3 additions & 0 deletions project/deps.sc
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ object Java {
def minimumBloopJava = 17
def minimumInternalJava = 16
def defaultJava = minimumBloopJava
def mainJavaVersions = Seq(8, 11, 17, 21, 23)
def allJavaVersions =
(mainJavaVersions ++ Seq(minimumBloopJava, minimumInternalJava, defaultJava)).distinct
}

// Dependencies used in integration test fixtures
Expand Down

0 comments on commit c1bd77a

Please sign in to comment.