Skip to content

Commit

Permalink
Merge pull request #3375 from Gedochao/maintenance/test-java-23
Browse files Browse the repository at this point in the history
Run extra tests for main supported JVM versions
  • Loading branch information
Gedochao authored Dec 30, 2024
2 parents 511f6fc + 2c203af commit 55ccea7
Show file tree
Hide file tree
Showing 7 changed files with 171 additions and 25 deletions.
5 changes: 5 additions & 0 deletions build.sc
Original file line number Diff line number Diff line change
Expand Up @@ -1030,12 +1030,17 @@ 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}"
| def scala3LtsPrefix = "${Scala.scala3LtsPrefix}"
| def scala3Lts = "${Scala.scala3Lts}"
| def scala3NextPrefix = "${Scala.scala3NextPrefix}"
| def scala3NextRc = "${Scala.scala3NextRc}"
| def scala3NextRcAnnounced = "${Scala.scala3NextRcAnnounced}"
| def scala3Next = "${Scala.scala3Next}"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1908,19 +1908,19 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg

test("BSP respects JAVA_HOME") {
TestUtil.retryOnCi() {
val javaVersion = "22"
val javaVersion = "23"
val inputs = TestInputs(os.rel / "check-java.sc" ->
s"""assert(System.getProperty("java.version").startsWith("$javaVersion"))
|println(System.getProperty("java.home"))""".stripMargin)
inputs.fromRoot { root =>
os.proc(TestUtil.cli, "bloop", "exit", "--power").call(cwd = root)
val java22Home =
val java23Home =
os.Path(
os.proc(TestUtil.cs, "java-home", "--jvm", s"zulu:$javaVersion").call().out.trim(),
os.pwd
)
os.proc(TestUtil.cli, "setup-ide", "check-java.sc")
.call(cwd = root, env = Map("JAVA_HOME" -> java22Home.toString()))
.call(cwd = root, env = Map("JAVA_HOME" -> java23Home.toString()))
val ideOptionsPath = root / Constants.workspaceDirName / "ide-options-v2.json"
expect(ideOptionsPath.toNIO.toFile.exists())
val ideEnvsPath = root / Constants.workspaceDirName / "ide-envs.json"
Expand Down Expand Up @@ -1948,7 +1948,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg

test("BSP respects --java-home") {
TestUtil.retryOnCi() {
val javaVersion = "22"
val javaVersion = "23"
val inputs = TestInputs(os.rel / "check-java.sc" ->
s"""assert(System.getProperty("java.version").startsWith("$javaVersion"))
|println(System.getProperty("java.home"))""".stripMargin)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,16 @@ import scala.util.Properties
trait CoursierScalaInstallationTestHelper {
def withScalaRunnerWrapper(
root: os.Path,
localCache: os.Path,
localBin: os.Path,
scalaVersion: String
scalaVersion: String,
localCache: Option[os.Path] = None,
shouldCleanUp: Boolean = true
)(f: os.Path => Unit): Unit = {
val localCacheArgs = localCache.fold(Seq.empty[String])(c => Seq("--cache", c.toString))
os.proc(
TestUtil.cs,
"install",
"--cache",
localCache,
localCacheArgs,
"--install-dir",
localBin,
s"scala:$scalaVersion"
Expand Down Expand Up @@ -74,21 +75,23 @@ trait CoursierScalaInstallationTestHelper {
.call(cwd = root).out.trim()
expect(wrapperVersion == cliVersion)
f(launchScalaPath)
// clean up cs local binaries
val csPrebuiltBinaryDir =
os.Path(underlyingScriptPath.toString().substring(
0,
underlyingScriptPath.toString().indexOf(scalaVersion) + scalaVersion.length
))
System.err.println(s"Cleaning up, trying to remove $csPrebuiltBinaryDir")
try {
os.remove.all(csPrebuiltBinaryDir)
if (shouldCleanUp) {
// clean up cs local binaries
val csPrebuiltBinaryDir =
os.Path(underlyingScriptPath.toString().substring(
0,
underlyingScriptPath.toString().indexOf(scalaVersion) + scalaVersion.length
))
System.err.println(s"Cleaning up, trying to remove $csPrebuiltBinaryDir")
try {
os.remove.all(csPrebuiltBinaryDir)

System.err.println(s"Cleanup complete. Removed $csPrebuiltBinaryDir")
}
catch {
case ex: java.nio.file.FileSystemException =>
System.err.println(s"Failed to remove $csPrebuiltBinaryDir: $ex")
System.err.println(s"Cleanup complete. Removed $csPrebuiltBinaryDir")
}
catch {
case ex: java.nio.file.FileSystemException =>
System.err.println(s"Failed to remove $csPrebuiltBinaryDir: $ex")
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
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

def canUseScalaInstallationWrapper: Boolean =
actualScalaVersion.startsWith("3") && actualScalaVersion.split('.').drop(1).head.toInt >= 5

for {
javaVersion <- Constants.allJavaVersions
index = javaIndex(javaVersion)
useScalaInstallationWrapper <-
if (canUseScalaInstallationWrapper) Seq(false, true) else Seq(false)
launcherString = if (useScalaInstallationWrapper) "coursier scala installation" else "Scala CLI"
scalaRunnerWrapperVersion = actualScalaVersion match {
case v if v == Constants.scala3NextRc => Constants.scala3NextRcAnnounced
case v if v == Constants.scala3Next => Constants.scala3NextAnnounced
case v => v
}
withLauncher = (root: os.Path) =>
(f: Seq[os.Shellable] => Unit) =>
if (useScalaInstallationWrapper)
withScalaRunnerWrapper(
root = root,
localBin = root / "local-bin",
scalaVersion = scalaRunnerWrapperVersion,
shouldCleanUp = false
)(launcher => f(Seq(launcher)))
else
f(Seq(TestUtil.cli))
} {
test(s"correct JVM is picked up by $launcherString 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
)
withLauncher(root) { launcher =>
val res = os.proc(launcher, "run", ".", extraOptions)
.call(cwd = root, env = Map("JAVA_HOME" -> javaHome.toString))
expect(res.out.trim().contains(javaHome.toString))
}
}
}
}

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

if (!Properties.isWin || !useScalaInstallationWrapper) // TODO make this pass on Windows
test(
s"correct JVM is picked up by $launcherString 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
)
withLauncher(root) { launcher =>
val res =
os.proc(launcher, "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 with $launcherString 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)
withLauncher(root) { launcher =>
val res = os.proc(
launcher,
"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,9 @@ abstract class RunTestDefinitions
with RunScalacCompatTestDefinitions
with RunSnippetTestDefinitions
with RunScalaPyTestDefinitions
with RunZipTestDefinitions { _: TestScalaVersion =>
with RunZipTestDefinitions
with RunJdkTestDefinitions
with CoursierScalaInstallationTestHelper { _: TestScalaVersion =>
protected lazy val extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions
protected val emptyInputs: TestInputs = TestInputs(os.rel / ".placeholder" -> "")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -842,9 +842,9 @@ class SipScalaTests extends ScalaCliSuite
val scalaVersion = Constants.scala3NextRcAnnounced
withScalaRunnerWrapper(
root = root,
localCache = localCache,
localBin = localBin,
scalaVersion = scalaVersion
scalaVersion = scalaVersion,
localCache = Some(localCache)
) { launchScalaPath =>
val r =
os.proc(
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 55ccea7

Please sign in to comment.