@@ -15,8 +15,11 @@ import scala.concurrent.duration._
1515import scala .jdk .CollectionConverters ._
1616import scala .util .Properties
1717
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 {
2023 _ : TestScalaVersion =>
2124 protected lazy val extraOptions : Seq [String ] = scalaVersionArgs ++ TestUtil .extraOptions
2225
@@ -31,7 +34,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
3134 os.proc(TestUtil .cli, " setup-ide" , " ." , extraOptions).call(cwd = root, stdout = os.Inherit )
3235 val details = readBspConfig(root)
3336 expect(details.argv.length >= 2 )
34- expect(details.argv( 1 ) == " bsp" )
37+ expect(details.argv.dropWhile(_ != TestUtil .cliPath).drop( 1 ).head == " bsp" )
3538 }
3639 }
3740
@@ -63,7 +66,11 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
6366 expectedIdeEnvsFile.toString,
6467 root.toString
6568 )
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)
6774 expect(os.isFile(expectedIdeOptionsFile))
6875 expect(os.isFile(expectedIdeInputsFile))
6976 expect(os.isFile(expectedIdeEnvsFile))
@@ -108,7 +115,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
108115 (root / " directory" / Constants .workspaceDirName / " ide-envs.json" ).toString,
109116 (root / " directory" / " simple.sc" ).toString
110117 )
111- expect(details.argv == expectedArgv)
118+ expect(details.argv.dropWhile(_ != TestUtil .cliPath) == expectedArgv)
112119 }
113120 }
114121
@@ -2220,14 +2227,90 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
22202227 }
22212228 }
22222229
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+
22232301 test(" setup-ide passes Java props to the BSP configuration correctly" ) {
22242302 val scriptName = " hello.sc"
22252303 TestInputs (os.rel / scriptName -> s """ println("Hello") """ ).fromRoot { root =>
22262304 val javaProps = List (" -Dfoo=bar" , " -Dbar=baz" )
22272305 os.proc(TestUtil .cli, javaProps, " setup-ide" , scriptName, extraOptions)
22282306 .call(cwd = root)
22292307 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)
22312314 expect(bspConfig.argv.containsSlice(javaProps))
22322315 expect(bspConfig.argv.indexOfSlice(javaProps) < bspConfig.argv.indexOf(" bsp" ))
22332316 }
0 commit comments