Skip to content

Commit

Permalink
NIT refactor using directives usage in unit tests: get rid of unneces…
Browse files Browse the repository at this point in the history
…sary commas and double quote escapes
  • Loading branch information
Gedochao committed Dec 4, 2024
1 parent cdd3f52 commit 21ff792
Show file tree
Hide file tree
Showing 12 changed files with 126 additions and 126 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class ActionableDiagnosticTests extends TestUtil.ScalaCliBuildSuite {
val testInputs = TestInputs(
os.rel / "Foo.scala" ->
s"""//> using dep $dependencyOsLib
|//> using dep "$dependencyPprintLib"
|//> using dep $dependencyPprintLib
|
|object Hello extends App {
| println("Hello")
Expand All @@ -79,7 +79,7 @@ class ActionableDiagnosticTests extends TestUtil.ScalaCliBuildSuite {
actionableDiagnostics.find(_.suggestion.startsWith("com.lihaoyi::pprint")).get

expect(osLib.positions == Seq(File(Right(root / "Foo.scala"), (0, 14), (0, 39))))
expect(pprintLib.positions == Seq(File(Right(root / "Foo.scala"), (1, 15), (1, 40))))
expect(pprintLib.positions == Seq(File(Right(root / "Foo.scala"), (1, 14), (1, 39))))
}
}

Expand Down
28 changes: 14 additions & 14 deletions modules/build/src/test/scala/scala/build/tests/BuildTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ abstract class BuildTests(server: Boolean) extends TestUtil.ScalaCliBuildSuite {
|pprint.log(g)
|""".stripMargin,
os.rel / "simple2.sc" ->
"""//> using dep com.lihaoyi::geny:0.6.5, "com.lihaoyi::pprint:0.6.6"
"""//> using dep com.lihaoyi::geny:0.6.5 com.lihaoyi::pprint:0.6.6
|import geny.Generator
|val g = Generator("Hel", "lo")
|pprint.log(g)
Expand Down Expand Up @@ -422,7 +422,7 @@ abstract class BuildTests(server: Boolean) extends TestUtil.ScalaCliBuildSuite {
|}
|""".stripMargin,
os.rel / "Ignored.scala" ->
"""//> using target.scala.== "2.12"
"""//> using target.scala.== 2.12
|object Ignored {
| def foo = 2
|}
Expand Down Expand Up @@ -702,16 +702,16 @@ abstract class BuildTests(server: Boolean) extends TestUtil.ScalaCliBuildSuite {
test("repeated Java options") {
val inputs = TestInputs(
os.rel / "foo.sc" ->
"""//> using javaOpt --add-opens, "foo/bar"
|//> using javaOpt --add-opens, "other/thing"
|//> using javaOpt --add-exports, "foo/bar"
|//> using javaOpt --add-exports, "other/thing"
|//> using javaOpt --add-modules, "foo/bar"
|//> using javaOpt --add-modules, other/thing
|//> using javaOpt --add-reads, "foo/bar"
|//> using javaOpt --add-reads, "other/thing"
|//> using javaOpt "--patch-module", "foo/bar"
|//> using javaOpt "--patch-module", "other/thing"
"""//> using javaOpt --add-opens foo/bar
|//> using javaOpt --add-opens other/thing
|//> using javaOpt --add-exports foo/bar
|//> using javaOpt --add-exports other/thing
|//> using javaOpt --add-modules foo/bar
|//> using javaOpt --add-modules other/thing
|//> using javaOpt --add-reads foo/bar
|//> using javaOpt --add-reads other/thing
|//> using javaOpt --patch-module foo/bar
|//> using javaOpt --patch-module other/thing
|
|def foo = "bar"
|""".stripMargin
Expand Down Expand Up @@ -743,7 +743,7 @@ abstract class BuildTests(server: Boolean) extends TestUtil.ScalaCliBuildSuite {
test("-source:future not internally duplicating") {
val inputs = TestInputs(
os.rel / "foo.scala" ->
"""//> using option "-source:future"
"""//> using option -source:future
|def foo = "bar"
|""".stripMargin
)
Expand All @@ -762,7 +762,7 @@ abstract class BuildTests(server: Boolean) extends TestUtil.ScalaCliBuildSuite {
val inputs = TestInputs(
os.rel / "foo.scala" ->
"""//> using scala 2.13
|//> using options -deprecation, "-feature", "-Xmaxwarns", "1"
|//> using options -deprecation -feature -Xmaxwarns 1
|//> using option -Xdisable-assertions
|
|def foo = "bar"
Expand Down
52 changes: 26 additions & 26 deletions modules/build/src/test/scala/scala/build/tests/DirectiveTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ class DirectiveTests extends TestUtil.ScalaCliBuildSuite {
)
)

test("resolving position of lib directive") {
test("resolving position of dep directive") {
val testInputs = TestInputs(
os.rel / "simple.sc" ->
"""//> using dep "com.lihaoyi::utest:0.7.10"
"""//> using dep com.lihaoyi::utest:0.7.10
|""".stripMargin
)
testInputs.withBuild(baseOptions, buildThreads, bloopConfigOpt) {
Expand All @@ -64,15 +64,15 @@ class DirectiveTests extends TestUtil.ScalaCliBuildSuite {
case _ => sys.error("cannot happen")
}

expect(startPos == (0, 15))
expect(endPos == (0, 40))
expect(startPos == (0, 14))
expect(endPos == (0, 39))
}
}

test("should parse javac options") {
val testInputs = TestInputs(
os.rel / "simple.sc" ->
"""//> using javacOpt "source", "1.8", "target", "1.8"
"""//> using javacOpt source 1.8 target 1.8
|""".stripMargin
)
testInputs.withBuild(baseOptions, buildThreads, bloopConfigOpt) {
Expand All @@ -90,7 +90,7 @@ class DirectiveTests extends TestUtil.ScalaCliBuildSuite {
Seq("--no-fallback", "--enable-url-protocols=http,https")
TestInputs(
os.rel / "simple.sc" ->
s"""//> using packaging.graalvmArgs "$noFallback", "$enableUrl"
s"""//> using packaging.graalvmArgs $noFallback $enableUrl
|""".stripMargin
).withBuild(baseOptions, buildThreads, bloopConfigOpt) {
(_, _, maybeBuild) =>
Expand Down Expand Up @@ -155,8 +155,8 @@ class DirectiveTests extends TestUtil.ScalaCliBuildSuite {
}

test(s"resolve test scope dependencies correctly when building for ${scope.name} scope") {
withProjectFile(projectFileContent = """//> using dep "com.lihaoyi::os-lib:0.9.1"
|//> using test.dep "org.scalameta::munit::0.7.29"
withProjectFile(projectFileContent = """//> using dep com.lihaoyi::os-lib:0.9.1
|//> using test.dep org.scalameta::munit::0.7.29
|""".stripMargin) { (build, isTestScope) =>
val deps = build.options.classPathOptions.extraDependencies.toSeq.map(_.value)
expect(deps.nonEmpty)
Expand All @@ -172,9 +172,9 @@ class DirectiveTests extends TestUtil.ScalaCliBuildSuite {
}
test(s"resolve test scope javacOpts correctly when building for ${scope.name} scope") {
withProjectFile(projectFileContent =
"""//> using javacOpt "source", "1.8"
|//> using test.javacOpt "target", "1.8"
|//> using test.dep "org.scalameta::munit::0.7.29"
"""//> using javacOpt source 1.8
|//> using test.javacOpt target 1.8
|//> using test.dep org.scalameta::munit::0.7.29
|""".stripMargin
) { (build, isTestScope) =>
val javacOpts = build.options.javaOptions.javacOptions.map(_.value)
Expand All @@ -185,9 +185,9 @@ class DirectiveTests extends TestUtil.ScalaCliBuildSuite {
}
test(s"resolve test scope scalac opts correctly when building for ${scope.name} scope") {
withProjectFile(projectFileContent =
"""//> using option "--explain"
|//> using test.option "-deprecation"
|//> using test.dep "org.scalameta::munit::0.7.29"
"""//> using option --explain
|//> using test.option -deprecation
|//> using test.dep org.scalameta::munit::0.7.29
|""".stripMargin
) { (build, isTestScope) =>
val scalacOpts = build.options.scalaOptions.scalacOptions.toSeq.map(_.value.value)
Expand All @@ -198,9 +198,9 @@ class DirectiveTests extends TestUtil.ScalaCliBuildSuite {
}
test(s"resolve test scope javaOpts correctly when building for ${scope.name} scope") {
withProjectFile(projectFileContent =
"""//> using javaOpt "-Xmx2g"
|//> using test.javaOpt "-Dsomething=a"
|//> using test.dep "org.scalameta::munit::0.7.29"
"""//> using javaOpt -Xmx2g
|//> using test.javaOpt -Dsomething=a
|//> using test.dep org.scalameta::munit::0.7.29
|""".stripMargin
) { (build, isTestScope) =>
val javaOpts = build.options.javaOptions.javaOpts.toSeq.map(_.value.value)
Expand All @@ -211,9 +211,9 @@ class DirectiveTests extends TestUtil.ScalaCliBuildSuite {
}
test(s"resolve test scope javaProps correctly when building for ${scope.name} scope") {
withProjectFile(projectFileContent =
"""//> using javaProp "foo=1"
|//> using test.javaProp "bar=2"
|//> using test.dep "org.scalameta::munit::0.7.29"
"""//> using javaProp foo=1
|//> using test.javaProp bar=2
|//> using test.dep org.scalameta::munit::0.7.29
|""".stripMargin
) { (build, isTestScope) =>
val javaProps = build.options.javaOptions.javaOpts.toSeq.map(_.value.value)
Expand All @@ -224,9 +224,9 @@ class DirectiveTests extends TestUtil.ScalaCliBuildSuite {
}
test(s"resolve test scope resourceDir correctly when building for ${scope.name} scope") {
withProjectFile(projectFileContent =
"""//> using resourceDir "./mainResources"
|//> using test.resourceDir "./testResources"
|//> using test.dep "org.scalameta::munit::0.7.29"
"""//> using resourceDir ./mainResources
|//> using test.resourceDir ./testResources
|//> using test.dep org.scalameta::munit::0.7.29
|""".stripMargin
) { (build, isTestScope) =>
val resourcesDirs = build.options.classPathOptions.resourcesDir
Expand Down Expand Up @@ -265,7 +265,7 @@ class DirectiveTests extends TestUtil.ScalaCliBuildSuite {
val filePath = os.rel / "src" / "simple.scala"
val testInputs = TestInputs(
os.rel / filePath ->
"""//> using options "-coverage-out:${.}""""
"""//> using options -coverage-out:${.}"""
)
testInputs.withBuild(baseOptions, buildThreads, bloopConfigOpt) {
(root, _, maybeBuild) =>
Expand All @@ -284,7 +284,7 @@ class DirectiveTests extends TestUtil.ScalaCliBuildSuite {
val filePath = os.rel / "src" / "simple.scala"
val testInputs = TestInputs(
os.rel / filePath ->
"""//> using options "-coverage-out:$$${.}""""
"""//> using options -coverage-out:$$${.}"""
)
testInputs.withBuild(baseOptions, buildThreads, bloopConfigOpt) {
(root, _, maybeBuild) =>
Expand All @@ -303,7 +303,7 @@ class DirectiveTests extends TestUtil.ScalaCliBuildSuite {
val filePath = os.rel / "src" / "simple.scala"
val testInputs = TestInputs(
os.rel / filePath ->
"""//> using options "-coverage-out:$${.}""""
"""//> using options -coverage-out:$${.}"""
)
testInputs.withBuild(baseOptions, buildThreads, bloopConfigOpt) {
(_, _, maybeBuild) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,10 @@ class ExcludeTests extends TestUtil.ScalaCliBuildSuite {
test("throw error when exclude found in multiple files") {
val testInputs = TestInputs(
os.rel / "Hello.scala" ->
"""//> using exclude "*.sc"
"""//> using exclude *.sc
|""".stripMargin,
os.rel / "Main.scala" ->
"""//> using exclude "*/test/*"
"""//> using exclude */test/*
|""".stripMargin
)
testInputs.withInputs { (_, inputs) =>
Expand All @@ -57,10 +57,10 @@ class ExcludeTests extends TestUtil.ScalaCliBuildSuite {
test("throw error when exclude found in non top-level project.scala and file") {
val testInputs = TestInputs(
os.rel / "Main.scala" ->
"""//> using exclude "*/test/*"
"""//> using exclude */test/*
|""".stripMargin,
os.rel / "src" / "project.scala" ->
s"""//> using exclude "*.sc" """
s"""//> using exclude *.sc"""
)
testInputs.withInputs { (_, inputs) =>
val crossSources =
Expand All @@ -84,7 +84,7 @@ class ExcludeTests extends TestUtil.ScalaCliBuildSuite {
"""object Main {
|}""".stripMargin,
os.rel / "project.scala" ->
s"""//> using exclude "Main.scala" """
s"""//> using exclude Main.scala"""
)
testInputs.withInputs { (root, inputs) =>
val (crossSources, _) =
Expand Down Expand Up @@ -118,7 +118,7 @@ class ExcludeTests extends TestUtil.ScalaCliBuildSuite {
"""object Main {
|}""".stripMargin,
os.rel / "project.scala" ->
s"""//> using exclude "$${.}${File.separator}Main.scala" """
s"""//> using exclude $${.}${File.separator}Main.scala"""
)
testInputs.withInputs { (root, inputs) =>
val (crossSources, _) =
Expand Down Expand Up @@ -152,7 +152,7 @@ class ExcludeTests extends TestUtil.ScalaCliBuildSuite {
"""object Main {
|}""".stripMargin,
os.rel / "project.scala" ->
"""//> using exclude "src/*.scala" """
"""//> using exclude src/*.scala"""
)
testInputs.withInputs { (root, inputs) =>
val (crossSources, _) =
Expand Down Expand Up @@ -186,7 +186,7 @@ class ExcludeTests extends TestUtil.ScalaCliBuildSuite {
"""object Main {
|}""".stripMargin,
os.rel / "project.scala" ->
"""//> using exclude "src/*.scala" """
"""//> using exclude src/*.scala"""
)
testInputs.withInputs { (root, inputs) =>
val (crossSources, _) =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class PackagingUsingDirectiveTests extends TestUtil.ScalaCliBuildSuite {
test("package type") {
val inputs = TestInputs(
os.rel / "p.sc" ->
"""//> using packaging.packageType "graalvm"
"""//> using packaging.packageType graalvm
|def foo() = println("hello foo")
|""".stripMargin
)
Expand All @@ -38,7 +38,7 @@ class PackagingUsingDirectiveTests extends TestUtil.ScalaCliBuildSuite {
val output = "foo"
val inputs = TestInputs(
os.rel / "Bar.scala" ->
s"""//> using packaging.output "$output"
s"""//> using packaging.output $output
|def hello() = println("hello")
|""".stripMargin
)
Expand All @@ -54,10 +54,10 @@ class PackagingUsingDirectiveTests extends TestUtil.ScalaCliBuildSuite {
test("docker options") {
val inputs = TestInputs(
os.rel / "p.sc" ->
"""//> using packaging.dockerFrom "openjdk:11"
|//> using packaging.dockerImageTag "1.0.0"
|//> using packaging.dockerImageRegistry "virtuslab"
|//> using packaging.dockerImageRepository "scala-cli"
"""//> using packaging.dockerFrom openjdk:11
|//> using packaging.dockerImageTag 1.0.0
|//> using packaging.dockerImageRegistry virtuslab
|//> using packaging.dockerImageRepository scala-cli
|
|def foo() = println("hello foo")
|""".stripMargin
Expand Down
Loading

0 comments on commit 21ff792

Please sign in to comment.