Skip to content

Commit

Permalink
Test custom local repositories passed through launcher params with Sc…
Browse files Browse the repository at this point in the history
…ala 3.5.0-RC1-fakeversion-bin-SNAPSHOT
  • Loading branch information
Gedochao committed May 23, 2024
1 parent 04992d3 commit 6fefa30
Show file tree
Hide file tree
Showing 3 changed files with 133 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2107,72 +2107,6 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
}
}

test("BSP respects --cli-default-scala-version & --predefined-repository launcher options") {
val sv = "3.5.0-RC1"
val inputs = TestInputs(
os.rel / "simple.sc" -> s"""assert(dotty.tools.dotc.config.Properties.simpleVersionString == "$sv")"""
)
inputs.fromRoot { root =>
os.proc(TestUtil.cli, "bloop", "exit", "--power").call(cwd = root)
val localRepoPath = root / "local-repo"
val artifactNames = Seq(
"scala3-compiler_3",
"scala3-staging_3",
"scala3-tasty-inspector_3",
"scala3-sbt-bridge"
)
for { artifactName <- artifactNames } {
val csRes = os.proc(
TestUtil.cs,
"fetch",
"--cache",
localRepoPath,
s"org.scala-lang:$artifactName:$sv"
)
.call(cwd = root)
expect(csRes.exitCode == 0)
}
os.proc(
TestUtil.cli,
"--cli-default-scala-version",
sv,
"--predefined-repository",
(localRepoPath / "https" / "repo1.maven.org" / "maven2").toNIO.toUri.toASCIIString,
"setup-ide",
"simple.sc",
"--with-compiler",
"--offline",
"--power"
)
.call(cwd = root)
val ideOptionsPath = root / Constants.workspaceDirName / "ide-options-v2.json"
expect(ideOptionsPath.toNIO.toFile.exists())
val ideEnvsPath = root / Constants.workspaceDirName / "ide-envs.json"
expect(ideEnvsPath.toNIO.toFile.exists())
val ideLauncherOptionsPath = root / Constants.workspaceDirName / "ide-launcher-options.json"
expect(ideLauncherOptionsPath.toNIO.toFile.exists())
val jsonOptions = List("--json-options", ideOptionsPath.toString)
val launcherOptions = List("--json-launcher-options", ideLauncherOptionsPath.toString)
val envOptions = List("--envs-file", ideEnvsPath.toString)
val bspOptions = jsonOptions ++ launcherOptions ++ envOptions
withBsp(inputs, Seq("."), bspOptions = bspOptions, reuseRoot = Some(root)) {
(_, _, remoteServer) =>
async {
val targets = await(remoteServer.workspaceBuildTargets().asScala)
.getTargets.asScala
.filter(!_.getId.getUri.contains("-test"))
.map(_.getId())
val compileResult =
await(remoteServer.buildTargetCompile(new b.CompileParams(targets.asJava)).asScala)
expect(compileResult.getStatusCode == b.StatusCode.OK)
val runResult =
await(remoteServer.buildTargetRun(new b.RunParams(targets.head)).asScala)
expect(runResult.getStatusCode == b.StatusCode.OK)
}
}
}
}

