Skip to content

Commit 55ccea7

Browse files
authored
Merge pull request #3375 from Gedochao/maintenance/test-java-23
Run extra tests for main supported JVM versions
2 parents 511f6fc + 2c203af commit 55ccea7

File tree

7 files changed

+171
-25
lines changed

7 files changed

+171
-25
lines changed

build.sc

+5
Original file line numberDiff line numberDiff line change
@@ -1030,12 +1030,17 @@ 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}"
10371041
| def scala3LtsPrefix = "${Scala.scala3LtsPrefix}"
10381042
| def scala3Lts = "${Scala.scala3Lts}"
1043+
| def scala3NextPrefix = "${Scala.scala3NextPrefix}"
10391044
| def scala3NextRc = "${Scala.scala3NextRc}"
10401045
| def scala3NextRcAnnounced = "${Scala.scala3NextRcAnnounced}"
10411046
| def scala3Next = "${Scala.scala3Next}"

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

+4-4
Original file line numberDiff line numberDiff line change
@@ -1908,19 +1908,19 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
19081908

19091909
test("BSP respects JAVA_HOME") {
19101910
TestUtil.retryOnCi() {
1911-
val javaVersion = "22"
1911+
val javaVersion = "23"
19121912
val inputs = TestInputs(os.rel / "check-java.sc" ->
19131913
s"""assert(System.getProperty("java.version").startsWith("$javaVersion"))
19141914
|println(System.getProperty("java.home"))""".stripMargin)
19151915
inputs.fromRoot { root =>
19161916
os.proc(TestUtil.cli, "bloop", "exit", "--power").call(cwd = root)
1917-
val java22Home =
1917+
val java23Home =
19181918
os.Path(
19191919
os.proc(TestUtil.cs, "java-home", "--jvm", s"zulu:$javaVersion").call().out.trim(),
19201920
os.pwd
19211921
)
19221922
os.proc(TestUtil.cli, "setup-ide", "check-java.sc")
1923-
.call(cwd = root, env = Map("JAVA_HOME" -> java22Home.toString()))
1923+
.call(cwd = root, env = Map("JAVA_HOME" -> java23Home.toString()))
19241924
val ideOptionsPath = root / Constants.workspaceDirName / "ide-options-v2.json"
19251925
expect(ideOptionsPath.toNIO.toFile.exists())
19261926
val ideEnvsPath = root / Constants.workspaceDirName / "ide-envs.json"
@@ -1948,7 +1948,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
19481948

19491949
test("BSP respects --java-home") {
19501950
TestUtil.retryOnCi() {
1951-
val javaVersion = "22"
1951+
val javaVersion = "23"
19521952
val inputs = TestInputs(os.rel / "check-java.sc" ->
19531953
s"""assert(System.getProperty("java.version").startsWith("$javaVersion"))
19541954
|println(System.getProperty("java.home"))""".stripMargin)

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

+21-18
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,16 @@ import scala.util.Properties
1010
trait CoursierScalaInstallationTestHelper {
1111
def withScalaRunnerWrapper(
1212
root: os.Path,
13-
localCache: os.Path,
1413
localBin: os.Path,
15-
scalaVersion: String
14+
scalaVersion: String,
15+
localCache: Option[os.Path] = None,
16+
shouldCleanUp: Boolean = true
1617
)(f: os.Path => Unit): Unit = {
18+
val localCacheArgs = localCache.fold(Seq.empty[String])(c => Seq("--cache", c.toString))
1719
os.proc(
1820
TestUtil.cs,
1921
"install",
20-
"--cache",
21-
localCache,
22+
localCacheArgs,
2223
"--install-dir",
2324
localBin,
2425
s"scala:$scalaVersion"
@@ -74,21 +75,23 @@ trait CoursierScalaInstallationTestHelper {
7475
.call(cwd = root).out.trim()
7576
expect(wrapperVersion == cliVersion)
7677
f(launchScalaPath)
77-
// clean up cs local binaries
78-
val csPrebuiltBinaryDir =
79-
os.Path(underlyingScriptPath.toString().substring(
80-
0,
81-
underlyingScriptPath.toString().indexOf(scalaVersion) + scalaVersion.length
82-
))
83-
System.err.println(s"Cleaning up, trying to remove $csPrebuiltBinaryDir")
84-
try {
85-
os.remove.all(csPrebuiltBinaryDir)
78+
if (shouldCleanUp) {
79+
// clean up cs local binaries
80+
val csPrebuiltBinaryDir =
81+
os.Path(underlyingScriptPath.toString().substring(
82+
0,
83+
underlyingScriptPath.toString().indexOf(scalaVersion) + scalaVersion.length
84+
))
85+
System.err.println(s"Cleaning up, trying to remove $csPrebuiltBinaryDir")
86+
try {
87+
os.remove.all(csPrebuiltBinaryDir)
8688

87-
System.err.println(s"Cleanup complete. Removed $csPrebuiltBinaryDir")
88-
}
89-
catch {
90-
case ex: java.nio.file.FileSystemException =>
91-
System.err.println(s"Failed to remove $csPrebuiltBinaryDir: $ex")
89+
System.err.println(s"Cleanup complete. Removed $csPrebuiltBinaryDir")
90+
}
91+
catch {
92+
case ex: java.nio.file.FileSystemException =>
93+
System.err.println(s"Failed to remove $csPrebuiltBinaryDir: $ex")
94+
}
9295
}
9396
}
9497
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,133 @@
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+
def canUseScalaInstallationWrapper: Boolean =
15+
actualScalaVersion.startsWith("3") && actualScalaVersion.split('.').drop(1).head.toInt >= 5
16+
17+
for {
18+
javaVersion <- Constants.allJavaVersions
19+
index = javaIndex(javaVersion)
20+
useScalaInstallationWrapper <-
21+
if (canUseScalaInstallationWrapper) Seq(false, true) else Seq(false)
22+
launcherString = if (useScalaInstallationWrapper) "coursier scala installation" else "Scala CLI"
23+
scalaRunnerWrapperVersion = actualScalaVersion match {
24+
case v if v == Constants.scala3NextRc => Constants.scala3NextRcAnnounced
25+
case v if v == Constants.scala3Next => Constants.scala3NextAnnounced
26+
case v => v
27+
}
28+
withLauncher = (root: os.Path) =>
29+
(f: Seq[os.Shellable] => Unit) =>
30+
if (useScalaInstallationWrapper)
31+
withScalaRunnerWrapper(
32+
root = root,
33+
localBin = root / "local-bin",
34+
scalaVersion = scalaRunnerWrapperVersion,
35+
shouldCleanUp = false
36+
)(launcher => f(Seq(launcher)))
37+
else
38+
f(Seq(TestUtil.cli))
39+
} {
40+
test(s"correct JVM is picked up by $launcherString when JAVA_HOME set to $index") {
41+
TestUtil.retryOnCi() {
42+
TestInputs(
43+
os.rel / "check_java_home.sc" ->
44+
s"""assert(
45+
| System.getProperty("java.version").startsWith("$javaVersion") ||
46+
| System.getProperty("java.version").startsWith("1.$javaVersion")
47+
|)
48+
|println(System.getProperty("java.home"))""".stripMargin
49+
).fromRoot { root =>
50+
val javaHome =
51+
os.Path(
52+
os.proc(TestUtil.cs, "java-home", "--jvm", index).call().out.trim(),
53+
os.pwd
54+
)
55+
withLauncher(root) { launcher =>
56+
val res = os.proc(launcher, "run", ".", extraOptions)
57+
.call(cwd = root, env = Map("JAVA_HOME" -> javaHome.toString))
58+
expect(res.out.trim().contains(javaHome.toString))
59+
}
60+
}
61+
}
62+
}
63+
64+
test(s"hello world with $launcherString and --jvm $index") {
65+
TestUtil.retryOnCi() {
66+
val expectedMessage = "Hello, world!"
67+
TestInputs(
68+
os.rel / "hello_world.sc" -> s"println(\"$expectedMessage\")"
69+
).fromRoot { root =>
70+
withLauncher(root) { launcher =>
71+
val res = os.proc(launcher, "run", ".", extraOptions, "--jvm", javaVersion)
72+
.call(cwd = root)
73+
expect(res.out.trim() == expectedMessage)
74+
}
75+
}
76+
}
77+
}
78+
79+
if (!Properties.isWin || !useScalaInstallationWrapper) // TODO make this pass on Windows
80+
test(
81+
s"correct JVM is picked up by $launcherString when Java $index is passed with --java-home"
82+
) {
83+
TestUtil.retryOnCi() {
84+
TestInputs(
85+
os.rel / "check_java_home.sc" ->
86+
s"""assert(
87+
| System.getProperty("java.version").startsWith("$javaVersion") ||
88+
| System.getProperty("java.version").startsWith("1.$javaVersion")
89+
|)
90+
|println(System.getProperty("java.home"))""".stripMargin
91+
).fromRoot { root =>
92+
val javaHome =
93+
os.Path(
94+
os.proc(TestUtil.cs, "java-home", "--jvm", index).call().out.trim(),
95+
os.pwd
96+
)
97+
withLauncher(root) { launcher =>
98+
val res =
99+
os.proc(launcher, "run", ".", extraOptions, "--java-home", javaHome.toString)
100+
.call(cwd = root)
101+
expect(res.out.trim().contains(javaHome.toString))
102+
}
103+
}
104+
}
105+
}
106+
107+
if (javaVersion >= Constants.bloopMinimumJvmVersion)
108+
test(s"Bloop runs correctly with $launcherString on JVM $index") {
109+
TestUtil.retryOnCi() {
110+
val expectedMessage = "Hello, world!"
111+
TestInputs(os.rel / "check_java_home.sc" -> s"""println("$expectedMessage")""")
112+
.fromRoot { root =>
113+
os.proc(TestUtil.cli, "bloop", "exit", "--power").call(cwd = root)
114+
withLauncher(root) { launcher =>
115+
val res = os.proc(
116+
launcher,
117+
"run",
118+
".",
119+
extraOptions,
120+
"--bloop-jvm",
121+
index,
122+
"--jvm",
123+
index
124+
)
125+
.call(cwd = root, stderr = os.Pipe)
126+
expect(res.err.trim().contains(javaVersion.toString))
127+
expect(res.out.trim() == expectedMessage)
128+
}
129+
}
130+
}
131+
}
132+
}
133+
}

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

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

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -842,9 +842,9 @@ class SipScalaTests extends ScalaCliSuite
842842
val scalaVersion = Constants.scala3NextRcAnnounced
843843
withScalaRunnerWrapper(
844844
root = root,
845-
localCache = localCache,
846845
localBin = localBin,
847-
scalaVersion = scalaVersion
846+
scalaVersion = scalaVersion,
847+
localCache = Some(localCache)
848848
) { launchScalaPath =>
849849
val r =
850850
os.proc(

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)