Skip to content

Commit 9ae6413

Browse files
authored
Merge pull request #2837 from Gedochao/maintenance/bloop-fatal-invariant-fix
Bump `bloop-core` to 1.5.16-sc-2
2 parents 09057a3 + 0657b89 commit 9ae6413

File tree

13 files changed

+239
-279
lines changed

13 files changed

+239
-279
lines changed

modules/integration/src/main/scala/scala/cli/integration/TestInputs.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ final case class TestInputs(maybeCharset: Option[Charset], files: (os.RelPath, S
3434
writeIn(tmpDir)
3535
f(tmpDir)
3636
}
37+
def fileNames: Seq[String] = files.flatMap(_._1.lastOpt)
3738
}
3839

3940
object TestInputs {

modules/integration/src/test/scala/scala/cli/integration/BspTestDefinitions.scala

Lines changed: 30 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@ import scala.jdk.CollectionConverters.*
2222
import scala.util.control.NonFatal
2323
import scala.util.{Failure, Properties, Success, Try}
2424

25-
abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArgs {
25+
abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArgs
26+
with ScriptWrapperTestDefinitions {
2627
_: TestScalaVersion =>
27-
private lazy val extraOptions = scalaVersionArgs ++ TestUtil.extraOptions
28+
protected lazy val extraOptions: Seq[String] = scalaVersionArgs ++ TestUtil.extraOptions
2829

2930
import BspTestDefinitions.*
3031

@@ -61,12 +62,12 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
6162
pool.shutdown()
6263
}
6364

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

69-
private def extractTestTargets(targets: Seq[BuildTargetIdentifier]): BuildTargetIdentifier =
70+
protected def extractTestTargets(targets: Seq[BuildTargetIdentifier]): BuildTargetIdentifier =
7071
targets.collectFirst {
7172
case t if t.getUri.contains("-test") => t
7273
}.get
@@ -78,7 +79,8 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
7879
pauseDuration: FiniteDuration = 5.seconds,
7980
bspOptions: List[String] = List.empty,
8081
reuseRoot: Option[os.Path] = None,
81-
stdErrOpt: Option[os.RelPath] = None
82+
stdErrOpt: Option[os.RelPath] = None,
83+
extraOptionsOverride: Seq[String] = extraOptions
8284
)(
8385
f: (
8486
os.Path,
@@ -93,7 +95,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
9395
val stdErrPathOpt: Option[os.ProcessOutput] = stdErrOpt.map(path => inputsRoot / path)
9496
val stderr: os.ProcessOutput = stdErrPathOpt.getOrElse(os.Inherit)
9597

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

16081610
val scalaDiagnostic = new Gson().fromJson[b.ScalaDiagnostic](
1609-
updateActionableDiagnostic.getData().asInstanceOf[JsonElement],
1611+
updateActionableDiagnostic.getData.asInstanceOf[JsonElement],
16101612
classOf[b.ScalaDiagnostic]
16111613
)
16121614

1613-
val actions = scalaDiagnostic.getActions().asScala.toList
1615+
val actions = scalaDiagnostic.getActions.asScala.toList
16141616
assert(actions.size == 1)
1615-
val changes = actions.head.getEdit().getChanges().asScala.toList
1617+
val changes = actions.head.getEdit.getChanges.asScala.toList
16161618
assert(changes.size == 1)
16171619
val textEdit = changes.head
16181620

1619-
expect(textEdit.getNewText().contains("com.lihaoyi::os-lib:"))
1620-
expect(textEdit.getRange().getStart.getLine == 0)
1621-
expect(textEdit.getRange().getStart.getCharacter == 15)
1622-
expect(textEdit.getRange().getEnd.getLine == 0)
1623-
expect(textEdit.getRange().getEnd.getCharacter == 40)
1621+
expect(textEdit.getNewText.contains("com.lihaoyi::os-lib:"))
1622+
expect(textEdit.getRange.getStart.getLine == 0)
1623+
expect(textEdit.getRange.getStart.getCharacter == 15)
1624+
expect(textEdit.getRange.getEnd.getLine == 0)
1625+
expect(textEdit.getRange.getEnd.getCharacter == 40)
16241626
}
16251627
}
16261628
}
@@ -1653,8 +1655,8 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
16531655
await(remoteServer.buildTargetCompile(new b.CompileParams(targets)).asScala)
16541656

