Skip to content

Commit 2260aa2

Browse files
Merge pull request #13069 from dwijnand/patmat-no-check-all
Remove excessive -Ycheck-all-patmat use in tests
2 parents 9997e9c + e27c7d2 commit 2260aa2

24 files changed

+65
-45
lines changed

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

Lines changed: 28 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,28 +10,25 @@ 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

1515
import scala.io.Source._
1616
import 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-
2318
class 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
}

tests/patmat/i10174b.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
2: Pattern Match Exhaustivity: _: Int
2-
58: Match case Unreachable
1+
3: Pattern Match Exhaustivity: _: Int
2+
59: Match case Unreachable

tests/patmat/i10174b.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// scalac: -Ycheck-all-patmat
12
def foo(x: Int): Unit =
23
x match {
34
case 1 =>
@@ -1001,4 +1002,4 @@ def foo(x: Int): Unit =
10011002
case 998 =>
10021003
case 999 =>
10031004
case 1000 =>
1004-
}
1005+
}
File renamed without changes.
File renamed without changes.
File renamed without changes.

tests/patmat/i6197d.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
5: Pattern Match Exhaustivity: _: Array[String]
1+
6: Pattern Match Exhaustivity: _: Array[String]

tests/patmat/i6197d.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
1+
// scalac: -Ycheck-all-patmat
12
def foo(x: Array[String]) = x match {
23
case _: Array[_] =>
34
}
45

56
def bar(x: Array[String]) = x match {
67
case _: Array[_ <: Int] =>
7-
}
8+
}

tests/patmat/i6255b.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2: Pattern Match Exhaustivity: _: Expr[Int]
1+
3: Pattern Match Exhaustivity: _: Expr[Int]

tests/patmat/i6255b.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// scalac: -Ycheck-all-patmat
12
class Foo {
23
def foo(x: quoted.Expr[Int])(using scala.quoted.Quotes): Unit = x match {
34
case '{ 1 } =>

tests/patmat/patmat-indent.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
9: Pattern Match Exhaustivity: Nil
2-
23: Pattern Match Exhaustivity: true, false
3-
27: Pattern Match Exhaustivity: _: Int
1+
10: Pattern Match Exhaustivity: Nil
2+
24: Pattern Match Exhaustivity: true, false
3+
28: Pattern Match Exhaustivity: _: Int

tests/patmat/patmat-indent.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// scalac: -Ycheck-all-patmat
12
object Test {
23
val Nil: scala.collection.immutable.Nil.type = scala.collection.immutable.Nil
34
val X = 5
@@ -27,4 +28,4 @@ object Test {
2728
def foo3(x: Int) = x match {
2829
case X => 0
2930
}
30-
}
31+
}

tests/patmat/t10502.check

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
5: Pattern Match Exhaustivity: Perhaps(None)
2-
15: Pattern Match Exhaustivity: Nil
3-
31: Pattern Match Exhaustivity: Multi(None, _)
4-
44: Pattern Match Exhaustivity: Prod(None, _)
1+
6: Pattern Match Exhaustivity: Perhaps(None)
2+
16: Pattern Match Exhaustivity: Nil
3+
32: Pattern Match Exhaustivity: Multi(None, _)
4+
45: Pattern Match Exhaustivity: Prod(None, _)

tests/patmat/t10502.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// scalac: -Ycheck-all-patmat
12
object Perhaps {
23

34
def unapply[A](oa: Option[A]): Some[Option[A]] = Some(oa)

tests/patmat/t3163.check

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
2: Pattern Match Exhaustivity: _: AnyVal
1+
3: Pattern Match Exhaustivity: _: AnyVal

tests/patmat/t3163.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// scalac: -Ycheck-all-patmat
12
object Test {
23
def foo(x : AnyVal) = x match {case b : Boolean => "It's a bool"}
3-
}
4+
}

tests/patmat/t4526.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
2: Pattern Match Exhaustivity: _: Int
2-
7: Pattern Match Exhaustivity: (_, _)
3-
12: Pattern Match Exhaustivity: (true, true), (false, false)
1+
3: Pattern Match Exhaustivity: _: Int
2+
8: Pattern Match Exhaustivity: (_, _)
3+
13: Pattern Match Exhaustivity: (true, true), (false, false)

tests/patmat/t4526.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// scalac: -Ycheck-all-patmat
12
object Test{
23
def foo(a: Int) = a match {
34
case 5 => "Five!"
@@ -13,4 +14,4 @@ object Test{
1314
case (true, false) => "tf"
1415
case (false, true) => "ft"
1516
}
16-
}
17+
}

tests/patmat/t4661b.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
10: Pattern Match Exhaustivity: _: c.Foo
2-
13: Match case Unreachable
1+
11: Pattern Match Exhaustivity: _: c.Foo
2+
14: Match case Unreachable

tests/patmat/t4661b.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// scalac: -Ycheck-all-patmat
12
class C {
23
trait Foo
34
class One extends Foo

tests/patmat/t9351.check

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
8: Pattern Match Exhaustivity: _: A
2-
17: Pattern Match Exhaustivity: (_, _)
3-
28: Pattern Match Exhaustivity: (_, _)
1+
9: Pattern Match Exhaustivity: _: A
2+
18: Pattern Match Exhaustivity: (_, _)
3+
29: Pattern Match Exhaustivity: (_, _)

tests/patmat/t9351.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// scalac: -Ycheck-all-patmat
12
trait A {}
23
case object B extends A {}
34
case object C extends A {}

tests/patmat/t9809.check

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
3: Pattern Match Exhaustivity: (_, _)
2-
7: Pattern Match Exhaustivity: (_, _)
1+
4: Pattern Match Exhaustivity: (_, _)
2+
8: Pattern Match Exhaustivity: (_, _)

tests/patmat/t9809.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
// scalac: -Ycheck-all-patmat
12
object Example {
23
val op1: (Any, Any) => Unit = {
34
case (_, b: Int) =>

0 commit comments

Comments
 (0)