Skip to content

Commit

Permalink
Merge pull request #2837 from Gedochao/maintenance/bloop-fatal-invari…
Browse files Browse the repository at this point in the history
…ant-fix

Bump `bloop-core` to 1.5.16-sc-2
  • Loading branch information
Gedochao authored Apr 10, 2024
2 parents 09057a3 + 0657b89 commit 9ae6413
Show file tree
Hide file tree
Showing 13 changed files with 239 additions and 279 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ final case class TestInputs(maybeCharset: Option[Charset], files: (os.RelPath, S
writeIn(tmpDir)
f(tmpDir)
}
def fileNames: Seq[String] = files.flatMap(_._1.lastOpt)
}

object TestInputs {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,10 @@ import scala.jdk.CollectionConverters.*
import scala.util.control.NonFatal
import scala.util.{Failure, Properties, Success, Try}

abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArgs {
abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArgs
with ScriptWrapperTestDefinitions {
_: TestScalaVersion =>
private lazy val extraOptions = scalaVersionArgs ++ TestUtil.extraOptions
protected lazy val extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions

import BspTestDefinitions.*

Expand Down Expand Up @@ -61,12 +62,12 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
pool.shutdown()
}

private def extractMainTargets(targets: Seq[BuildTargetIdentifier]): BuildTargetIdentifier =
protected def extractMainTargets(targets: Seq[BuildTargetIdentifier]): BuildTargetIdentifier =
targets.collectFirst {
case t if !t.getUri.contains("-test") => t
}.get

private def extractTestTargets(targets: Seq[BuildTargetIdentifier]): BuildTargetIdentifier =
protected def extractTestTargets(targets: Seq[BuildTargetIdentifier]): BuildTargetIdentifier =
targets.collectFirst {
case t if t.getUri.contains("-test") => t
}.get
Expand All @@ -78,7 +79,8 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
pauseDuration: FiniteDuration = 5.seconds,
bspOptions: List[String] = List.empty,
reuseRoot: Option[os.Path] = None,
stdErrOpt: Option[os.RelPath] = None
stdErrOpt: Option[os.RelPath] = None,
extraOptionsOverride: Seq[String] = extraOptions
)(
f: (
os.Path,
Expand All @@ -93,7 +95,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
val stdErrPathOpt: Option[os.ProcessOutput] = stdErrOpt.map(path => inputsRoot / path)
val stderr: os.ProcessOutput = stdErrPathOpt.getOrElse(os.Inherit)

val proc = os.proc(TestUtil.cli, "bsp", bspOptions ++ extraOptions, args)
val proc = os.proc(TestUtil.cli, "bsp", bspOptions ++ extraOptionsOverride, args)
.spawn(cwd = root, stderr = stderr)
var remoteServer: b.BuildServer & b.ScalaBuildServer & b.JavaBuildServer & b.JvmBuildServer =
null
Expand Down Expand Up @@ -1606,21 +1608,21 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
)

val scalaDiagnostic = new Gson().fromJson[b.ScalaDiagnostic](
updateActionableDiagnostic.getData().asInstanceOf[JsonElement],
updateActionableDiagnostic.getData.asInstanceOf[JsonElement],
classOf[b.ScalaDiagnostic]
)

val actions = scalaDiagnostic.getActions().asScala.toList
val actions = scalaDiagnostic.getActions.asScala.toList
assert(actions.size == 1)
val changes = actions.head.getEdit().getChanges().asScala.toList
val changes = actions.head.getEdit.getChanges.asScala.toList
assert(changes.size == 1)
val textEdit = changes.head

expect(textEdit.getNewText().contains("com.lihaoyi::os-lib:"))
expect(textEdit.getRange().getStart.getLine == 0)
expect(textEdit.getRange().getStart.getCharacter == 15)
expect(textEdit.getRange().getEnd.getLine == 0)
expect(textEdit.getRange().getEnd.getCharacter == 40)
expect(textEdit.getNewText.contains("com.lihaoyi::os-lib:"))
expect(textEdit.getRange.getStart.getLine == 0)
expect(textEdit.getRange.getStart.getCharacter == 15)
expect(textEdit.getRange.getEnd.getLine == 0)
expect(textEdit.getRange.getEnd.getCharacter == 40)
}
}
}
Expand Down Expand Up @@ -1653,8 +1655,8 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
await(remoteServer.buildTargetCompile(new b.CompileParams(targets)).asScala)

val visibleDiagnostics =
localClient.diagnostics().map(_.getDiagnostics().asScala).find(
!_.isEmpty
localClient.diagnostics().map(_.getDiagnostics.asScala).find(
_.nonEmpty
).getOrElse(
Nil
)
Expand All @@ -1676,21 +1678,21 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
)

val scalaDiagnostic = new Gson().fromJson[b.ScalaDiagnostic](
updateActionableDiagnostic.getData().asInstanceOf[JsonElement],
updateActionableDiagnostic.getData.asInstanceOf[JsonElement],
classOf[b.ScalaDiagnostic]
)

