Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix commas being treated as using directives value separators & deprecate using them with whitespace #3333

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
6 changes: 3 additions & 3 deletions gcbenchmark/gcbenchmark.scala
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//> using dep "com.lihaoyi::os-lib:0.9.1"
//> using dep "com.lihaoyi::pprint:0.8.1"
//> using scala "2.13"
//> using dep com.lihaoyi::os-lib:0.9.1
//> using dep com.lihaoyi::pprint:0.8.1
//> using scala 2.13

// Usage: scala-cli gcbenchmark.scala -- <path_to_scala_cli_executable>

Expand Down
2 changes: 1 addition & 1 deletion gifs/create_missing.sc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/usr/bin/env scala-cli

//> using lib "com.lihaoyi::os-lib:0.7.8"
//> using lib com.lihaoyi::os-lib:0.7.8

/** Small and handy script to generate stubs for .svg files with nice TODO
*/
Expand Down
2 changes: 1 addition & 1 deletion gifs/scenarios/embeddable_scripts.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ else
# Put your stuff here
cat <<EOF | updateFile count_lines.sc
#!/usr/bin/env scala-cli
//> using scala "3.0.2"
//> using scala 3.0.2
import scala.io.StdIn.readLine
import LazyList.continually

Expand Down
2 changes: 1 addition & 1 deletion gifs/scenarios/projects.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" &> /dev/null && pwd)
if [[ -z "${ASCIINEMA_REC}" ]]; then
# Warm up scala-cli
echo "println(1)" | scala-cli -S 2.13.6 -
echo "//> using dep \"com.softwaremill.sttp.client3::core:3.8.13\" " | scala-cli -S 2.13.6 -
echo "//> using dep com.softwaremill.sttp.client3::core:3.8.13" | scala-cli -S 2.13.6 -
scala-cli config suppress-warning.outdated-dependencies-files true
# or do other preparation (e.g. create code)
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import scala.build.errors.{Diagnostic, Severity}

class CustomDirectivesReporter(path: Either[String, os.Path], onDiagnostic: Diagnostic => Unit)
extends Reporter {

private var errorCount = 0
private var errorCount = 0
private var warningCount = 0

private def toScalaCliPosition(position: DirectivePosition): Position = {
val coords = (position.getLine, position.getColumn)
Expand All @@ -28,16 +28,21 @@ class CustomDirectivesReporter(path: Either[String, os.Path], onDiagnostic: Diag
}
override def warning(msg: String): Unit =
onDiagnostic {
warningCount += 1
Diagnostic(msg, Severity.Warning)
}
override def warning(position: DirectivePosition, msg: String): Unit =
onDiagnostic {
warningCount += 1
Diagnostic(msg, Severity.Warning, Seq(toScalaCliPosition(position)))
}

override def hasErrors(): Boolean =
errorCount != 0

override def hasWarnings(): Boolean =
warningCount != 0

override def reset(): Unit = {
errorCount = 0
}
Expand Down
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
Loading