private def checkIfBloopProjectIsInitialised(
root: os.Path,
buildTargetsResp: b.WorkspaceBuildTargetsResult
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,95 @@
package scala.cli.integration

class BspTests3NextRc extends BspTestDefinitions with BspTests3Definitions with Test3NextRc
import ch.epfl.scala.bsp4j as b
import com.eed3si9n.expecty.Expecty.expect

import scala.async.Async.{async, await}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.jdk.CollectionConverters.*
import scala.util.Properties

class BspTests3NextRc extends BspTestDefinitions with BspTests3Definitions with Test3NextRc {
test("BSP respects --cli-default-scala-version & --predefined-repository launcher options") {
// 3.5.0-RC1-fakeversion-bin-SNAPSHOT has too long filenames for Windows.
// Yes, seriously. Which is why we can't use it there.
val sv = if (Properties.isWin) Constants.scala3NextRc else "3.5.0-RC1-fakeversion-bin-SNAPSHOT"
val inputs = TestInputs(
os.rel / "simple.sc" -> s"""assert(dotty.tools.dotc.config.Properties.versionNumberString == "$sv")"""
)
inputs.fromRoot { root =>
os.proc(TestUtil.cli, "bloop", "exit", "--power").call(cwd = root)
val localRepoPath = root / "local-repo"
if (Properties.isWin) {
val artifactNames = Seq(
"scala3-compiler_3",
"scala3-staging_3",
"scala3-tasty-inspector_3",
"scala3-sbt-bridge"
)
for { artifactName <- artifactNames } {
val csRes = os.proc(
TestUtil.cs,
"fetch",
"--cache",
localRepoPath,
s"org.scala-lang:$artifactName:$sv"
)
.call(cwd = root)
expect(csRes.exitCode == 0)
}
}
else {
TestUtil.initializeGit(root)
os.proc(
"git",
"clone",
"https://github.com/dotty-staging/maven-test-repo.git",
localRepoPath.toString
).call(cwd = root)
}
val predefinedRepository =
if (Properties.isWin)
(localRepoPath / "https" / "repo1.maven.org" / "maven2").toNIO.toUri.toASCIIString
else
(localRepoPath / "thecache" / "https" / "repo1.maven.org" / "maven2").toNIO.toUri.toASCIIString
os.proc(
TestUtil.cli,
"--cli-default-scala-version",
sv,
"--predefined-repository",
predefinedRepository,
"setup-ide",
"simple.sc",
"--with-compiler",
"--offline",
"--power"
)
.call(cwd = root)
val ideOptionsPath = root / Constants.workspaceDirName / "ide-options-v2.json"
expect(ideOptionsPath.toNIO.toFile.exists())
val ideEnvsPath = root / Constants.workspaceDirName / "ide-envs.json"
expect(ideEnvsPath.toNIO.toFile.exists())
val ideLauncherOptionsPath = root / Constants.workspaceDirName / "ide-launcher-options.json"
expect(ideLauncherOptionsPath.toNIO.toFile.exists())
val jsonOptions = List("--json-options", ideOptionsPath.toString)
val launcherOptions = List("--json-launcher-options", ideLauncherOptionsPath.toString)
val envOptions = List("--envs-file", ideEnvsPath.toString)
val bspOptions = jsonOptions ++ launcherOptions ++ envOptions
withBsp(inputs, Seq("."), bspOptions = bspOptions, reuseRoot = Some(root)) {
(_, _, remoteServer) =>
async {
val targets = await(remoteServer.workspaceBuildTargets().asScala)
.getTargets.asScala
.filter(!_.getId.getUri.contains("-test"))
.map(_.getId())
val compileResult =
await(remoteServer.buildTargetCompile(new b.CompileParams(targets.asJava)).asScala)
expect(compileResult.getStatusCode == b.StatusCode.OK)
val runResult =
await(remoteServer.buildTargetRun(new b.RunParams(targets.head)).asScala)
expect(runResult.getStatusCode == b.StatusCode.OK)
}
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -597,38 +597,59 @@ class SipScalaTests extends ScalaCliSuite with SbtTestHelper with MillTestHelper
for {
withBloop <- Seq(true, false)
withBloopString = if (withBloop) "with Bloop" else "with --server=false"
sv3 = if (Properties.isWin) "3.5.0-RC1" else "3.5.0-RC1-fakeversion-bin-SNAPSHOT"
sv2 = "2.13.15-bin-ccdcde3"
} {
test(
s"default Scala version (3.4.1-RC1) coming straight from a predefined local repository $withBloopString"
s"default Scala version ($sv3) coming straight from a predefined local repository $withBloopString"
) {
TestInputs(
os.rel / "simple.sc" -> "println(dotty.tools.dotc.config.Properties.simpleVersionString)"
os.rel / "simple.sc" -> "println(dotty.tools.dotc.config.Properties.versionNumberString)"
)
.fromRoot { root =>
val localRepoPath = root / "local-repo"
val sv = "3.4.1-RC1"
val artifactNames =
Seq("scala3-compiler_3", "scala3-staging_3", "scala3-tasty-inspector_3") ++
(if (withBloop) Seq("scala3-sbt-bridge") else Nil)
for { artifactName <- artifactNames } {
val csRes = os.proc(
TestUtil.cs,
"fetch",
"--cache",
localRepoPath,
s"org.scala-lang:$artifactName:$sv"
)
.call(cwd = root)
expect(csRes.exitCode == 0)
val sv = sv3
if (Properties.isWin) {
// 3.5.0-RC1-fakeversion-bin-SNAPSHOT has too long filenames for Windows.
// Yes, seriously. Which is why we can't use it there.
val artifactNames =
Seq("scala3-compiler_3", "scala3-staging_3", "scala3-tasty-inspector_3") ++
(if (withBloop) Seq("scala3-sbt-bridge") else Nil)
for { artifactName <- artifactNames } {
val csRes = os.proc(
TestUtil.cs,
"fetch",
"--cache",
localRepoPath,
s"org.scala-lang:$artifactName:$sv"
)
.call(cwd = root)
expect(csRes.exitCode == 0)
}
}
else {
TestUtil.initializeGit(root)
os.proc(
"git",
"clone",
"https://github.com/dotty-staging/maven-test-repo.git",
localRepoPath.toString
).call(cwd = root)
}
val buildServerOptions =
if (withBloop) Nil else Seq("--server=false")

val predefinedRepository =
if (Properties.isWin)
(localRepoPath / "https" / "repo1.maven.org" / "maven2").toNIO.toUri.toASCIIString
else
(localRepoPath / "thecache" / "https" / "repo1.maven.org" / "maven2").toNIO.toUri.toASCIIString
val r = os.proc(
TestUtil.cli,
"--cli-default-scala-version",
sv,
"--predefined-repository",
(localRepoPath / "https" / "repo1.maven.org" / "maven2").toNIO.toUri.toASCIIString,
predefinedRepository,
"run",
"simple.sc",
"--with-compiler",
Expand All @@ -642,14 +663,14 @@ class SipScalaTests extends ScalaCliSuite with SbtTestHelper with MillTestHelper
}

test(
s"default Scala version (2.13.15-bin-ccdcde3) coming straight from a predefined local repository $withBloopString"
s"default Scala version ($sv2) coming straight from a predefined local repository $withBloopString"
) {
TestInputs(
os.rel / "simple.sc" -> "println(scala.util.Properties.versionNumberString)"
)
.fromRoot { root =>
val localRepoPath = root / "local-repo"
val sv = "2.13.15-bin-ccdcde3"
val sv = sv2
val artifactNames =
Seq("scala-compiler") ++ (if (withBloop) Seq("scala2-sbt-bridge") else Nil)
for { artifactName <- artifactNames } {
Expand Down

0 comments on commit 6fefa30

Please sign in to comment.