diff --git a/compiler/test/dotty/tools/utils.scala b/compiler/test/dotty/tools/utils.scala index a9792bf2f43c..f6d568ecce85 100644 --- a/compiler/test/dotty/tools/utils.scala +++ b/compiler/test/dotty/tools/utils.scala @@ -2,6 +2,7 @@ package dotty package tools import java.io.File +import java.nio.charset.Charset import java.nio.charset.StandardCharsets.UTF_8 import java.nio.file.{Files, Path => JPath} @@ -45,8 +46,8 @@ def assertThrows[T <: Throwable: ClassTag](p: T => Boolean)(body: => Any): Unit case NonFatal(other) => throw AssertionError(s"Wrong exception: expected ${implicitly[ClassTag[T]]} but was ${other.getClass.getName}").tap(_.addSuppressed(other)) end assertThrows -def toolArgsFor(files: List[JPath]): List[String] = - files.flatMap(path => toolArgsParse(Files.lines(path, UTF_8).limit(10).toScala(List))) +def toolArgsFor(files: List[JPath], charset: Charset = UTF_8): List[String] = + files.flatMap(path => toolArgsParse(Files.lines(path, charset).limit(10).toScala(List))) // Inspect the first 10 of the given lines for compiler options of the form // `// scalac: args`, `/* scalac: args`, ` * scalac: args`. @@ -58,7 +59,8 @@ def toolArgsParse(lines: List[String]): List[String] = { val endc = "*" + "/" // be forgiving of /* scalac: ... */ def stripped(s: String) = s.substring(s.indexOf(tag) + tag.length).stripSuffix(endc) val args = lines.to(LazyList).take(10).filter { s => - s.contains("// " + tag) + s.contains("//" + tag) + || s.contains("// " + tag) || s.contains("/* " + tag) || s.contains(" * " + tag) // but avoid picking up comments like "% scalac ./a.scala" and "$ scalac a.scala" diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index 4ba1229feecb..0efcb4c64fc5 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -6,7 +6,7 @@ import java.io.{File => JFile, IOException} import java.lang.System.{lineSeparator => EOL} import java.nio.file.StandardCopyOption.REPLACE_EXISTING import java.nio.file.{Files, NoSuchFileException, Path, Paths} -import java.nio.charset.StandardCharsets +import java.nio.charset.{Charset, StandardCharsets} import java.text.SimpleDateFormat import java.util.{HashMap, Timer, TimerTask} import java.util.concurrent.{TimeUnit, TimeoutException, Executors => JExecutors} @@ -441,15 +441,17 @@ trait ParallelTesting extends RunnerOrchestration { self => throw e protected def compile(files0: Array[JFile], flags0: TestFlags, suppressErrors: Boolean, targetDir: JFile): TestReporter = { - val flags = flags0.and("-d", targetDir.getPath) - .withClasspath(targetDir.getPath) - def flattenFiles(f: JFile): Array[JFile] = if (f.isDirectory) f.listFiles.flatMap(flattenFiles) else Array(f) val files: Array[JFile] = files0.flatMap(flattenFiles) + val flags = flags0 + .and(toolArgsFor(files.toList.map(_.toPath), getCharsetFromEncodingOpt(flags0)): _*) + .and("-d", targetDir.getPath) + .withClasspath(targetDir.getPath) + def compileWithJavac(fs: Array[String]) = if (fs.nonEmpty) { val fullArgs = Array( "javac", @@ -1358,6 +1360,11 @@ trait ParallelTesting extends RunnerOrchestration { self => // Create a CompilationTest and let the user decide whether to execute a pos or a neg test new CompilationTest(targets) } + + private def getCharsetFromEncodingOpt(flags: TestFlags) = + flags.options.sliding(2).collectFirst { + case Array("-encoding", encoding) => Charset.forName(encoding) + }.getOrElse(StandardCharsets.UTF_8) } object ParallelTesting { diff --git a/tests/neg/literals.scala b/tests/neg/literals.scala index 4b847a74df66..8e062c19351b 100644 --- a/tests/neg/literals.scala +++ b/tests/neg/literals.scala @@ -2,7 +2,7 @@ trait RejectedLiterals { def missingHex: Int = { 0x } // error: invalid literal number } /* -// scalac: -Ywarn-octal-literal -Xfatal-warnings -deprecation +// nsc: -Ywarn-octal-literal -Xfatal-warnings -deprecation trait RejectedLiterals { def missingHex: Int = { 0x } // line 4: was: not reported, taken as zero diff --git a/tests/run/1938-2.scala b/tests/run/1938-2.scala index 32e4c4518b96..143a94705455 100644 --- a/tests/run/1938-2.scala +++ b/tests/run/1938-2.scala @@ -1,6 +1,6 @@ object ProdNonEmpty { def _1: Int = 0 - def _2: String = "???" // Slight variation with scalac: this test passes + def _2: String = "???" // Slight variation with nsc: this test passes // with ??? here. I think dotty behavior is fine // according to the spec given that methods involved // in pattern matching should be pure.