Skip to content

Commit 090710a

Browse files
authored
use directives instead of scalac options in tests (#18560)
- update remaining `// scalac:` to `//> using options` in tests - throw error when using old syntax in tests fixes `scalac:` portion of #18149 still to do: - rewrite `// test: -jvm 15+` to use a directive - support `// scalajs: --skip` with a directive or similar once this is done, we can remove the `toolArg` regex
2 parents 5adef26 + c16fb4e commit 090710a

File tree

6 files changed

+23
-20
lines changed

6 files changed

+23
-20
lines changed

compiler/test-resources/repl/i13208.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// scalac: -source:future -deprecation
1+
//> using options -source:future -deprecation
22
scala> type M[X] = X match { case Int => String case _ => Int }
33
scala> type N[X] = X match { case List[_] => Int }
44
1 warning found

compiler/test-resources/repl/rewrite-messages

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// scalac: -source:future-migration -deprecation -Werror
1+
//> using options -source:future-migration -deprecation -Werror
22
scala> import scala.util._
33
-- Error: ----------------------------------------------------------------------
44
1 | import scala.util._

compiler/test/dotty/tools/repl/ReplTest.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ extends ReplDriver(options, new PrintStream(out, true, StandardCharsets.UTF_8.na
6969

7070
val expectedOutput = lines.filter(nonBlank)
7171
val actualOutput = {
72-
val opts = toolArgsFor(ToolName.Scalac)(lines.take(1))
72+
val opts = toolArgsFor(ToolName.Scalac, scriptFile.map(_.toString))(lines.take(1))
7373
val (optsLine, inputLines) = if opts.isEmpty then ("", lines) else (lines.head, lines.drop(1))
7474
resetToInitial(opts)
7575

compiler/test/dotty/tools/utils.scala

+18-13
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ type ToolArgs = Map[ToolName, List[String]]
6565
*/
6666
def toolArgsFor(files: List[JPath], charset: Charset = UTF_8): ToolArgs =
6767
files.foldLeft(Map.empty[ToolName, List[String]]) { (res, path) =>
68-
val toolargs = toolArgsParse(resource(Files.lines(path, charset))(_.limit(10).toScala(List)))
68+
val toolargs = toolArgsParse(resource(Files.lines(path, charset))(_.limit(10).toScala(List)), Some(path.toString))
6969
toolargs.foldLeft(res) {
7070
case (acc, (tool, args)) =>
7171
val name = ToolName.named(tool)
@@ -74,31 +74,36 @@ def toolArgsFor(files: List[JPath], charset: Charset = UTF_8): ToolArgs =
7474
}
7575
}
7676

77-
def toolArgsFor(tool: ToolName)(lines: List[String]): List[String] =
78-
toolArgsParse(lines).collectFirst { case (name, args) if tool eq ToolName.named(name) => CommandLineParser.tokenize(args) }.getOrElse(Nil)
77+
def toolArgsFor(tool: ToolName, filename: Option[String])(lines: List[String]): List[String] =
78+
toolArgsParse(lines, filename).collectFirst { case (name, args) if tool eq ToolName.named(name) => CommandLineParser.tokenize(args) }.getOrElse(Nil)
7979

80-
// scalac: arg1 arg2, with alternative opening, optional space, alt names, text that is not */ up to end.
80+
// scalajs: arg1 arg2, with alternative opening, optional space, alt names, text that is not */ up to end.
8181
// groups are (name, args)
82+
// note: ideally we would replace everything that requires this to use directive syntax, however scalajs: --skip has no directive equivalent yet.
8283
private val toolArg = raw"(?://|/\*| \*) ?(?i:(${ToolName.values.mkString("|")})):((?:[^*]|\*(?!/))*)".r.unanchored
8384
private val directiveOptionsArg = raw"//> using options (.*)".r.unanchored
8485

8586
// Inspect the lines for compiler options of the form
86-
// `// scalac: args`, `/* scalac: args`, ` * scalac: args`.
87+
// `//> using options args`, `// scalajs: args`, `/* scalajs: args`, ` * scalajs: args` etc.
8788
// If args string ends in close comment, stop at the `*` `/`.
8889
// Returns all the matches by the regex.
89-
def toolArgsParse(lines: List[String]): List[(String,String)] =
90-
lines.flatMap { case toolArg(name, args) => List((name, args)) case _ => Nil } ++
90+
def toolArgsParse(lines: List[String], filename: Option[String]): List[(String,String)] =
91+
lines.flatMap {
92+
case toolArg("scalac", _) => sys.error(s"`// scalac: args` not supported. Please use `//> using options args`${filename.fold("")(f => s" in file $f")}")
93+
case toolArg(name, args) => List((name, args))
94+
case _ => Nil
95+
} ++
9196
lines.flatMap { case directiveOptionsArg(args) => List(("scalac", args)) case _ => Nil }
9297

9398
import org.junit.Test
9499
import org.junit.Assert._
95100

96101
class ToolArgsTest:
97-
@Test def `missing toolarg is absent`: Unit = assertEquals(Nil, toolArgsParse(List("")))
98-
@Test def `toolarg is present`: Unit = assertEquals(("test", " -hey") :: Nil, toolArgsParse("// test: -hey" :: Nil))
99-
@Test def `tool is present`: Unit = assertEquals("-hey" :: Nil, toolArgsFor(ToolName.Test)("// test: -hey" :: Nil))
100-
@Test def `missing tool is absent`: Unit = assertEquals(Nil, toolArgsFor(ToolName.Javac)("// test: -hey" :: Nil))
102+
@Test def `missing toolarg is absent`: Unit = assertEquals(Nil, toolArgsParse(List(""), None))
103+
@Test def `toolarg is present`: Unit = assertEquals(("test", " -hey") :: Nil, toolArgsParse("// test: -hey" :: Nil, None))
104+
@Test def `tool is present`: Unit = assertEquals("-hey" :: Nil, toolArgsFor(ToolName.Test, None)("// test: -hey" :: Nil))
105+
@Test def `missing tool is absent`: Unit = assertEquals(Nil, toolArgsFor(ToolName.Javac, None)("// test: -hey" :: Nil))
101106
@Test def `multitool is present`: Unit =
102-
assertEquals("-hey" :: Nil, toolArgsFor(ToolName.Test)("// test: -hey" :: "// javac: -d /tmp" :: Nil))
103-
assertEquals("-d" :: "/tmp" :: Nil, toolArgsFor(ToolName.Javac)("// test: -hey" :: "// javac: -d /tmp" :: Nil))
107+
assertEquals("-hey" :: Nil, toolArgsFor(ToolName.Test, None)("// test: -hey" :: "// javac: -d /tmp" :: Nil))
108+
assertEquals("-d" :: "/tmp" :: Nil, toolArgsFor(ToolName.Javac, None)("// test: -hey" :: "// javac: -d /tmp" :: Nil))
104109
end ToolArgsTest

tests/disabled/macro/pos/t8013/inpervolated_2.scala

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
/*
2-
* scalac: -Xfatal-warnings -Xlint
3-
*/
1+
//> using options -Xfatal-warnings -Xlint
42
package t8013
53

64
// unsuspecting user of perverse macro

tests/pos-macros/i18409.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// scalac: -Werror -Wunused:all
1+
//> using options -Werror -Wunused:all
22

33
import scala.quoted.*
44

0 commit comments

Comments
 (0)