Skip to content

Commit 5da0e9a

Browse files
authored
Add tests for setup-ide with --cli-version (#3163)
1 parent 31a88e4 commit 5da0e9a

File tree

2 files changed

+42
-18
lines changed

2 files changed

+42
-18
lines changed

modules/cli/src/main/scala/scala/cli/ScalaCli.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,9 @@ object ScalaCli {
252252
predefinedCliVersion = None,
253253
initialLauncherPath = None
254254
)
255-
case v if v < Version("1.5.1") && !ver.contains("nightly") =>
255+
case v
256+
if v < Version("1.5.0-34-g31a88e428-SNAPSHOT") && v < Version("1.5.1") &&
257+
!ver.contains("nightly") =>
256258
initialScalaRunnerArgs.copy(
257259
predefinedCliVersion = None,
258260
initialLauncherPath = None

modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala

Lines changed: 39 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2163,21 +2163,43 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
21632163
}
21642164
}
21652165

2166-
// TODO: uncomment when the fix for https://github.com/VirtusLab/scala-cli/issues/3157 is on nightly
2167-
// test("setup-ide prepares a valid BSP configuration with --cli-version") {
2168-
// val scriptName = "cli-version.sc"
2169-
// val cliVersion = "nightly"
2170-
// val inputs = TestInputs(os.rel / scriptName -> s"""println("Hello from launcher v$cliVersion""")
2171-
// inputs.fromRoot { root =>
2172-
// val cliVersionArgs = List("--cli-version", cliVersion)
2173-
// os.proc(TestUtil.cli, cliVersionArgs, "setup-ide", scriptName, extraOptions).call(cwd = root)
2174-
// val expectedIdeLauncherFile = root / Constants.workspaceDirName / "ide-launcher-options.json"
2175-
// expect(expectedIdeLauncherFile.toNIO.toFile.exists())
2176-
// expect(os.read(expectedIdeLauncherFile).contains(cliVersion))
2177-
// val bspConfig = readBspConfig(root)
2178-
// expect(bspConfig.argv.head == TestUtil.cliPath)
2179-
// expect(bspConfig.argv.containsSlice(cliVersionArgs))
2180-
// expect(bspConfig.argv.indexOfSlice(cliVersionArgs) < bspConfig.argv.indexOf("bsp"))
2181-
// }
2182-
// }
2166+
for { cliVersion <- Seq("1.5.0", "1.5.0-19-g932866db6-SNAPSHOT", "1.0.0") }
2167+
test(s"setup-ide doesn't pass unrecognised arguments to old --cli-versions: $cliVersion") {
2168+
val scriptName = "cli-version.sc"
2169+
val inputs = TestInputs(
2170+
os.rel / scriptName -> s"""println("Hello from launcher v$cliVersion"""
2171+
)
2172+
inputs.fromRoot { root =>
2173+
val r =
2174+
os.proc(TestUtil.cli, "--cli-version", cliVersion, "setup-ide", scriptName, extraOptions)
2175+
.call(cwd = root, stderr = os.Pipe, check = false)
2176+
expect(!r.err.text().contains("Unrecognized argument"))
2177+
expect(r.exitCode == 0)
2178+
}
2179+
}
2180+
2181+
// TODO: test for the most recent CLI version as well when 1.5.1 is out
2182+
for { cliVersion <- Seq("1.5.0-34-g31a88e428-SNAPSHOT") }
2183+
test(
2184+
s"setup-ide prepares a valid BSP configuration with --cli-version $cliVersion"
2185+
) {
2186+
val scriptName = "cli-version.sc"
2187+
val inputs = TestInputs(
2188+
os.rel / scriptName -> s"""println("Hello from launcher v$cliVersion"""
2189+
)
2190+
inputs.fromRoot { root =>
2191+
val cliVersionArgs = List("--cli-version", cliVersion)
2192+
os.proc(TestUtil.cli, cliVersionArgs, "setup-ide", scriptName, extraOptions).call(cwd =
2193+
root
2194+
)
2195+
val expectedIdeLauncherFile =
2196+
root / Constants.workspaceDirName / "ide-launcher-options.json"
2197+
expect(expectedIdeLauncherFile.toNIO.toFile.exists())
2198+
expect(os.read(expectedIdeLauncherFile).contains(cliVersion))
2199+
val bspConfig = readBspConfig(root)
2200+
expect(bspConfig.argv.head == TestUtil.cliPath)
2201+
expect(bspConfig.argv.containsSlice(cliVersionArgs))
2202+
expect(bspConfig.argv.indexOfSlice(cliVersionArgs) < bspConfig.argv.indexOf("bsp"))
2203+
}
2204+
}
21832205
}

0 commit comments

Comments
 (0)