val actions = scalaDiagnostic.getActions().asScala.toList
val actions = scalaDiagnostic.getActions.asScala.toList
assert(actions.size == 1)
val changes = actions.head.getEdit().getChanges().asScala.toList
val changes = actions.head.getEdit.getChanges.asScala.toList
assert(changes.size == 1)
val textEdit = changes.head

expect(textEdit.getNewText().contains("\n case TestB() => ???"))
expect(textEdit.getRange().getStart.getLine == 7)
expect(textEdit.getRange().getStart.getCharacter == 19)
expect(textEdit.getRange().getEnd.getLine == 7)
expect(textEdit.getRange().getEnd.getCharacter == 19)
expect(textEdit.getNewText.contains("\n case TestB() => ???"))
expect(textEdit.getRange.getStart.getLine == 7)
expect(textEdit.getRange.getStart.getCharacter == 19)
expect(textEdit.getRange.getEnd.getLine == 7)
expect(textEdit.getRange.getEnd.getCharacter == 19)
}
}
}
Expand Down Expand Up @@ -1938,11 +1940,11 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
}

val diagnostics = diagnosticsParams.flatMap(_.getDiagnostics.asScala)
.sortBy(_.getRange().getEnd().getCharacter())
.sortBy(_.getRange.getEnd.getCharacter())

