@@ -11,11 +11,33 @@ trait RunJdkTestDefinitions { _: RunTestDefinitions =>
1111 s " zulu: $javaVersion"
1212 else javaVersion.toString
1313
14+ def canUseScalaInstallationWrapper : Boolean =
15+ actualScalaVersion.startsWith(" 3" ) && actualScalaVersion.split('.' ).drop(1 ).head.toInt >= 5
16+
1417 for {
1518 javaVersion <- Constants .allJavaVersions
1619 index = javaIndex(javaVersion)
20+ useScalaInstallationWrapper <-
21+ if (canUseScalaInstallationWrapper) Seq (false , true ) else Seq (false )
22+ launcherString = if (useScalaInstallationWrapper) " coursier scala installation" else " Scala CLI"
23+ scalaRunnerWrapperVersion = actualScalaVersion match {
24+ case v if v == Constants .scala3NextRc => Constants .scala3NextRcAnnounced
25+ case v if v == Constants .scala3Next => Constants .scala3NextAnnounced
26+ case v => v
27+ }
28+ withLauncher = (root : os.Path ) =>
29+ (f : Seq [os.Shellable ] => Unit ) =>
30+ if (useScalaInstallationWrapper)
31+ withScalaRunnerWrapper(
32+ root = root,
33+ localBin = root / " local-bin" ,
34+ scalaVersion = scalaRunnerWrapperVersion,
35+ shouldCleanUp = false
36+ )(launcher => f(Seq (launcher)))
37+ else
38+ f(Seq (TestUtil .cli))
1739 } {
18- test(s " correct JVM is picked up when JAVA_HOME set to $index" ) {
40+ test(s " correct JVM is picked up by $launcherString when JAVA_HOME set to $index" ) {
1941 TestUtil .retryOnCi() {
2042 TestInputs (
2143 os.rel / " check_java_home.sc" ->
@@ -30,67 +52,80 @@ trait RunJdkTestDefinitions { _: RunTestDefinitions =>
3052 os.proc(TestUtil .cs, " java-home" , " --jvm" , index).call().out.trim(),
3153 os.pwd
3254 )
33- val res = os.proc(TestUtil .cli, " run" , " ." , extraOptions)
55+ withLauncher(root) { launcher =>
56+ val res = os.proc(launcher, " run" , " ." , extraOptions)
3457 .call(cwd = root, env = Map (" JAVA_HOME" -> javaHome.toString))
3558 expect(res.out.trim().contains(javaHome.toString))
59+ }
3660 }
3761 }
3862 }
3963
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 " ) {
64+ test(s " hello world with $launcherString and --jvm $index" ) {
5265 TestUtil .retryOnCi() {
66+ val expectedMessage = " Hello, world!"
5367 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
68+ os.rel / " hello_world.sc" -> s " println( \" $expectedMessage\" ) "
6069 ).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)
70+ withLauncher(root) { launcher =>
71+ val res = os.proc(launcher, " run" , " ." , extraOptions, " --jvm" , javaVersion)
6872 .call(cwd = root)
69- expect(res.out.trim().contains(javaHome.toString))
73+ expect(res.out.trim() == expectedMessage)
74+ }
7075 }
7176 }
7277 }
7378
79+ if (! Properties .isWin || ! useScalaInstallationWrapper) // TODO make this pass on Windows
80+ test(
81+ s " correct JVM is picked up by $launcherString when Java $index is passed with --java-home "
82+ ) {
83+ TestUtil .retryOnCi() {
84+ TestInputs (
85+ os.rel / " check_java_home.sc" ->
86+ s """ assert(
87+ | System.getProperty("java.version").startsWith(" $javaVersion") ||
88+ | System.getProperty("java.version").startsWith("1. $javaVersion")
89+ |)
90+ |println(System.getProperty("java.home")) """ .stripMargin
91+ ).fromRoot { root =>
92+ val javaHome =
93+ os.Path (
94+ os.proc(TestUtil .cs, " java-home" , " --jvm" , index).call().out.trim(),
95+ os.pwd
96+ )
97+ withLauncher(root) { launcher =>
98+ val res =
99+ os.proc(launcher, " run" , " ." , extraOptions, " --java-home" , javaHome.toString)
100+ .call(cwd = root)
101+ expect(res.out.trim().contains(javaHome.toString))
102+ }
103+ }
104+ }
105+ }
106+
74107 if (javaVersion >= Constants .bloopMinimumJvmVersion)
75- test(s " Bloop runs correctly on JVM $index" ) {
108+ test(s " Bloop runs correctly with $launcherString on JVM $index" ) {
76109 TestUtil .retryOnCi() {
77110 val expectedMessage = " Hello, world!"
78111 TestInputs (os.rel / " check_java_home.sc" -> s """ println(" $expectedMessage") """ )
79112 .fromRoot { root =>
80113 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)
114+ withLauncher(root) { launcher =>
115+ val res = os.proc(
116+ launcher,
117+ " run" ,
118+ " ." ,
119+ extraOptions,
120+ " --bloop-jvm" ,
121+ index,
122+ " --jvm" ,
123+ index
124+ )
125+ .call(cwd = root, stderr = os.Pipe )
126+ expect(res.err.trim().contains(javaVersion.toString))
127+ expect(res.out.trim() == expectedMessage)
128+ }
94129 }
95130 }
96131 }
0 commit comments