16551657
val visibleDiagnostics =
1656-
localClient.diagnostics().map(_.getDiagnostics().asScala).find(
1657-
!_.isEmpty
1658+
localClient.diagnostics().map(_.getDiagnostics.asScala).find(
1659+
_.nonEmpty
16581660
).getOrElse(
16591661
Nil
16601662
)
@@ -1676,21 +1678,21 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
16761678
)
16771679

16781680
val scalaDiagnostic = new Gson().fromJson[b.ScalaDiagnostic](
1679-
updateActionableDiagnostic.getData().asInstanceOf[JsonElement],
1681+
updateActionableDiagnostic.getData.asInstanceOf[JsonElement],
16801682
classOf[b.ScalaDiagnostic]
16811683
)
16821684

1683-
val actions = scalaDiagnostic.getActions().asScala.toList
1685+
val actions = scalaDiagnostic.getActions.asScala.toList
16841686
assert(actions.size == 1)
1685-
val changes = actions.head.getEdit().getChanges().asScala.toList
1687+
val changes = actions.head.getEdit.getChanges.asScala.toList
16861688
assert(changes.size == 1)
16871689
val textEdit = changes.head
16881690

1689-
expect(textEdit.getNewText().contains("\n case TestB() => ???"))
1690-
expect(textEdit.getRange().getStart.getLine == 7)
1691-
expect(textEdit.getRange().getStart.getCharacter == 19)
1692-
expect(textEdit.getRange().getEnd.getLine == 7)
1693-
expect(textEdit.getRange().getEnd.getCharacter == 19)
1691+
expect(textEdit.getNewText.contains("\n case TestB() => ???"))
1692+
expect(textEdit.getRange.getStart.getLine == 7)
1693+
expect(textEdit.getRange.getStart.getCharacter == 19)
1694+
expect(textEdit.getRange.getEnd.getLine == 7)
1695+
expect(textEdit.getRange.getEnd.getCharacter == 19)
16941696
}
16951697
}
16961698
}
@@ -1938,11 +1940,11 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
19381940
}
19391941

19401942
val diagnostics = diagnosticsParams.flatMap(_.getDiagnostics.asScala)
1941-
.sortBy(_.getRange().getEnd().getCharacter())
1943+
.sortBy(_.getRange.getEnd.getCharacter())
19421944

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

