From c33a3166e904d7ee03f513645cec78f46f7dfddb Mon Sep 17 00:00:00 2001 From: Piotr Chabelski Date: Tue, 17 Dec 2024 15:57:28 +0100 Subject: [PATCH 1/3] Bump BSP tests from Java 22 to 23 --- .../scala/scala/cli/integration/BspTestDefinitions.scala | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala index 82c1d7b60c..c3f4bed829 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala @@ -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" @@ -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) From c1bd77a9afd717d1530f17209a9252fe7b55436b Mon Sep 17 00:00:00 2001 From: Piotr Chabelski Date: Tue, 17 Dec 2024 16:42:47 +0100 Subject: [PATCH 2/3] Run some extra tests for Java 8, 11, 17, 21 & 23 --- build.sc | 4 + .../integration/RunJdkTestDefinitions.scala | 98 +++++++++++++++++++ .../cli/integration/RunTestDefinitions.scala | 3 +- project/deps.sc | 3 + 4 files changed, 107 insertions(+), 1 deletion(-) create mode 100644 modules/integration/src/test/scala/scala/cli/integration/RunJdkTestDefinitions.scala diff --git a/build.sc b/build.sc index 1402aeddb8..4e24282710 100644 --- a/build.sc +++ b/build.sc @@ -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}" diff --git a/modules/integration/src/test/scala/scala/cli/integration/RunJdkTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/RunJdkTestDefinitions.scala new file mode 100644 index 0000000000..f76bba245b --- /dev/null +++ b/modules/integration/src/test/scala/scala/cli/integration/RunJdkTestDefinitions.scala @@ -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) + } + } + } + } +} diff --git a/modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala index 767ad9767d..192ec100d7 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala @@ -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" -> "") diff --git a/project/deps.sc b/project/deps.sc index 1f5291af07..24b1d92c0c 100644 --- a/project/deps.sc +++ b/project/deps.sc @@ -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 From 2c203afb87fa92657932df7e6822522715c54f3f Mon Sep 17 00:00:00 2001 From: Piotr Chabelski Date: Wed, 18 Dec 2024 18:04:58 +0100 Subject: [PATCH 3/3] Run JDK tests for both the Scala CLI launchers and `coursier` Scala installation's `scala` script --- build.sc | 1 + .../CoursierScalaInstallationTestHelper.scala | 39 +++--- .../integration/RunJdkTestDefinitions.scala | 119 +++++++++++------- .../cli/integration/RunTestDefinitions.scala | 3 +- .../scala/cli/integration/SipScalaTests.scala | 4 +- 5 files changed, 103 insertions(+), 63 deletions(-) diff --git a/build.sc b/build.sc index 4e24282710..7a6579d5c4 100644 --- a/build.sc +++ b/build.sc @@ -1040,6 +1040,7 @@ trait CliIntegration extends SbtModule with ScalaCliPublishModule with HasTests | 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}" diff --git a/modules/integration/src/test/scala/scala/cli/integration/CoursierScalaInstallationTestHelper.scala b/modules/integration/src/test/scala/scala/cli/integration/CoursierScalaInstallationTestHelper.scala index 2eb53db2e8..0eb31e5ca3 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/CoursierScalaInstallationTestHelper.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/CoursierScalaInstallationTestHelper.scala @@ -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" @@ -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") + } } } } diff --git a/modules/integration/src/test/scala/scala/cli/integration/RunJdkTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/RunJdkTestDefinitions.scala index f76bba245b..bb93fbea58 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/RunJdkTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/RunJdkTestDefinitions.scala @@ -11,11 +11,33 @@ trait RunJdkTestDefinitions { _: RunTestDefinitions => 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 when JAVA_HOME set to $index") { + test(s"correct JVM is picked up by $launcherString when JAVA_HOME set to $index") { TestUtil.retryOnCi() { TestInputs( os.rel / "check_java_home.sc" -> @@ -30,67 +52,80 @@ trait RunJdkTestDefinitions { _: RunTestDefinitions => os.proc(TestUtil.cs, "java-home", "--jvm", index).call().out.trim(), os.pwd ) - val res = os.proc(TestUtil.cli, "run", ".", extraOptions) + 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 --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") { + test(s"hello world with $launcherString and --jvm $index") { TestUtil.retryOnCi() { + val expectedMessage = "Hello, world!" 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 + os.rel / "hello_world.sc" -> s"println(\"$expectedMessage\")" ).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) + withLauncher(root) { launcher => + val res = os.proc(launcher, "run", ".", extraOptions, "--jvm", javaVersion) .call(cwd = root) - expect(res.out.trim().contains(javaHome.toString)) + 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 on JVM $index") { + 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) - 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) + 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) + } } } } diff --git a/modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala b/modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala index 192ec100d7..486b2f602a 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala @@ -22,7 +22,8 @@ abstract class RunTestDefinitions with RunSnippetTestDefinitions with RunScalaPyTestDefinitions with RunZipTestDefinitions - with RunJdkTestDefinitions { _: TestScalaVersion => + with RunJdkTestDefinitions + with CoursierScalaInstallationTestHelper { _: TestScalaVersion => protected lazy val extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions protected val emptyInputs: TestInputs = TestInputs(os.rel / ".placeholder" -> "") diff --git a/modules/integration/src/test/scala/scala/cli/integration/SipScalaTests.scala b/modules/integration/src/test/scala/scala/cli/integration/SipScalaTests.scala index 813ec100d6..daee0f49ba 100644 --- a/modules/integration/src/test/scala/scala/cli/integration/SipScalaTests.scala +++ b/modules/integration/src/test/scala/scala/cli/integration/SipScalaTests.scala @@ -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(