Skip to content

Commit 1a5c065

Browse files
committed
Run some extra tests for Java 8, 11, 17, 21 & 23
1 parent 1a51bf2 commit 1a5c065

File tree

4 files changed

+107
-1
lines changed

4 files changed

+107
-1
lines changed

build.sc

+4
Original file line numberDiff line numberDiff line change
@@ -1030,7 +1030,11 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests
10301030
|
10311031
|/** Build-time constants. Generated by mill. */
10321032
|object Constants {
1033+
| def allJavaVersions = Seq(${Java.allJavaVersions.sorted.mkString(", ")})
10331034
| def bspVersion = "${Deps.bsp4j.dep.version}"
1035+
| def bloopMinimumJvmVersion = ${Java.minimumBloopJava}
1036+
| def minimumInternalJvmVersion = ${Java.minimumInternalJava}
1037+
| def defaultJvmVersion = ${Java.defaultJava}
10341038
| def scala212 = "${Scala.scala212}"
10351039
| def scala213 = "${Scala.scala213}"
10361040
| def scalaSnapshot213 = "${TestDeps.scalaSnapshot213}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
package scala.cli.integration
2+
3+
import com.eed3si9n.expecty.Expecty.expect
4+
5+
import scala.util.Properties
6+
7+
trait RunJdkTestDefinitions { _: RunTestDefinitions =>
8+
def javaIndex(javaVersion: Int): String =
9+
// TODO just passing the version number on arm64 should be enough, needs a fix in cs
10+
if (Properties.isMac && TestUtil.isM1 && (javaVersion < 11 || javaVersion == 16))
11+
s"zulu:$javaVersion"
12+
else javaVersion.toString
13+
14+
for {
15+
javaVersion <- Constants.allJavaVersions
16+
index = javaIndex(javaVersion)
17+
} {
18+
test(s"correct JVM is picked up when JAVA_HOME set to $index") {
19+
TestUtil.retryOnCi() {
20+
TestInputs(
21+
os.rel / "check_java_home.sc" ->
22+
s"""assert(
23+
| System.getProperty("java.version").startsWith("$javaVersion") ||
24+
| System.getProperty("java.version").startsWith("1.$javaVersion")
25+
|)
26+
|println(System.getProperty("java.home"))""".stripMargin
27+
).fromRoot { root =>
28+
val javaHome =
29+
os.Path(
30+
os.proc(TestUtil.cs, "java-home", "--jvm", index).call().out.trim(),
31+
os.pwd
32+
)
33+
val res = os.proc(TestUtil.cli, "run", ".", extraOptions)
34+
.call(cwd = root, env = Map("JAVA_HOME" -> javaHome.toString))
35+
expect(res.out.trim().contains(javaHome.toString))
36+
}
37+
}
38+
}
39+
40+
test(s"hello world with --jvm $index") {
41+
val expectedMessage = "Hello, world!"
42+
TestInputs(
43+
os.rel / "hello_world.sc" -> s"println(\"$expectedMessage\")"
44+
).fromRoot { root =>
45+
val res = os.proc(TestUtil.cli, "run", ".", extraOptions, "--jvm", javaVersion)
46+
.call(cwd = root)
47+
expect(res.out.trim() == expectedMessage)
48+
}
49+
}
50+
51+
test(s"correct JVM is picked up when Java $index is passed with --java-home") {
52+
TestUtil.retryOnCi() {
53+
TestInputs(
54+
os.rel / "check_java_home.sc" ->
55+
s"""assert(
56+
| System.getProperty("java.version").startsWith("$javaVersion") ||
57+
| System.getProperty("java.version").startsWith("1.$javaVersion")
58+
|)
59+
|println(System.getProperty("java.home"))""".stripMargin
60+
).fromRoot { root =>
61+
val javaHome =
62+
os.Path(
63+
os.proc(TestUtil.cs, "java-home", "--jvm", index).call().out.trim(),
64+
os.pwd
65+
)
66+
val res =
67+
os.proc(TestUtil.cli, "run", ".", extraOptions, "--java-home", javaHome.toString)
68+
.call(cwd = root)
69+
expect(res.out.trim().contains(javaHome.toString))
70+
}
71+
}
72+
}
73+
74+
if (javaVersion >= Constants.bloopMinimumJvmVersion)
75+
test(s"Bloop runs correctly on JVM $index") {
76+
TestUtil.retryOnCi() {
77+
val expectedMessage = "Hello, world!"
78+
TestInputs(os.rel / "check_java_home.sc" -> s"""println("$expectedMessage")""")
79+
.fromRoot { root =>
80+
os.proc(TestUtil.cli, "bloop", "exit", "--power").call(cwd = root)
81+
val res = os.proc(
82+
TestUtil.cli,
83+
"run",
84+
".",
85+
extraOptions,
86+
"--bloop-jvm",
87+
index,
88+
"--jvm",
89+
index
90+
)
91+
.call(cwd = root, stderr = os.Pipe)
92+
expect(res.err.trim().contains(javaVersion.toString))
93+
expect(res.out.trim() == expectedMessage)
94+
}
95+
}
96+
}
97+
}
98+
}

modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ abstract class RunTestDefinitions
2121
with RunScalacCompatTestDefinitions
2222
with RunSnippetTestDefinitions
2323
with RunScalaPyTestDefinitions
24-
with RunZipTestDefinitions { _: TestScalaVersion =>
24+
with RunZipTestDefinitions
25+
with RunJdkTestDefinitions { _: TestScalaVersion =>
2526
protected lazy val extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions
2627
protected val emptyInputs: TestInputs = TestInputs(os.rel / ".placeholder" -> "")
2728

project/deps.sc

+3
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ object Java {
8080
def minimumBloopJava = 17
8181
def minimumInternalJava = 16
8282
def defaultJava = minimumBloopJava
83+
def mainJavaVersions = Seq(8, 11, 17, 21, 23)
84+
def allJavaVersions =
85+
(mainJavaVersions ++ Seq(minimumBloopJava, minimumInternalJava, defaultJava)).distinct
8386
}
8487

8588
// Dependencies used in integration test fixtures

0 commit comments

Comments
 (0)