@@ -10,28 +10,25 @@ import reporting.TestReporter
1010import dotty .tools .io .Directory
1111
1212import java .io ._
13- import java .nio .file .{Path => JPath }
13+ import java .nio .file .{Files , Path => JPath }
1414
1515import scala .io .Source ._
1616import org .junit .Test
1717
18- class PatmatDefaultExhaustivityTest extends PatmatExhaustivityTest {
19- override val testsDir = " tests/patmat-default"
20- override val options = super .options.filter(_ != " -Ycheck-all-patmat" )
21- }
22-
2318class PatmatExhaustivityTest {
2419 val testsDir = " tests/patmat"
25- // stop-after: patmatexhaust-huge.scala crash compiler
26- def options = List (" -pagewidth" , " 80" , " -color:never" , " -Ystop-after:explicitSelf" , " -Ycheck-all-patmat" , " -classpath" , TestConfiguration .basicClasspath)
20+ // pagewidth/color: for a stable diff as the defaults are based on the terminal (e.g size)
21+ // stop-after: patmatexhaust-huge.scala crash compiler (but also hides other warnings..)
22+ val options = List (" -pagewidth" , " 80" , " -color:never" , " -Ystop-after:explicitSelf" , " -classpath" , TestConfiguration .basicClasspath)
2723
28- private def compile (files : Seq [String ]): Seq [String ] = {
24+ private def compile (files : List [JPath ]): Seq [String ] = {
25+ val opts = toolArgsFor(files)
2926 val stringBuffer = new StringWriter ()
3027 val printWriter = new PrintWriter (stringBuffer)
3128 val reporter = TestReporter .simplifiedReporter(printWriter)
3229
3330 try {
34- Main .process((options ++ files).toArray, reporter, null )
31+ Main .process((options ::: opts ::: files.map(_.toString) ).toArray, reporter, null )
3532 } catch {
3633 case e : Throwable =>
3734 e.printStackTrace(printWriter)
@@ -44,7 +41,7 @@ class PatmatExhaustivityTest {
4441 }
4542
4643 private def compileFile (path : JPath ): Boolean = {
47- val actualLines = compile(path.toString :: Nil )
44+ val actualLines = compile(List ( path) )
4845 val baseFilePath = path.toString.stripSuffix(" .scala" )
4946 val checkFilePath = baseFilePath + " .check"
5047
@@ -55,7 +52,7 @@ class PatmatExhaustivityTest {
5552 private def compileDir (path : JPath ): Boolean = {
5653 val files = Directory (path).list.toList
5754 .filter(f => f.extension == " scala" || f.extension == " java" )
58- .map(_.jpath.toString )
55+ .map(_.jpath)
5956
6057 val actualLines = compile(files)
6158 val checkFilePath = s " ${path}${File .separator}expected.check "
@@ -67,12 +64,7 @@ class PatmatExhaustivityTest {
6764 def patmatExhaustivity : Unit = {
6865 val res = Directory (testsDir).list.toList
6966 .filter(f => f.extension == " scala" || f.isDirectory)
70- .map { f =>
71- if (f.isDirectory)
72- compileDir(f.jpath)
73- else
74- compileFile(f.jpath)
75- }
67+ .map(f => if f.isDirectory then compileDir(f.jpath) else compileFile(f.jpath))
7668
7769 val failed = res.filter(! _)
7870 val ignored = Directory (testsDir).list.toList.filter(_.extension == " ignore" )
@@ -83,4 +75,22 @@ class PatmatExhaustivityTest {
8375
8476 println(msg)
8577 }
78+
79+ // inspect given files for tool args of the form `tool: args`
80+ // if args string ends in close comment, drop the `*` `/`
81+ // if split, parse the args string as command line.
82+ // (from scala.tools.partest.nest.Runner#toolArgsFor)
83+ private def toolArgsFor (files : List [JPath ]): List [String ] = {
84+ import scala .jdk .OptionConverters ._
85+ import config .CommandLineParser .tokenize
86+ files.flatMap { path =>
87+ val tag = " scalac:"
88+ val endc = " *" + " /" // be forgiving of /* scalac: ... */
89+ def stripped (s : String ) = s.substring(s.indexOf(tag) + tag.length).stripSuffix(endc)
90+ val args = scala.util.Using .resource(Files .lines(path, scala.io.Codec .UTF8 .charSet))(
91+ _.limit(10 ).filter(_.contains(tag)).map(stripped).findAny.toScala
92+ )
93+ args.map(tokenize).getOrElse(Nil )
94+ }
95+ }
8696}
0 commit comments