Skip to content

Commit

Permalink
test: move cancel compile test to sbt
Browse files Browse the repository at this point in the history
  • Loading branch information
kasiaMarek committed Oct 3, 2023
1 parent c85e193 commit 140ba58
Show file tree
Hide file tree
Showing 2 changed files with 82 additions and 1 deletion.
3 changes: 2 additions & 1 deletion tests/unit/src/test/scala/tests/CancelCompileLspSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import ch.epfl.scala.bsp4j.StatusCode

class CancelCompileLspSuite extends BaseLspSuite("compile-cancel") {

test("basic") {
// Ignore for now due to an error in Bloop: https://github.com/scalacenter/bloop/issues/2170
test("basic".ignore) {
cleanWorkspace()
for {
_ <- initialize(
Expand Down
80 changes: 80 additions & 0 deletions tests/unit/src/test/scala/tests/CancelCompileSbtLspSuite.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package tests

import scala.meta.internal.metals.ServerCommands
import scala.meta.internal.metals.{BuildInfo => V}

import ch.epfl.scala.bsp4j.StatusCode

class CancelCompileSbtLspSuite
extends BaseLspSuite("compile-cancel-sbt", SbtServerInitializer) {

test("basic") {
cleanWorkspace()
for {
_ <- initialize(
s"""
|/project/build.properties
|sbt.version=${V.sbtVersion}
|/build.sbt
|${SbtBuildLayout.commonSbtSettings}
|ThisBuild / scalaVersion := "${BuildInfo.scalaVersion}"
|val a = project.in(file("a")).settings(
| libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value
| )
|val b = project.in(file("b")).dependsOn(a)
|val c = project.in(file("c")).dependsOn(b)
|/a/src/main/scala/a/A.scala
|package a
|
|import scala.reflect.macros.blackbox.Context
|import scala.language.experimental.macros
|
|object A {
| val x = 123
| def sleep(): Unit = macro sleepImpl
| def sleepImpl(c: Context)(): c.Expr[Unit] = {
| import c.universe._
| // Sleep for 3 seconds
| Thread.sleep(3000)
| reify { () }
| }
|}
|
|/b/src/main/scala/b/B.scala
|package b
|object B {
| a.A.sleep()
| val x = a.A.x
|}
|/c/src/main/scala/c/C.scala
|package c
|object C { val x: String = b.B.x }
|""".stripMargin
)
_ <- server.server.buildServerPromise.future
(compileReport, _) <- server.server.compilations
.compileFile(
workspace.resolve("c/src/main/scala/c/C.scala")
)
.zip {
// wait until the compilation start
Thread.sleep(1000)
server.executeCommand(ServerCommands.CancelCompile)
}
_ = assertNoDiff(client.workspaceDiagnostics, "")
_ = assertEquals(compileReport.getStatusCode(), StatusCode.CANCELLED)
_ <- server.server.compilations.compileFile(
workspace.resolve("c/src/main/scala/c/C.scala")
)
_ = assertNoDiff(
client.workspaceDiagnostics,
"""|c/src/main/scala/c/C.scala:2:28: error: type mismatch;
| found : Int
| required: String
|object C { val x: String = b.B.x }
| ^^^^^
|""".stripMargin,
)
} yield ()
}
}

0 comments on commit 140ba58

Please sign in to comment.