Skip to content

Commit 78e2fb0

Browse files
committed
Revert "tests: Move toolArgsFor out of PatmatExhaustivityTest"
This reverts commit 5fc8313.
1 parent b599359 commit 78e2fb0

File tree

2 files changed

+26
-28
lines changed

2 files changed

+26
-28
lines changed

compiler/test/dotty/tools/dotc/transform/PatmatExhaustivityTest.scala

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@ import reporting.TestReporter
1010
import dotty.tools.io.Directory
1111

1212
import java.io._
13-
import java.nio.file.{Path => JPath}
13+
import java.nio.file.{Files, Path => JPath}
1414

15+
import scala.io.Source._
1516
import org.junit.Test
1617

1718
class PatmatExhaustivityTest {
@@ -78,4 +79,22 @@ class PatmatExhaustivityTest {
7879

7980
println(msg)
8081
}
82+
83+
// inspect given files for tool args of the form `tool: args`
84+
// if args string ends in close comment, drop the `*` `/`
85+
// if split, parse the args string as command line.
86+
// (from scala.tools.partest.nest.Runner#toolArgsFor)
87+
private def toolArgsFor(files: List[JPath]): List[String] = {
88+
import scala.jdk.OptionConverters._
89+
import config.CommandLineParser.tokenize
90+
files.flatMap { path =>
91+
val tag = "scalac:"
92+
val endc = "*" + "/" // be forgiving of /* scalac: ... */
93+
def stripped(s: String) = s.substring(s.indexOf(tag) + tag.length).stripSuffix(endc)
94+
val args = scala.util.Using.resource(Files.lines(path, scala.io.Codec.UTF8.charSet))(
95+
_.limit(10).filter(_.contains(tag)).map(stripped).findAny.toScala
96+
)
97+
args.map(tokenize).getOrElse(Nil)
98+
}
99+
}
81100
}

compiler/test/dotty/tools/utils.scala

Lines changed: 6 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package tools
33

44
import java.io.File
55
import java.nio.charset.StandardCharsets.UTF_8
6-
import java.nio.file.{Files, Path => JPath}
76

8-
import scala.io.{Codec, Source}
7+
import scala.io.Source
98
import scala.reflect.ClassTag
109
import scala.util.Using.resource
1110
import scala.util.chaining.given
@@ -26,10 +25,11 @@ extension (f: File) def absPath =
2625
extension (str: String) def dropExtension =
2726
str.reverse.dropWhile(_ != '.').drop(1).reverse
2827

29-
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)
28+
private def withFile[T](file: File)(action: Source => T): T =
29+
resource(Source.fromFile(file, UTF_8.name))(action)
30+
31+
def readLines(f: File): List[String] = withFile(f)(_.getLines.toList)
32+
def readFile(f: File): String = withFile(f)(_.mkString)
3333

3434
private object Unthrown extends ControlThrowable
3535

@@ -43,24 +43,3 @@ def assertThrows[T <: Throwable: ClassTag](p: T => Boolean)(body: => Any): Unit
4343
case failed: T => throw AssertionError(s"Exception failed check: $failed").tap(_.addSuppressed(failed))
4444
case NonFatal(other) => throw AssertionError(s"Wrong exception: expected ${implicitly[ClassTag[T]]} but was ${other.getClass.getName}").tap(_.addSuppressed(other))
4545
end assertThrows
46-
47-
def toolArgsFor(files: List[JPath])(using codec: Codec = Codec.UTF8): List[String] =
48-
files.flatMap(path => toolArgsParse(readLines(path.toFile)))
49-
50-
// Inspect the first 10 of the given lines for compiler options of the form
51-
// `// scalac: args`, `/* scalac: args`, ` * scalac: args`.
52-
// If args string ends in close comment, drop the `*` `/`.
53-
// If split, parse the args string as a command line.
54-
// (from scala.tools.partest.nest.Runner#toolArgsFor)
55-
def toolArgsParse(lines: List[String]): List[String] = {
56-
val tag = "scalac:"
57-
val endc = "*" + "/" // be forgiving of /* scalac: ... */
58-
def stripped(s: String) = s.substring(s.indexOf(tag) + tag.length).stripSuffix(endc)
59-
val args = lines.to(LazyList).take(10).filter { s =>
60-
s.contains("// " + tag)
61-
|| s.contains("/* " + tag)
62-
|| s.contains(" * " + tag)
63-
// but avoid picking up comments like "% scalac ./a.scala" and "$ scalac a.scala"
64-
}.map(stripped).headOption
65-
args.map(dotc.config.CommandLineParser.tokenize).getOrElse(Nil)
66-
}

0 commit comments

Comments
 (0)