|
| 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 | +} |
0 commit comments