Skip to content

Commit b460782

Browse files
Merge pull request #14260 from dwijnand/fix-windows
Fix nightlies (REPL tests)
2 parents 3e74816 + 0698e0a commit b460782

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

compiler/test/dotty/tools/utils.scala

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import java.io.File
55
import java.nio.charset.StandardCharsets.UTF_8
66
import java.nio.file.{Files, Path => JPath}
77

8-
import scala.io.{Codec, Source}
8+
import scala.io.Source
9+
import scala.jdk.StreamConverters._
910
import scala.reflect.ClassTag
1011
import scala.util.Using.resource
1112
import scala.util.chaining.given
@@ -27,9 +28,9 @@ extension (str: String) def dropExtension =
2728
str.reverse.dropWhile(_ != '.').drop(1).reverse
2829

2930
private
30-
def withFile[T](file: File)(action: Source => T)(using Codec): T = resource(Source.fromFile(file))(action)
31-
def readLines(f: File)(using codec: Codec = Codec.UTF8): List[String] = withFile(f)(_.getLines.toList)
32-
def readFile(f: File)(using codec: Codec = Codec.UTF8): String = withFile(f)(_.mkString)
31+
def withFile[T](file: File)(action: Source => T): T = resource(Source.fromFile(file, UTF_8.name))(action)
32+
def readLines(f: File): List[String] = withFile(f)(_.getLines.toList)
33+
def readFile(f: File): String = withFile(f)(_.mkString)
3334

3435
private object Unthrown extends ControlThrowable
3536

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

47-
def toolArgsFor(files: List[JPath])(using codec: Codec = Codec.UTF8): List[String] =
48-
files.flatMap(path => toolArgsParse(readLines(path.toFile)))
48+
def toolArgsFor(files: List[JPath]): List[String] =
49+
files.flatMap(path => toolArgsParse(Files.lines(path, UTF_8).limit(10).toScala(List)))
4950

5051
// Inspect the first 10 of the given lines for compiler options of the form
5152
// `// scalac: args`, `/* scalac: args`, ` * scalac: args`.
@@ -63,4 +64,4 @@ def toolArgsParse(lines: List[String]): List[String] = {
6364
// but avoid picking up comments like "% scalac ./a.scala" and "$ scalac a.scala"
6465
}.map(stripped).headOption
6566
args.map(dotc.config.CommandLineParser.tokenize).getOrElse(Nil)
66-
}
67+
}

0 commit comments

Comments
 (0)