|
| 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 | + def javaIndex(javaVersion: Int): String = |
| 9 | + // TODO just passing the version number on arm64 should be enough, needs a fix in cs |
| 10 | + if (Properties.isMac && TestUtil.isM1 && (javaVersion < 11 || javaVersion == 16)) |
| 11 | + s"zulu:$javaVersion" |
| 12 | + else javaVersion.toString |
| 13 | + |
| 14 | + for { |
| 15 | + javaVersion <- Constants.allJavaVersions |
| 16 | + index = javaIndex(javaVersion) |
| 17 | + } { |
| 18 | + test(s"correct JVM is picked up when JAVA_HOME set to $index") { |
| 19 | + TestUtil.retryOnCi() { |
| 20 | + TestInputs( |
| 21 | + os.rel / "check_java_home.sc" -> |
| 22 | + s"""assert( |
| 23 | + | System.getProperty("java.version").startsWith("$javaVersion") || |
| 24 | + | System.getProperty("java.version").startsWith("1.$javaVersion") |
| 25 | + |) |
| 26 | + |println(System.getProperty("java.home"))""".stripMargin |
| 27 | + ).fromRoot { root => |
| 28 | + val javaHome = |
| 29 | + os.Path( |
| 30 | + os.proc(TestUtil.cs, "java-home", "--jvm", index).call().out.trim(), |
| 31 | + os.pwd |
| 32 | + ) |
| 33 | + val res = os.proc(TestUtil.cli, "run", ".", extraOptions) |
| 34 | + .call(cwd = root, env = Map("JAVA_HOME" -> javaHome.toString)) |
| 35 | + expect(res.out.trim().contains(javaHome.toString)) |
| 36 | + } |
| 37 | + } |
| 38 | + } |
| 39 | + |
| 40 | + test(s"hello world with --jvm $index") { |
| 41 | + val expectedMessage = "Hello, world!" |
| 42 | + TestInputs( |
| 43 | + os.rel / "hello_world.sc" -> s"println(\"$expectedMessage\")" |
| 44 | + ).fromRoot { root => |
| 45 | + val res = os.proc(TestUtil.cli, "run", ".", extraOptions, "--jvm", javaVersion) |
| 46 | + .call(cwd = root) |
| 47 | + expect(res.out.trim() == expectedMessage) |
| 48 | + } |
| 49 | + } |
| 50 | + |
| 51 | + test(s"correct JVM is picked up when Java $index is passed with --java-home") { |
| 52 | + TestUtil.retryOnCi() { |
| 53 | + TestInputs( |
| 54 | + os.rel / "check_java_home.sc" -> |
| 55 | + s"""assert( |
| 56 | + | System.getProperty("java.version").startsWith("$javaVersion") || |
| 57 | + | System.getProperty("java.version").startsWith("1.$javaVersion") |
| 58 | + |) |
| 59 | + |println(System.getProperty("java.home"))""".stripMargin |
| 60 | + ).fromRoot { root => |
| 61 | + val javaHome = |
| 62 | + os.Path( |
| 63 | + os.proc(TestUtil.cs, "java-home", "--jvm", index).call().out.trim(), |
| 64 | + os.pwd |
| 65 | + ) |
| 66 | + val res = |
| 67 | + os.proc(TestUtil.cli, "run", ".", extraOptions, "--java-home", javaHome.toString) |
| 68 | + .call(cwd = root) |
| 69 | + expect(res.out.trim().contains(javaHome.toString)) |
| 70 | + } |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | + if (javaVersion >= Constants.bloopMinimumJvmVersion) |
| 75 | + test(s"Bloop runs correctly on JVM $index") { |
| 76 | + TestUtil.retryOnCi() { |
| 77 | + val expectedMessage = "Hello, world!" |
| 78 | + TestInputs(os.rel / "check_java_home.sc" -> s"""println("$expectedMessage")""") |
| 79 | + .fromRoot { root => |
| 80 | + os.proc(TestUtil.cli, "bloop", "exit", "--power").call(cwd = root) |
| 81 | + val res = os.proc( |
| 82 | + TestUtil.cli, |
| 83 | + "run", |
| 84 | + ".", |
| 85 | + extraOptions, |
| 86 | + "--bloop-jvm", |
| 87 | + index, |
| 88 | + "--jvm", |
| 89 | + index |
| 90 | + ) |
| 91 | + .call(cwd = root, stderr = os.Pipe) |
| 92 | + expect(res.err.trim().contains(javaVersion.toString)) |
| 93 | + expect(res.out.trim() == expectedMessage) |
| 94 | + } |
| 95 | + } |
| 96 | + } |
| 97 | + } |
| 98 | +} |
0 commit comments