Skip to content

Commit cdd3f52

Browse files
committed
NIT refactor using directives usage in integration tests:
- get rid of unnecessary commas and double quote escapes - fix the `publish setup` sub-command to only add double quotes when a value contains whitespace chars - fix the `fix` sub-command to only add double quotes when a value contains whitespace chars
1 parent 2654727 commit cdd3f52

35 files changed

+260
-258
lines changed

modules/cli/src/main/scala/scala/cli/commands/publish/PublishSetup.scala

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,12 +262,15 @@ object PublishSetup extends ScalaCommand[PublishSetupOptions] {
262262

263263
def extraDirectivesLines(extraDirectives: Seq[(String, String)]) =
264264
extraDirectives.map {
265-
case (k, v) =>
266-
s"""//> using $k $v""" + nl
265+
case (k, v) if v.exists(_.isWhitespace) => s"""//> using $k "$v"""" + nl
266+
case (k, v) => s"""//> using $k $v""" + nl
267267
}.mkString
268268

269269
val extraLines = missingFieldsWithDefaultsAndValues.map {
270270
case (_, default, None) => extraDirectivesLines(default.extraDirectives)
271+
case (check, default, Some(value)) if value.exists(_.isWhitespace) =>
272+
s"""//> using ${check.directivePath} "$value"""" + nl +
273+
extraDirectivesLines(default.extraDirectives)
271274
case (check, default, Some(value)) =>
272275
s"""//> using ${check.directivePath} $value""" + nl +
273276
extraDirectivesLines(default.extraDirectives)

modules/directives/src/main/scala/scala/build/preprocessing/directives/StrictDirective.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package scala.build.preprocessing.directives
22

3-
import com.virtuslab.using_directives.custom.model.{EmptyValue, StringValue, Value}
3+
import com.virtuslab.using_directives.custom.model.{EmptyValue, Value}
44

55
import scala.build.Position
66

@@ -16,11 +16,11 @@ import scala.build.Position
1616

1717
case class StrictDirective(
1818
key: String,
19-
values: Seq[Value[_]],
19+
values: Seq[Value[?]],
2020
startColumn: Int = 0
2121
) {
2222
override def toString: String = {
23-
val suffix = if validValues.isEmpty then "" else s" \"${validValues.mkString("\", \"")}\""
23+
val suffix = if validValues.isEmpty then "" else s" ${validValues.mkString(" ")}"
2424
s"//> using $key$suffix"
2525
}
2626

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class BloopTests extends ScalaCliSuite {
1515

1616
val dummyInputs: TestInputs = TestInputs(
1717
os.rel / "Test.scala" ->
18-
"""//> using scala "2.13"
18+
"""//> using scala 2.13
1919
|object Test {
2020
| def main(args: Array[String]): Unit =
2121
| println("Hello " + "from test")

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

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
383383
test("invalid diagnostics at startup") {
384384
val inputs = TestInputs(
385385
os.rel / "A.scala" ->
386-
s"""//> using resource "./resources"
386+
s"""//> using resource ./resources
387387
|
388388
|object A {}
389389
|""".stripMargin
@@ -402,9 +402,9 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
402402
expectedMessage = "Unrecognized directive: resource with values: ./resources",
403403
expectedSeverity = b.DiagnosticSeverity.ERROR,
404404
expectedStartLine = 0,
405-
expectedStartCharacter = 20,
405+
expectedStartCharacter = 19,
406406
expectedEndLine = 0,
407-
expectedEndCharacter = 31,
407+
expectedEndCharacter = 30,
408408
strictlyCheckMessage = false
409409
)
410410
}
@@ -414,7 +414,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
414414
test("directive diagnostics") {
415415
val inputs = TestInputs(
416416
os.rel / "Test.scala" ->
417-
s"""//> using dep "com.lihaoyi::pprint:0.0.0.0.0.1"
417+
s"""//> using dep com.lihaoyi::pprint:0.0.0.0.0.1
418418
|
419419
|object Test {
420420
| val msg = "Hello"
@@ -442,9 +442,9 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
442442
expectedMessage = expectedMessage,
443443
expectedSeverity = b.DiagnosticSeverity.ERROR,
444444
expectedStartLine = 0,
445-
expectedStartCharacter = 15,
445+
expectedStartCharacter = 14,
446446
expectedEndLine = 0,
447-
expectedEndCharacter = 46,
447+
expectedEndCharacter = 45,
448448
strictlyCheckMessage = false
449449
)
450450
}
@@ -454,14 +454,14 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
454454
test("directives in multiple files diagnostics") {
455455
val inputs = TestInputs(
456456
os.rel / "Foo.scala" ->
457-
s"""//> using scala "3.3.0"
457+
s"""//> using scala 3.3.0
458458
|
459459
|object Foo extends App {
460460
| println("Foo")
461461
|}
462462
|""".stripMargin,
463463
os.rel / "Bar.scala" -> "",
464-
os.rel / "Hello.java" -> "//> using jvm \"11\""
464+
os.rel / "Hello.java" -> "//> using jvm 11"
465465
)
466466

467467
withBsp(inputs, Seq(".")) { (root, localClient, remoteServer) =>
@@ -516,8 +516,8 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
516516
)
517517
}
518518

519-
checkDirectivesInMultipleFilesWarnings("Foo.scala", 0, 0, 0, 23)
520-
checkDirectivesInMultipleFilesWarnings("Hello.java", 0, 0, 0, 18)
519+
checkDirectivesInMultipleFilesWarnings("Foo.scala", 0, 0, 0, 21)
520+
checkDirectivesInMultipleFilesWarnings("Hello.java", 0, 0, 0, 16)
521521
}
522522
}
523523
}
@@ -581,7 +581,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
581581

582582
val didChangeParamsFuture = localClient.buildTargetDidChange()
583583
val updatedContent =
584-
"""//> using dep "com.lihaoyi::pprint:0.6.6"
584+
"""//> using dep com.lihaoyi::pprint:0.6.6
585585
|val msg = "Hello"
586586
|pprint.log(msg)
587587
|""".stripMargin
@@ -729,13 +729,13 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
729729
test("test workspace update after adding file to main scope") {
730730
val inputs = TestInputs(
731731
os.rel / "Messages.scala" ->
732-
"""//> using dep "com.lihaoyi::os-lib:0.7.8"
732+
"""//> using dep com.lihaoyi::os-lib:0.7.8
733733
|object Messages {
734734
| def msg = "Hello"
735735
|}
736736
|""".stripMargin,
737737
os.rel / "MyTests.test.scala" ->
738-
"""//> using dep "com.lihaoyi::utest::0.7.10"
738+
"""//> using dep com.lihaoyi::utest::0.7.10
739739
|import utest._
740740
|
741741
|object MyTests extends TestSuite {
@@ -950,7 +950,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
950950
val depName = "os-lib"
951951
val depVersion = "0.8.1"
952952
val updatedSourceFile =
953-
s"""//> using dep "com.lihaoyi::$depName:$depVersion"
953+
s"""//> using dep com.lihaoyi::$depName:$depVersion
954954
|
955955
|object ReloadTest {
956956
| println(os.pwd)
@@ -1058,7 +1058,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
10581058
val utilsFileName = "Utils.scala"
10591059
val inputs = TestInputs(
10601060
os.rel / "Hello.scala" ->
1061-
s"""|//> using file "Utils.scala"
1061+
s"""|//> using file Utils.scala
10621062
|
10631063
|object Hello extends App {
10641064
| println("Hello World")
@@ -1350,7 +1350,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
13501350
val directiveValue = "value"
13511351
val inputs = TestInputs(
13521352
os.rel / sourceFileName ->
1353-
s"""//> using $directiveKey "$directiveValue"
1353+
s"""//> using $directiveKey $directiveValue
13541354
|
13551355
|object UnrecognisedUsingDirective extends App {
13561356
| println("Hello")
@@ -1374,9 +1374,9 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
13741374
s"Unrecognized directive: $directiveKey with values: $directiveValue",
13751375
expectedSeverity = b.DiagnosticSeverity.ERROR,
13761376
expectedStartLine = 0,
1377-
expectedStartCharacter = 34,
1377+
expectedStartCharacter = 33,
13781378
expectedEndLine = 0,
1379-
expectedEndCharacter = 39
1379+
expectedEndCharacter = 38
13801380
)
13811381
}
13821382
}
@@ -1385,7 +1385,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
13851385
test("bloop projects are initialised properly for a directive for an unfetchable dependency") {
13861386
val inputs = TestInputs(
13871387
os.rel / "InvalidUsingDirective.scala" ->
1388-
s"""//> using dep "no::lib:123"
1388+
s"""//> using dep no::lib:123
13891389
|
13901390
|object InvalidUsingDirective extends App {
13911391
| println("Hello")
@@ -1408,9 +1408,9 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
14081408
expectedMessage = "Error downloading no:lib",
14091409
expectedSeverity = b.DiagnosticSeverity.ERROR,
14101410
expectedStartLine = 0,
1411-
expectedStartCharacter = 15,
1411+
expectedStartCharacter = 14,
14121412
expectedEndLine = 0,
1413-
expectedEndCharacter = 26,
1413+
expectedEndCharacter = 25,
14141414
strictlyCheckMessage = false
14151415
)
14161416
}
@@ -1458,7 +1458,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
14581458
val fileName = "Hello.scala"
14591459
val inputs = TestInputs(
14601460
os.rel / fileName ->
1461-
s"""//> using dep "com.lihaoyi::os-lib:0.7.8"
1461+
s"""//> using dep com.lihaoyi::os-lib:0.7.8
14621462
|
14631463
|object Hello extends App {
14641464
| println("Hello")
@@ -1486,9 +1486,9 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
14861486
expectedMessage = "os-lib is outdated",
14871487
expectedSeverity = b.DiagnosticSeverity.HINT,
14881488
expectedStartLine = 0,
1489-
expectedStartCharacter = 15,
1489+
expectedStartCharacter = 14,
14901490
expectedEndLine = 0,
1491-
expectedEndCharacter = 40,
1491+
expectedEndCharacter = 39,
14921492
expectedSource = Some("scala-cli"),
14931493
strictlyCheckMessage = false
14941494
)
@@ -1506,9 +1506,9 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
15061506

15071507
expect(textEdit.getNewText.contains("com.lihaoyi::os-lib:"))
15081508
expect(textEdit.getRange.getStart.getLine == 0)
1509-
expect(textEdit.getRange.getStart.getCharacter == 15)
1509+
expect(textEdit.getRange.getStart.getCharacter == 14)
15101510
expect(textEdit.getRange.getEnd.getLine == 0)
1511-
expect(textEdit.getRange.getEnd.getCharacter == 40)
1511+
expect(textEdit.getRange.getEnd.getCharacter == 39)
15121512
}
15131513
}
15141514
}
@@ -1586,7 +1586,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
15861586
test("bsp should support jvmRunEnvironment request") {
15871587
val inputs = TestInputs(
15881588
os.rel / "Hello.scala" ->
1589-
s"""//> using dep "com.lihaoyi::os-lib:0.7.8"
1589+
s"""//> using dep com.lihaoyi::os-lib:0.7.8
15901590
|
15911591
|object Hello extends App {
15921592
| println("Hello")
@@ -1781,7 +1781,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
17811781
val inputs = TestInputs(
17821782
os.rel / "test.sc" ->
17831783
"""//> using toolkit latest
1784-
|//> using test.toolkit "typelevel:latest"
1784+
|//> using test.toolkit typelevel:latest
17851785
|
17861786
|//> using lib org.typelevel::cats-core:2.6.1
17871787
|
@@ -1862,7 +1862,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
18621862
expectedStartLine = 1,
18631863
expectedStartCharacter = 10,
18641864
expectedEndLine = 1,
1865-
expectedEndCharacter = 41
1865+
expectedEndCharacter = 39
18661866
)
18671867

18681868
checkScalaAction(
@@ -1873,7 +1873,7 @@ abstract class BspTestDefinitions extends ScalaCliSuite with TestScalaVersionArg
18731873
expectedStartLine = 1,
18741874
expectedStartCharacter = 10,
18751875
expectedEndLine = 1,
1876-
expectedEndCharacter = 41,
1876+
expectedEndCharacter = 39,
18771877
expectedNewText = "test.toolkit typelevel:default"
18781878
)
18791879
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ trait BspTests3Definitions { _: BspTestDefinitions =>
1111
|main()
1212
|""".stripMargin,
1313
os.rel / script2 ->
14-
s"""//> using dep "org.scalatest::scalatest:3.2.15"
14+
s"""//> using dep org.scalatest::scalatest:3.2.15
1515
|
1616
|import org.scalatest.*, flatspec.*, matchers.*
1717
|

0 commit comments

Comments
 (0)