19551957
checkScalaAction(
1956-
diagnostic = diagnostics.apply(0),
1958+
diagnostic = diagnostics.head,
19571959
expectedActionsSize = 1,
19581960
expectedTitle = "Change to: toolkit default",
19591961
expectedChanges = 1,
@@ -2090,7 +2092,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
20902092
expectedEndLine: Int,
20912093
expectedEndCharacter: Int,
20922094
expectedNewText: String
2093-
) = {
2095+
): Unit = {
20942096
expect(diagnostic.getDataKind == "scala")
20952097

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

21312133
object BspTestDefinitions {
2132-
21332134
private final case class Details(
21342135
name: String,
21352136
version: String,
@@ -2138,7 +2139,4 @@ object BspTestDefinitions {
21382139
languages: List[String]
21392140
)
21402141
private val detailsCodec: JsonValueCodec[Details] = JsonCodecMaker.make
2141-
2142-
private final case class TextEdit(range: b.Range, newText: String)
2143-
21442142
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package scala.cli.integration
22

3-
class BspTests212 extends BspTestDefinitions with Test212
3+
class BspTests212 extends BspTestDefinitions with BspTests2Definitions with Test212

modules/integration/src/test/scala/scala/cli/integration/BspTests213.scala

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ import scala.async.Async.{async, await}
88
import scala.concurrent.ExecutionContext.Implicits.global
99
import scala.jdk.CollectionConverters.*
1010

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

3534
val visibleDiagnostics =
36-
localClient.diagnostics().map(_.getDiagnostics().asScala).find(!_.isEmpty).getOrElse(
35+
localClient.diagnostics().map(_.getDiagnostics.asScala).find(_.nonEmpty).getOrElse(
3736
Nil
3837
)
3938

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

5655
val scalaDiagnostic = new Gson().fromJson[b.ScalaDiagnostic](
57-
updateActionableDiagnostic.getData().asInstanceOf[JsonElement],
56+
updateActionableDiagnostic.getData.asInstanceOf[JsonElement],
5857
classOf[b.ScalaDiagnostic]
5958
)
6059

61-
val actions = scalaDiagnostic.getActions().asScala.toList
60+
val actions = scalaDiagnostic.getActions.asScala.toList
6261
assert(actions.size == 1)
63-
val changes = actions.head.getEdit().getChanges().asScala.toList
62+
val changes = actions.head.getEdit.getChanges.asScala.toList
6463
assert(changes.size == 1)
6564
val textEdit = changes.head
6665

67-
expect(textEdit.getNewText().contains("(x: Int)"))
68-
expect(textEdit.getRange().getStart.getLine == 3)
69-
expect(textEdit.getRange().getStart.getCharacter == 4)
70-
expect(textEdit.getRange().getEnd.getLine == 3)
71-
expect(textEdit.getRange().getEnd.getCharacter == 10)
66+
expect(textEdit.getNewText.contains("(x: Int)"))
67+
expect(textEdit.getRange.getStart.getLine == 3)
68+
expect(textEdit.getRange.getStart.getCharacter == 4)
69+
expect(textEdit.getRange.getEnd.getLine == 3)
70+
expect(textEdit.getRange.getEnd.getCharacter == 10)
7271
}
7372
}
7473
}
7574
}
76-
7775
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package scala.cli.integration
2+
3+
import scala.concurrent.ExecutionContext.Implicits.global
4+
5+
trait BspTests2Definitions { _: BspTestDefinitions =>
6+
for {
7+
useDirectives <- Seq(true, false)
8+
(directive, options) <- Seq(
9+
(s"//> using scala $actualScalaVersion", Seq("--scala", actualScalaVersion))
10+
)
11+
extraOptionsOverride =
12+
if (useDirectives) TestUtil.extraOptions else TestUtil.extraOptions ++ options
13+
testNameSuffix = if (useDirectives) directive else options.mkString(" ")
14+
} test(s"BSP App object wrapper forced with $testNameSuffix") {
15+
val (script1, script2) = "script1.sc" -> "script2.sc"
16+
val directiveString = if (useDirectives) directive else ""
17+
val inputs = TestInputs(
18+
os.rel / script1 ->
19+
s"""//> using platform js
20+
|$directiveString
21+
|
22+
|def main(args: String*): Unit = println("Hello")
23+
|main()
24+
|""".stripMargin,
25+
os.rel / script2 ->
26+
"""println("Hello")
27+
|""".stripMargin
28+
)
29+
testScriptWrappers(inputs, extraOptionsOverride = extraOptionsOverride)(expectAppWrapper)
30+
}
31+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package scala.cli.integration
2+
3+
import scala.concurrent.ExecutionContext.Implicits.global
4+
5+
trait BspTests3Definitions { _: BspTestDefinitions =>
6+
test("BSP class wrapper for Scala 3") {
7+
val (script1, script2) = "script1.sc" -> "script2.sc"
8+
val inputs = TestInputs(
9+
os.rel / script1 ->
10+
s"""def main(args: String*): Unit = println("Hello")
11+
|main()
12+
|""".stripMargin,
13+
os.rel / script2 ->
14+
s"""//> using dep "org.scalatest::scalatest:3.2.15"
15+
|
16+
|import org.scalatest.*, flatspec.*, matchers.*
17+
|
18+
|class PiTest extends AnyFlatSpec with should.Matchers {
19+
| "pi calculus" should "return a precise enough pi value" in {
20+
| math.Pi shouldBe 3.14158d +- 0.001d
21+
| }
22+
|}
23+
|org.scalatest.tools.Runner.main(Array("-oDF", "-s", classOf[PiTest].getName))""".stripMargin
24+
)
25+
testScriptWrappers(inputs)(expectClassWrapper)
26+
}
27+
28+
for {
29+
useDirectives <- Seq(true, false)
30+
(directive, options) <- Seq(
31+
("//> using object.wrapper", Seq("--object-wrapper")),
32+
("//> using platform js", Seq("--js"))
33+
)
34+
wrapperOptions = if (useDirectives) Nil else options
35+
testNameSuffix = if (useDirectives) directive else options.mkString(" ")
36+
} test(s"BSP object wrapper forced with $testNameSuffix") {
37+
val (script1, script2) = "script1.sc" -> "script2.sc"
38+
val directiveString = if (useDirectives) directive else ""
39+
val inputs = TestInputs(
40+
os.rel / script1 ->
41+
s"""$directiveString
42+
|
43+
|def main(args: String*): Unit = println("Hello")
44+
|main()
45+
|""".stripMargin,
46+
os.rel / script2 ->
47+
"""println("Hello")
48+
|""".stripMargin
49+
)
50+
testScriptWrappers(inputs, bspOptions = wrapperOptions)(expectObjectWrapper)
51+
}
52+
}
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package scala.cli.integration
22

3-
class BspTests3Lts extends BspTestDefinitions with Test3Lts
3+
class BspTests3Lts extends BspTestDefinitions with BspTests3Definitions with Test3Lts
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package scala.cli.integration
22

3-
class BspTests3NextRc extends BspTestDefinitions with Test3NextRc
3+
class BspTests3NextRc extends BspTestDefinitions with BspTests3Definitions with Test3NextRc
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
package scala.cli.integration
22

3-
class BspTestsDefault extends BspTestDefinitions with TestDefault
3+
class BspTestsDefault extends BspTestDefinitions with BspTests3Definitions with TestDefault

modules/integration/src/test/scala/scala/cli/integration/RunTestDefinitions.scala

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2193,6 +2193,29 @@ abstract class RunTestDefinitions
21932193
}
21942194
}
21952195

2196+
test("running a .scala file several times doesn't produce Bloop errors") {
2197+
val msg = "Hello"
2198+
val input = "Main.scala"
2199+
TestInputs(
2200+
os.rel / input ->
2201+
s"""object Main {
2202+
| def main(args: Array[String]): Unit = {
2203+
| println("$msg")
2204+
| }
2205+
|}
2206+
|""".stripMargin
2207+
).fromRoot { root =>
2208+
// ensure the test will be run on a fresh Bloop instance
2209+
os.proc(TestUtil.cli, "bloop", "exit", "--power").call(cwd = root)
2210+
(0 to 2).foreach { _ =>
2211+
val res = os.proc(TestUtil.cli, "run", input, extraOptions)
2212+
.call(cwd = root, stderr = os.Pipe)
2213+
expect(res.out.trim() == msg)
2214+
expect(!res.err.trim().toLowerCase.contains("error"))
2215+
}
2216+
}
2217+
}
2218+
21962219
test(s"warn about invalid values present in JAVA_OPTS") {
21972220
val expectedOutput = "Hello"
21982221
TestInputs(os.rel / "example.sc" -> s"println(\"$expectedOutput\")")

0 commit comments

Comments
 (0)