Skip to content

Fix nightlies (REPL tests) #14260

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions compiler/test/dotty/tools/utils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import java.io.File
import java.nio.charset.StandardCharsets.UTF_8
import java.nio.file.{Files, Path => JPath}

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

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

private object Unthrown extends ControlThrowable

Expand All @@ -44,8 +45,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])(using codec: Codec = Codec.UTF8): List[String] =
files.flatMap(path => toolArgsParse(readLines(path.toFile)))
def toolArgsFor(files: List[JPath]): List[String] =
files.flatMap(path => toolArgsParse(Files.lines(path, UTF_8).limit(10).toScala(List)))

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