Skip to content

Commit 643314d

Browse files
committed
tests: Read tool args in test files
1 parent d77beb0 commit 643314d

File tree

4 files changed

+16
-8
lines changed

4 files changed

+16
-8
lines changed

compiler/test/dotty/tools/utils.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package dotty
22
package tools
33

44
import java.io.File
5+
import java.nio.charset.Charset
56
import java.nio.charset.StandardCharsets.UTF_8
67
import java.nio.file.{Files, Path => JPath}
78

@@ -45,8 +46,8 @@ def assertThrows[T <: Throwable: ClassTag](p: T => Boolean)(body: => Any): Unit
4546
case NonFatal(other) => throw AssertionError(s"Wrong exception: expected ${implicitly[ClassTag[T]]} but was ${other.getClass.getName}").tap(_.addSuppressed(other))
4647
end assertThrows
4748

48-
def toolArgsFor(files: List[JPath]): List[String] =
49-
files.flatMap(path => toolArgsParse(Files.lines(path, UTF_8).limit(10).toScala(List)))
49+
def toolArgsFor(files: List[JPath], charset: Charset = UTF_8): List[String] =
50+
files.flatMap(path => toolArgsParse(Files.lines(path, charset).limit(10).toScala(List)))
5051

5152
// Inspect the first 10 of the given lines for compiler options of the form
5253
// `// scalac: args`, `/* scalac: args`, ` * scalac: args`.

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import java.io.{File => JFile, IOException}
66
import java.lang.System.{lineSeparator => EOL}
77
import java.nio.file.StandardCopyOption.REPLACE_EXISTING
88
import java.nio.file.{Files, NoSuchFileException, Path, Paths}
9-
import java.nio.charset.StandardCharsets
9+
import java.nio.charset.{Charset, StandardCharsets}
1010
import java.text.SimpleDateFormat
1111
import java.util.{HashMap, Timer, TimerTask}
1212
import java.util.concurrent.{TimeUnit, TimeoutException, Executors => JExecutors}
@@ -441,15 +441,17 @@ trait ParallelTesting extends RunnerOrchestration { self =>
441441
throw e
442442

443443
protected def compile(files0: Array[JFile], flags0: TestFlags, suppressErrors: Boolean, targetDir: JFile): TestReporter = {
444-
val flags = flags0.and("-d", targetDir.getPath)
445-
.withClasspath(targetDir.getPath)
446-
447444
def flattenFiles(f: JFile): Array[JFile] =
448445
if (f.isDirectory) f.listFiles.flatMap(flattenFiles)
449446
else Array(f)
450447

451448
val files: Array[JFile] = files0.flatMap(flattenFiles)
452449

450+
val flags = flags0
451+
.and(toolArgsFor(files.toList.map(_.toPath), getCharsetFromEncodingOpt(flags0)): _*)
452+
.and("-d", targetDir.getPath)
453+
.withClasspath(targetDir.getPath)
454+
453455
def compileWithJavac(fs: Array[String]) = if (fs.nonEmpty) {
454456
val fullArgs = Array(
455457
"javac",
@@ -1358,6 +1360,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
13581360
// Create a CompilationTest and let the user decide whether to execute a pos or a neg test
13591361
new CompilationTest(targets)
13601362
}
1363+
1364+
private def getCharsetFromEncodingOpt(flags: TestFlags) =
1365+
flags.options.sliding(2).collectFirst {
1366+
case Array("-encoding", encoding) => Charset.forName(encoding)
1367+
}.getOrElse(StandardCharsets.UTF_8)
13611368
}
13621369

13631370
object ParallelTesting {

tests/neg/literals.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ trait RejectedLiterals {
22
def missingHex: Int = { 0x } // error: invalid literal number
33
}
44
/*
5-
// scalac: -Ywarn-octal-literal -Xfatal-warnings -deprecation
5+
// nsc: -Ywarn-octal-literal -Xfatal-warnings -deprecation
66
trait RejectedLiterals {
77
88
def missingHex: Int = { 0x } // line 4: was: not reported, taken as zero

tests/run/1938-2.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
object ProdNonEmpty {
22
def _1: Int = 0
3-
def _2: String = "???" // Slight variation with scalac: this test passes
3+
def _2: String = "???" // Slight variation with nsc: this test passes
44
// with ??? here. I think dotty behavior is fine
55
// according to the spec given that methods involved
66
// in pattern matching should be pure.

0 commit comments

Comments
 (0)