-
Notifications
You must be signed in to change notification settings - Fork 328
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test: move cancel compile test to sbt
- Loading branch information
1 parent
c85e193
commit 140ba58
Showing
2 changed files
with
82 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
tests/unit/src/test/scala/tests/CancelCompileSbtLspSuite.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 () | ||
} | ||
} |