{
checkDiagnostic(
diagnostic = diagnostics.apply(0),
diagnostic = diagnostics.head,
expectedMessage =
"Using 'latest' for toolkit is deprecated, use 'default' to get more stable behaviour",
expectedSeverity = b.DiagnosticSeverity.WARNING,
Expand All @@ -1953,7 +1955,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
)

checkScalaAction(
diagnostic = diagnostics.apply(0),
diagnostic = diagnostics.head,
expectedActionsSize = 1,
expectedTitle = "Change to: toolkit default",
expectedChanges = 1,
Expand Down Expand Up @@ -2090,7 +2092,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
expectedEndLine: Int,
expectedEndCharacter: Int,
expectedNewText: String
) = {
): Unit = {
expect(diagnostic.getDataKind == "scala")

val gson = new com.google.gson.Gson()
Expand Down Expand Up @@ -2129,7 +2131,6 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
}

object BspTestDefinitions {

private final case class Details(
name: String,
version: String,
Expand All @@ -2138,7 +2139,4 @@ object BspTestDefinitions {
languages: List[String]
)
private val detailsCodec: JsonValueCodec[Details] = JsonCodecMaker.make

private final case class TextEdit(range: b.Range, newText: String)

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package scala.cli.integration

class BspTests212 extends BspTestDefinitions with Test212
class BspTests212 extends BspTestDefinitions with BspTests2Definitions with Test212
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ import scala.async.Async.{async, await}
import scala.concurrent.ExecutionContext.Implicits.global
import scala.jdk.CollectionConverters.*

class BspTests213 extends BspTestDefinitions with Test213 {

class BspTests213 extends BspTestDefinitions with BspTests2Definitions with Test213 {
List(".sc", ".scala").foreach { filetype =>
test(s"bsp should report actionable diagnostic from bloop for $filetype files (Scala 2.13)") {
val fileName = s"Hello$filetype"
Expand All @@ -33,7 +32,7 @@ class BspTests213 extends BspTestDefinitions with Test213 {
await(remoteServer.buildTargetCompile(new b.CompileParams(targets)).asScala)

val visibleDiagnostics =
localClient.diagnostics().map(_.getDiagnostics().asScala).find(!_.isEmpty).getOrElse(
localClient.diagnostics().map(_.getDiagnostics.asScala).find(_.nonEmpty).getOrElse(
Nil
)

Expand All @@ -54,24 +53,23 @@ class BspTests213 extends BspTestDefinitions with Test213 {
)

val scalaDiagnostic = new Gson().fromJson[b.ScalaDiagnostic](
updateActionableDiagnostic.getData().asInstanceOf[JsonElement],
updateActionableDiagnostic.getData.asInstanceOf[JsonElement],
classOf[b.ScalaDiagnostic]
)

val actions = scalaDiagnostic.getActions().asScala.toList
val actions = scalaDiagnostic.getActions.asScala.toList
assert(actions.size == 1)
val changes = actions.head.getEdit().getChanges().asScala.toList
val changes = actions.head.getEdit.getChanges.asScala.toList
assert(changes.size == 1)
val textEdit = changes.head

expect(textEdit.getNewText().contains("(x: Int)"))
expect(textEdit.getRange().getStart.getLine == 3)
expect(textEdit.getRange().getStart.getCharacter == 4)
expect(textEdit.getRange().getEnd.getLine == 3)
expect(textEdit.getRange().getEnd.getCharacter == 10)
expect(textEdit.getNewText.contains("(x: Int)"))
expect(textEdit.getRange.getStart.getLine == 3)
expect(textEdit.getRange.getStart.getCharacter == 4)
expect(textEdit.getRange.getEnd.getLine == 3)
expect(textEdit.getRange.getEnd.getCharacter == 10)
}
}
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package scala.cli.integration

import scala.concurrent.ExecutionContext.Implicits.global

trait BspTests2Definitions { _: BspTestDefinitions =>
for {
useDirectives <- Seq(true, false)
(directive, options) <- Seq(
(s"//> using scala $actualScalaVersion", Seq("--scala", actualScalaVersion))
)
extraOptionsOverride =
if (useDirectives) TestUtil.extraOptions else TestUtil.extraOptions ++ options
testNameSuffix = if (useDirectives) directive else options.mkString(" ")
} test(s"BSP App object wrapper forced with $testNameSuffix") {
val (script1, script2) = "script1.sc" -> "script2.sc"
val directiveString = if (useDirectives) directive else ""
val inputs = TestInputs(
os.rel / script1 ->
s"""//> using platform js
|$directiveString
|
|def main(args: String*): Unit = println("Hello")
|main()
|""".stripMargin,
os.rel / script2 ->
"""println("Hello")
|""".stripMargin
)
testScriptWrappers(inputs, extraOptionsOverride = extraOptionsOverride)(expectAppWrapper)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package scala.cli.integration

import scala.concurrent.ExecutionContext.Implicits.global

trait BspTests3Definitions { _: BspTestDefinitions =>
test("BSP class wrapper for Scala 3") {
val (script1, script2) = "script1.sc" -> "script2.sc"
val inputs = TestInputs(
os.rel / script1 ->
s"""def main(args: String*): Unit = println("Hello")
|main()
|""".stripMargin,
os.rel / script2 ->
s"""//> using dep "org.scalatest::scalatest:3.2.15"
|
|import org.scalatest.*, flatspec.*, matchers.*
|
|class PiTest extends AnyFlatSpec with should.Matchers {
| "pi calculus" should "return a precise enough pi value" in {
| math.Pi shouldBe 3.14158d +- 0.001d
| }
|}
|org.scalatest.tools.Runner.main(Array("-oDF", "-s", classOf[PiTest].getName))""".stripMargin
)
testScriptWrappers(inputs)(expectClassWrapper)
}

for {
useDirectives <- Seq(true, false)
(directive, options) <- Seq(
("//> using object.wrapper", Seq("--object-wrapper")),
("//> using platform js", Seq("--js"))
)
wrapperOptions = if (useDirectives) Nil else options
testNameSuffix = if (useDirectives) directive else options.mkString(" ")
} test(s"BSP object wrapper forced with $testNameSuffix") {
val (script1, script2) = "script1.sc" -> "script2.sc"
val directiveString = if (useDirectives) directive else ""
val inputs = TestInputs(
os.rel / script1 ->
s"""$directiveString
|
|def main(args: String*): Unit = println("Hello")
|main()
|""".stripMargin,
os.rel / script2 ->
"""println("Hello")
|""".stripMargin
)
testScriptWrappers(inputs, bspOptions = wrapperOptions)(expectObjectWrapper)
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package scala.cli.integration

class BspTests3Lts extends BspTestDefinitions with Test3Lts
class BspTests3Lts extends BspTestDefinitions with BspTests3Definitions with Test3Lts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package scala.cli.integration

class BspTests3NextRc extends BspTestDefinitions with Test3NextRc
class BspTests3NextRc extends BspTestDefinitions with BspTests3Definitions with Test3NextRc
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
package scala.cli.integration

class BspTestsDefault extends BspTestDefinitions with TestDefault
class BspTestsDefault extends BspTestDefinitions with BspTests3Definitions with TestDefault
Original file line number Diff line number Diff line change
Expand Up @@ -2193,6 +2193,29 @@ abstract class RunTestDefinitions
}
}

test("running a .scala file several times doesn't produce Bloop errors") {
val msg = "Hello"
val input = "Main.scala"
TestInputs(
os.rel / input ->
s"""object Main {
| def main(args: Array[String]): Unit = {
| println("$msg")
| }
|}
|""".stripMargin
).fromRoot { root =>
// ensure the test will be run on a fresh Bloop instance
os.proc(TestUtil.cli, "bloop", "exit", "--power").call(cwd = root)
(0 to 2).foreach { _ =>
val res = os.proc(TestUtil.cli, "run", input, extraOptions)
.call(cwd = root, stderr = os.Pipe)
expect(res.out.trim() == msg)
expect(!res.err.trim().toLowerCase.contains("error"))
}
}
}

test(s"warn about invalid values present in JAVA_OPTS") {
val expectedOutput = "Hello"
TestInputs(os.rel / "example.sc" -> s"println(\"$expectedOutput\")")
Expand Down
Loading

0 comments on commit 9ae6413

Please sign in to comment.