aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorliu fengyun <liu@fengy.me>2016-10-18 18:58:11 +0200
committerFelix Mulder <felix.mulder@gmail.com>2016-11-09 13:06:27 +0100
commite0839e97cac2d212aae8eebbf3f828f91a27ddab (patch)
tree42bba77356f6d61e9ca872f2a7a696b266fbcb30 /test
parent1496db4b6fe039033f7d42d203c1563202c79868 (diff)
downloaddotty-e0839e97cac2d212aae8eebbf3f828f91a27ddab.tar.gz
dotty-e0839e97cac2d212aae8eebbf3f828f91a27ddab.tar.bz2
dotty-e0839e97cac2d212aae8eebbf3f828f91a27ddab.zip
add the forgotten patmat test
Diffstat (limited to 'test')
-rw-r--r--test/test/transform/PatmatExhaustivityTest.scala90
1 files changed, 90 insertions, 0 deletions
diff --git a/test/test/transform/PatmatExhaustivityTest.scala b/test/test/transform/PatmatExhaustivityTest.scala
new file mode 100644
index 000000000..d23a1c963
--- /dev/null
+++ b/test/test/transform/PatmatExhaustivityTest.scala
@@ -0,0 +1,90 @@
+package test.transform
+
+import java.io._
+
+import scala.io.Source._
+import scala.reflect.io.Directory
+import org.junit.Test
+import dotty.tools.dotc.Main
+import dotty.tools.dotc.reporting.ClassicReporter
+
+class PatmatExhaustivityTest {
+ val testsDir = "./tests/patmat"
+ // stop-after: patmatexhaust-huge.scala crash compiler
+ val options = List("-color:never", "-Ystop-after:splitter", "-Ycheck-all-patmat")
+
+ private def compileFile(file: File) = {
+ val stringBuffer = new StringWriter()
+ val reporter = new ClassicReporter(writer = new PrintWriter(stringBuffer))
+
+ try {
+ Main.process((file.getPath::options).toArray, reporter, null)
+ } catch {
+ case e: Throwable =>
+ println(s"Compile $file exception:")
+ e.printStackTrace()
+ }
+
+ val actual = stringBuffer.toString.trim
+ val checkFilePath = file.getAbsolutePath.stripSuffix(".scala") + ".check"
+ val checkContent =
+ if (new File(checkFilePath).exists)
+ fromFile(checkFilePath).getLines.mkString("\n").trim
+ else ""
+
+ (file, checkContent, actual)
+ }
+
+ /** A single test with multiple files grouped in a folder */
+ private def compileDir(file: File) = {
+ val stringBuffer = new StringWriter()
+ val reporter = new ClassicReporter(writer = new PrintWriter(stringBuffer))
+
+ val files = Directory(file.getPath).list.toList
+ .filter(f => f.extension == "scala" || f.extension == "java" )
+ .map(_.jfile.getPath)
+
+ try {
+ Main.process((options ++ files).toArray, reporter, null)
+ } catch {
+ case e: Throwable =>
+ println(s"Compile $file exception:")
+ e.printStackTrace()
+ }
+
+ val actual = stringBuffer.toString.trim
+ val checkFilePath = file.getPath + File.separator + "expected.check"
+ val checkContent =
+ if (new File(checkFilePath).exists)
+ fromFile(checkFilePath).getLines.mkString("\n").trim
+ else ""
+
+ (file, checkContent, actual)
+ }
+
+ @Test def patmatExhaustivity: Unit = {
+ val res = Directory(testsDir).list.toList
+ .filter(f => f.extension == "scala" || f.isDirectory)
+ .map { f =>
+ if (f.isDirectory)
+ compileDir(f.jfile)
+ else
+ compileFile(f.jfile)
+ }
+
+ val failed = res.filter { case (_, expected, actual) => expected != actual }
+ val ignored = Directory(testsDir).list.toList.filter(_.extension == "ignore")
+
+ failed.foreach { case (file, expected, actual) =>
+ println(s"\n----------------- incorrect output for $file --------------\n" +
+ s"Expected:\n-------\n$expected\n\nActual\n----------\n$actual\n"
+ )
+ }
+
+ val msg = s"Total: ${res.length + ignored.length}, Failed: ${failed.length}, Ignored: ${ignored.length}"
+
+ assert(failed.length == 0, msg)
+
+ println(msg)
+ }
+}