Skip to content

Commit 8a3c41f

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

File tree

2 files changed

+52
-1
lines changed

2 files changed

+52
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
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+
val allJdkVersionsToTest: Seq[Int] = Seq(8, 11, 17, 21, 23)
9+
10+
def javaIndex(javaVersion: Int): String =
11+
if (Properties.isMac && TestUtil.isM1 && javaVersion < 11) s"zulu:$javaVersion"
12+
else javaVersion.toString
13+
14+
for { javaVersion <- allJdkVersionsToTest } {
15+
test(s"correct JVM is picked up when JAVA_HOME set to $javaVersion") {
16+
TestUtil.retryOnCi() {
17+
TestInputs(
18+
os.rel / "check_java_home.sc" ->
19+
s"""assert(
20+
| System.getProperty("java.version").startsWith("$javaVersion") ||
21+
| System.getProperty("java.version").startsWith("1.$javaVersion")
22+
|)
23+
|println(System.getProperty("java.home"))""".stripMargin
24+
).fromRoot { root =>
25+
val javaHome =
26+
os.Path(
27+
os.proc(TestUtil.cs, "java-home", "--jvm", javaIndex(javaVersion)).call().out.trim(),
28+
os.pwd
29+
)
30+
val res = os.proc(TestUtil.cli, "run", ".", extraOptions)
31+
.call(cwd = root, env = Map("JAVA_HOME" -> javaHome.toString))
32+
expect(res.out.trim().contains(javaHome.toString))
33+
}
34+
}
35+
}
36+
37+
test(s"hello world with --jvm $javaVersion") {
38+
TestUtil.retryOnCi() {
39+
val expectedMessage = "Hello, world!"
40+
TestInputs(
41+
os.rel / "hello_world.sc" -> s"println(\"$expectedMessage\")"
42+
).fromRoot { root =>
43+
val res = os.proc(TestUtil.cli, "run", ".", extraOptions, "--jvm", javaVersion)
44+
.call(cwd = root)
45+
expect(res.out.trim() == expectedMessage)
46+
}
47+
}
48+
}
49+
}
50+
}

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

0 commit comments

Comments
 (0)