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 17, 2024
1 parent 1a51bf2 commit 8a3c41f
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package scala.cli.integration

import com.eed3si9n.expecty.Expecty.expect

import scala.util.Properties

trait RunJdkTestDefinitions { _: RunTestDefinitions =>
val allJdkVersionsToTest: Seq[Int] = Seq(8, 11, 17, 21, 23)

def javaIndex(javaVersion: Int): String =
if (Properties.isMac && TestUtil.isM1 && javaVersion < 11) s"zulu:$javaVersion"
else javaVersion.toString

for { javaVersion <- allJdkVersionsToTest } {
test(s"correct JVM is picked up when JAVA_HOME set to $javaVersion") {
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", javaIndex(javaVersion)).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 $javaVersion") {
TestUtil.retryOnCi() {
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)
}
}
}
}
}
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

0 comments on commit 8a3c41f

Please sign in to comment.