Skip to content

Commit

Permalink
chore: Add tests for Bazel 7
Browse files Browse the repository at this point in the history
  • Loading branch information
tgodzik committed Aug 29, 2024
1 parent 8e02ab8 commit 7deb099
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package scala.meta.internal.builds

import scala.meta.internal.metals.BuildInfo
import scala.meta.internal.metals.JavaBinary
import scala.meta.internal.metals.MetalsEnrichments._
import scala.meta.internal.metals.UserConfiguration
import scala.meta.io.AbsolutePath

import coursierapi.Dependency
import coursierapi.Fetch
import scala.meta.internal.metals.BuildInfo

case class BazelBuildTool(
userConfig: () => UserConfiguration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -261,11 +261,11 @@ final class Compilations(
val originId = "METALS-$" + UUID.randomUUID().toString
val params = new b.CompileParams(targets.asJava)
params.setOriginId(originId)
if (
userConfiguration().verboseCompilation && (connection.isBloop || connection.isScalaCLI)
) {
params.setArguments(List("--verbose", "--best-effort").asJava)
} else { params.setArguments(List("--best-effort").asJava) }
if (connection.isBloop || connection.isScalaCLI) {
if (userConfiguration().verboseCompilation)
params.setArguments(List("--verbose", "--best-effort").asJava)
else params.setArguments(List("--best-effort").asJava)
}
targets.foreach { target =>
isCompiling(target) = true
}
Expand Down
99 changes: 51 additions & 48 deletions tests/slow/src/test/scala/tests/bazel/BazelLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class BazelLspSuite
val buildTool: BazelBuildTool = BazelBuildTool(() => userConfig, workspace)

val bazelVersion = "6.4.0"
val bazel7Version = "7.3.0"

def bazelBspConfig: AbsolutePath = workspace.resolve(".bsp/bazelbsp.json")

Expand All @@ -38,55 +39,57 @@ class BazelLspSuite
val importMessage: String =
GenerateBspAndConnect.params("bazel", "bazelbsp").getMessage()

test("basic") {
cleanWorkspace()
for {
_ <- initialize(
BazelBuildLayout(workspaceLayout, V.bazelScalaVersion, bazelVersion)
)
_ = assertNoDiff(
client.workspaceMessageRequests,
List(
importMessage
).mkString("\n"),
)
_ = assert(bazelBspConfig.exists)
_ = client.messageRequests.clear() // restart
_ = assertStatus(_.isInstalled)
_ = assertNoDiff(client.workspaceDiagnostics, "")
_ <- server.didChange("WORKSPACE")(_ + "\n# comment")
_ <- server.didSave("WORKSPACE")(identity)
// Comment changes do not trigger "re-import project" request
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ <- server.didChange("Hello.scala") { text =>
text.replace("def hello: String", "def hello: Int")
}
_ <- server.didSave("Hello.scala")(identity)
_ = assertNoDiff(
client.workspaceDiagnostics,
"""|Hello.scala:4:20: error: type mismatch;
| found : String("Hello")
| required: Int
| def hello: Int = "Hello"
| ^
| def hello: Int = "Hello"
| ^
|""".stripMargin,
)
_ <- server.didChange(s"BUILD") { text =>
text.replace("\"hello\"", "\"hello1\"")
for (bazelVersion <- List(bazelVersion, bazel7Version)) {
test(s"basic-$bazelVersion") {
cleanWorkspace()
for {
_ <- initialize(
BazelBuildLayout(workspaceLayout, V.bazelScalaVersion, bazelVersion)
)
_ = assertNoDiff(
client.workspaceMessageRequests,
List(
importMessage
).mkString("\n"),
)
_ = assert(bazelBspConfig.exists)
_ = client.messageRequests.clear() // restart
_ = assertStatus(_.isInstalled)
_ = assertNoDiff(client.workspaceDiagnostics, "")
_ <- server.didChange("WORKSPACE")(_ + "\n# comment")
_ <- server.didSave("WORKSPACE")(identity)
// Comment changes do not trigger "re-import project" request
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ <- server.didChange("Hello.scala") { text =>
text.replace("def hello: String", "def hello: Int")
}
_ <- server.didSave("Hello.scala")(identity)
_ = assertNoDiff(
client.workspaceDiagnostics,
"""|Hello.scala:4:20: error: type mismatch;
| found : String("Hello")
| required: Int
| def hello: Int = "Hello"
| ^
| def hello: Int = "Hello"
| ^
|""".stripMargin,
)
_ <- server.didChange(s"BUILD") { text =>
text.replace("\"hello\"", "\"hello1\"")
}
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ = client.generateBspAndConnect = GenerateBspAndConnect.yes
_ <- server.didSave(s"BUILD")(identity)
} yield {
assertNoDiff(
client.workspaceMessageRequests,
List(
importBuildChangesMessage
).mkString("\n"),
)
server.assertBuildServerConnection()
}
_ = assertNoDiff(client.workspaceMessageRequests, "")
_ = client.generateBspAndConnect = GenerateBspAndConnect.yes
_ <- server.didSave(s"BUILD")(identity)
} yield {
assertNoDiff(
client.workspaceMessageRequests,
List(
importBuildChangesMessage
).mkString("\n"),
)
server.assertBuildServerConnection()
}
}

Expand Down

0 comments on commit 7deb099

Please sign in to comment.