@@ -15,8 +15,11 @@ import scala.concurrent.duration._
15
15
import scala .jdk .CollectionConverters ._
16
16
import scala .util .Properties
17
17
18
- abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArgs
19
- with BspSuite with ScriptWrapperTestDefinitions {
18
+ abstract class BspTestDefinitions extends ScalaCliSuite
19
+ with TestScalaVersionArgs
20
+ with BspSuite
21
+ with ScriptWrapperTestDefinitions
22
+ with CoursierScalaInstallationTestHelper {
20
23
_ : TestScalaVersion =>
21
24
protected lazy val extraOptions : Seq [String ] = scalaVersionArgs ++ TestUtil .extraOptions
22
25
@@ -31,7 +34,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
31
34
os.proc(TestUtil .cli, " setup-ide" , " ." , extraOptions).call(cwd = root, stdout = os.Inherit )
32
35
val details = readBspConfig(root)
33
36
expect(details.argv.length >= 2 )
34
- expect(details.argv( 1 ) == " bsp" )
37
+ expect(details.argv.dropWhile(_ != TestUtil .cliPath).drop( 1 ).head == " bsp" )
35
38
}
36
39
}
37
40
@@ -63,7 +66,11 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
63
66
expectedIdeEnvsFile.toString,
64
67
root.toString
65
68
)
66
- expect(details.argv == expectedArgv)
69
+ if (TestUtil .isJvmBootstrappedCli) {
70
+ expect(details.argv.head.endsWith(" java" ))
71
+ expect(details.argv.drop(1 ).head == " -jar" )
72
+ }
73
+ expect(details.argv.dropWhile(_ != TestUtil .cliPath) == expectedArgv)
67
74
expect(os.isFile(expectedIdeOptionsFile))
68
75
expect(os.isFile(expectedIdeInputsFile))
69
76
expect(os.isFile(expectedIdeEnvsFile))
@@ -108,7 +115,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
108
115
(root / " directory" / Constants .workspaceDirName / " ide-envs.json" ).toString,
109
116
(root / " directory" / " simple.sc" ).toString
110
117
)
111
- expect(details.argv == expectedArgv)
118
+ expect(details.argv.dropWhile(_ != TestUtil .cliPath) == expectedArgv)
112
119
}
113
120
}
114
121
@@ -2220,14 +2227,90 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
2220
2227
}
2221
2228
}
2222
2229
2230
+ for {
2231
+ useScalaWrapper <- Seq (false , true )
2232
+ if actualScalaVersion.coursierVersion >= " 3.5.0" .coursierVersion
2233
+ withLauncher = (root : os.Path ) =>
2234
+ (f : Seq [os.Shellable ] => Unit ) =>
2235
+ if (useScalaWrapper)
2236
+ withScalaRunnerWrapper(
2237
+ root = root,
2238
+ localBin = root / " local-bin" ,
2239
+ localCache = Some (root / " local-cache" ),
2240
+ scalaVersion = actualScalaVersion,
2241
+ shouldCleanUp = false
2242
+ )(launcher => f(Seq (launcher)))
2243
+ else
2244
+ f(Seq (TestUtil .cli))
2245
+ launcherString = if (useScalaWrapper) " coursier scala installation" else " Scala CLI"
2246
+ connectionJsonFileName = if (useScalaWrapper) " scala.json" else " scala-cli.json"
2247
+ }
2248
+ test(
2249
+ s " setup-ide with scala wrapper prepares valid BSP connection json with a valid launcher ( $launcherString) "
2250
+ ) {
2251
+ TestUtil .retryOnCi() {
2252
+ val scriptName = " example.sc"
2253
+ TestInputs (
2254
+ os.rel / scriptName -> s """ println("Hello") """
2255
+ )
2256
+ .fromRoot { root =>
2257
+ withLauncher(root) { launcher =>
2258
+ val javaHome =
2259
+ os.Path (
2260
+ os.proc(TestUtil .cs, " java-home" , " --jvm" , " zulu:8" ).call().out.trim(),
2261
+ os.pwd
2262
+ )
2263
+ os.proc(launcher, " setup-ide" , scriptName, extraOptions)
2264
+ .call(cwd = root, env = Map (" JAVA_HOME" -> javaHome.toString))
2265
+ val expectedIdeLauncherFile =
2266
+ root / Constants .workspaceDirName / " ide-launcher-options.json"
2267
+ expect(expectedIdeLauncherFile.toNIO.toFile.exists())
2268
+ val bspConfig = readBspConfig(root, connectionJsonFileName)
2269
+ val bspLauncherCommand = {
2270
+ val launcherPrefix = bspConfig.argv.takeWhile(_ != TestUtil .cliPath)
2271
+ launcherPrefix :+ bspConfig.argv.drop(launcherPrefix.length).head
2272
+ }
2273
+ expect(bspLauncherCommand.last == TestUtil .cliPath)
2274
+ if (TestUtil .isJvmBootstrappedCli) {
2275
+ // this launcher is not self-executable and has to be launched with `java -jar`
2276
+ expect(bspLauncherCommand.head.endsWith(" java" ))
2277
+ expect(bspLauncherCommand.drop(1 ) == List (" -jar" , TestUtil .cliPath))
2278
+ val bspJavaVersionResult = os.proc(bspLauncherCommand.head, " -version" )
2279
+ .call(
2280
+ cwd = root,
2281
+ env = Map (" JAVA_HOME" -> javaHome.toString),
2282
+ mergeErrIntoOut = true
2283
+ )
2284
+ val bspJavaVersion = TestUtil .parseJavaVersion(bspJavaVersionResult.out.trim()).get
2285
+ // the bsp launcher has to know to run itself on a supported JVM
2286
+ expect(bspJavaVersion >= math.max(
2287
+ Constants .minimumInternalJvmVersion,
2288
+ Constants .bloopMinimumJvmVersion
2289
+ ))
2290
+ }
2291
+ else
2292
+ expect(bspLauncherCommand == List (TestUtil .cliPath))
2293
+ val r = os.proc(bspLauncherCommand, " version" , " --cli-version" )
2294
+ .call(cwd = root, env = Map (" JAVA_HOME" -> javaHome.toString))
2295
+ expect(r.out.trim() == Constants .cliVersion)
2296
+ }
2297
+ }
2298
+ }
2299
+ }
2300
+
2223
2301
test(" setup-ide passes Java props to the BSP configuration correctly" ) {
2224
2302
val scriptName = " hello.sc"
2225
2303
TestInputs (os.rel / scriptName -> s """ println("Hello") """ ).fromRoot { root =>
2226
2304
val javaProps = List (" -Dfoo=bar" , " -Dbar=baz" )
2227
2305
os.proc(TestUtil .cli, javaProps, " setup-ide" , scriptName, extraOptions)
2228
2306
.call(cwd = root)
2229
2307
val bspConfig = readBspConfig(root)
2230
- expect(bspConfig.argv.head == TestUtil .cliPath)
2308
+ if (TestUtil .isJvmBootstrappedCli) {
2309
+ expect(bspConfig.argv.head.endsWith(" java" ))
2310
+ expect(bspConfig.argv.drop(1 ).head == " -jar" )
2311
+ expect(bspConfig.argv.dropWhile(_ != TestUtil .cliPath).head == TestUtil .cliPath)
2312
+ }
2313
+ else expect(bspConfig.argv.head == TestUtil .cliPath)
2231
2314
expect(bspConfig.argv.containsSlice(javaProps))
2232
2315
expect(bspConfig.argv.indexOfSlice(javaProps) < bspConfig.argv.indexOf(" bsp" ))
2233
2316
}
0 commit comments