@@ -11,11 +11,33 @@ trait RunJdkTestDefinitions { _: RunTestDefinitions =>
11
11
s " zulu: $javaVersion"
12
12
else javaVersion.toString
13
13
14
+ def canUseScalaInstallationWrapper : Boolean =
15
+ actualScalaVersion.startsWith(" 3" ) && actualScalaVersion.split('.' ).drop(1 ).head.toInt >= 5
16
+
14
17
for {
15
18
javaVersion <- Constants .allJavaVersions
16
19
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))
17
39
} {
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" ) {
19
41
TestUtil .retryOnCi() {
20
42
TestInputs (
21
43
os.rel / " check_java_home.sc" ->
@@ -30,67 +52,80 @@ trait RunJdkTestDefinitions { _: RunTestDefinitions =>
30
52
os.proc(TestUtil .cs, " java-home" , " --jvm" , index).call().out.trim(),
31
53
os.pwd
32
54
)
33
- val res = os.proc(TestUtil .cli, " run" , " ." , extraOptions)
55
+ withLauncher(root) { launcher =>
56
+ val res = os.proc(launcher, " run" , " ." , extraOptions)
34
57
.call(cwd = root, env = Map (" JAVA_HOME" -> javaHome.toString))
35
58
expect(res.out.trim().contains(javaHome.toString))
59
+ }
36
60
}
37
61
}
38
62
}
39
63
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" ) {
52
65
TestUtil .retryOnCi() {
66
+ val expectedMessage = " Hello, world!"
53
67
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\" ) "
60
69
).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)
68
72
.call(cwd = root)
69
- expect(res.out.trim().contains(javaHome.toString))
73
+ expect(res.out.trim() == expectedMessage)
74
+ }
70
75
}
71
76
}
72
77
}
73
78
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
+
74
107
if (javaVersion >= Constants .bloopMinimumJvmVersion)
75
- test(s " Bloop runs correctly on JVM $index" ) {
108
+ test(s " Bloop runs correctly with $launcherString on JVM $index" ) {
76
109
TestUtil .retryOnCi() {
77
110
val expectedMessage = " Hello, world!"
78
111
TestInputs (os.rel / " check_java_home.sc" -> s """ println(" $expectedMessage") """ )
79
112
.fromRoot { root =>
80
113
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
+ }
94
129
}
95
130
}
96
131
}
0 commit comments