@@ -10,28 +10,25 @@ import reporting.TestReporter
10
10
import dotty .tools .io .Directory
11
11
12
12
import java .io ._
13
- import java .nio .file .{Path => JPath }
13
+ import java .nio .file .{Files , Path => JPath }
14
14
15
15
import scala .io .Source ._
16
16
import org .junit .Test
17
17
18
- class PatmatDefaultExhaustivityTest extends PatmatExhaustivityTest {
19
- override val testsDir = " tests/patmat-default"
20
- override val options = super .options.filter(_ != " -Ycheck-all-patmat" )
21
- }
22
-
23
18
class PatmatExhaustivityTest {
24
19
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)
27
23
28
- private def compile (files : Seq [String ]): Seq [String ] = {
24
+ private def compile (files : List [JPath ]): Seq [String ] = {
25
+ val opts = toolArgsFor(files)
29
26
val stringBuffer = new StringWriter ()
30
27
val printWriter = new PrintWriter (stringBuffer)
31
28
val reporter = TestReporter .simplifiedReporter(printWriter)
32
29
33
30
try {
34
- Main .process((options ++ files).toArray, reporter, null )
31
+ Main .process((options ::: opts ::: files.map(_.toString) ).toArray, reporter, null )
35
32
} catch {
36
33
case e : Throwable =>
37
34
e.printStackTrace(printWriter)
@@ -44,7 +41,7 @@ class PatmatExhaustivityTest {
44
41
}
45
42
46
43
private def compileFile (path : JPath ): Boolean = {
47
- val actualLines = compile(path.toString :: Nil )
44
+ val actualLines = compile(List ( path) )
48
45
val baseFilePath = path.toString.stripSuffix(" .scala" )
49
46
val checkFilePath = baseFilePath + " .check"
50
47
@@ -55,7 +52,7 @@ class PatmatExhaustivityTest {
55
52
private def compileDir (path : JPath ): Boolean = {
56
53
val files = Directory (path).list.toList
57
54
.filter(f => f.extension == " scala" || f.extension == " java" )
58
- .map(_.jpath.toString )
55
+ .map(_.jpath)
59
56
60
57
val actualLines = compile(files)
61
58
val checkFilePath = s " ${path}${File .separator}expected.check "
@@ -67,12 +64,7 @@ class PatmatExhaustivityTest {
67
64
def patmatExhaustivity : Unit = {
68
65
val res = Directory (testsDir).list.toList
69
66
.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))
76
68
77
69
val failed = res.filter(! _)
78
70
val ignored = Directory (testsDir).list.toList.filter(_.extension == " ignore" )
@@ -83,4 +75,22 @@ class PatmatExhaustivityTest {
83
75
84
76
println(msg)
85
77
}
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
+ }
86
96
}
0 commit comments