Skip to content

Commit 74d1b82

Browse files
authored
Merge pull request #14144 from dwijnand/tests/read-tool-args
2 parents 2f16da6 + 643314d commit 74d1b82

File tree

4 files changed

+18
-9
lines changed

4 files changed

+18
-9
lines changed

compiler/test/dotty/tools/utils.scala

Lines changed: 5 additions & 3 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`.
@@ -58,7 +59,8 @@ def toolArgsParse(lines: List[String]): List[String] = {
5859
val endc = "*" + "/" // be forgiving of /* scalac: ... */
5960
def stripped(s: String) = s.substring(s.indexOf(tag) + tag.length).stripSuffix(endc)
6061
val args = lines.to(LazyList).take(10).filter { s =>
61-
s.contains("// " + tag)
62+
s.contains("//" + tag)
63+
|| s.contains("// " + tag)
6264
|| s.contains("/* " + tag)
6365
|| s.contains(" * " + tag)
6466
// but avoid picking up comments like "% scalac ./a.scala" and "$ scalac a.scala"

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

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import java.lang.System.{lineSeparator => EOL}
77
import java.net.URL
88
import java.nio.file.StandardCopyOption.REPLACE_EXISTING
99
import java.nio.file.{Files, NoSuchFileException, Path, Paths}
10-
import java.nio.charset.StandardCharsets
10+
import java.nio.charset.{Charset, StandardCharsets}
1111
import java.text.SimpleDateFormat
1212
import java.util.{HashMap, Timer, TimerTask}
1313
import java.util.concurrent.{TimeUnit, TimeoutException, Executors => JExecutors}
@@ -445,15 +445,17 @@ trait ParallelTesting extends RunnerOrchestration { self =>
445445
throw e
446446

447447
protected def compile(files0: Array[JFile], flags0: TestFlags, suppressErrors: Boolean, targetDir: JFile): TestReporter = {
448-
val flags = flags0.and("-d", targetDir.getPath)
449-
.withClasspath(targetDir.getPath)
450-
451448
def flattenFiles(f: JFile): Array[JFile] =
452449
if (f.isDirectory) f.listFiles.flatMap(flattenFiles)
453450
else Array(f)
454451

455452
val files: Array[JFile] = files0.flatMap(flattenFiles)
456453

454+
val flags = flags0
455+
.and(toolArgsFor(files.toList.map(_.toPath), getCharsetFromEncodingOpt(flags0)): _*)
456+
.and("-d", targetDir.getPath)
457+
.withClasspath(targetDir.getPath)
458+
457459
def compileWithJavac(fs: Array[String]) = if (fs.nonEmpty) {
458460
val fullArgs = Array(
459461
"javac",
@@ -1442,6 +1444,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
14421444
// Create a CompilationTest and let the user decide whether to execute a pos or a neg test
14431445
new CompilationTest(targets)
14441446
}
1447+
1448+
private def getCharsetFromEncodingOpt(flags: TestFlags) =
1449+
flags.options.sliding(2).collectFirst {
1450+
case Array("-encoding", encoding) => Charset.forName(encoding)
1451+
}.getOrElse(StandardCharsets.UTF_8)
14451452
}
14461453

14471454
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)