diff options
author | Felix Mulder <felix.mulder@gmail.com> | 2017-03-11 16:35:52 +0100 |
---|---|---|
committer | Felix Mulder <felix.mulder@gmail.com> | 2017-03-29 10:33:22 +0200 |
commit | 57f8d1b1f7962f99cf27501994b1440e369fe597 (patch) | |
tree | c032a08900e8befe280ab7119785fa3e339cf77f | |
parent | fc2bdc85381d93dcf7010cf13347569e14efb29c (diff) | |
download | dotty-57f8d1b1f7962f99cf27501994b1440e369fe597.tar.gz dotty-57f8d1b1f7962f99cf27501994b1440e369fe597.tar.bz2 dotty-57f8d1b1f7962f99cf27501994b1440e369fe597.zip |
Add neg testing capability to ParallelTesting
-rw-r--r-- | compiler/test/dotty/tools/dotc/ParallelTesting.scala | 47 | ||||
-rw-r--r-- | tests/neg/i941.scala | 2 | ||||
-rw-r--r-- | tests/neg/instantiateAbstract.scala | 2 |
3 files changed, 47 insertions, 4 deletions
diff --git a/compiler/test/dotty/tools/dotc/ParallelTesting.scala b/compiler/test/dotty/tools/dotc/ParallelTesting.scala index 45e341c33..8c4750f9f 100644 --- a/compiler/test/dotty/tools/dotc/ParallelTesting.scala +++ b/compiler/test/dotty/tools/dotc/ParallelTesting.scala @@ -92,6 +92,44 @@ trait ParallelTesting { } } + private final class NegCompileRun(targetDirs: List[JFile], fromDir: String, flags: Array[String]) + extends CompileRun(targetDirs, fromDir, flags) { + private[this] var _failed = false + private[this] def fail(): Unit = _failed = true + + def didFail: Boolean = _failed + + protected def compilationRunnable(dir: JFile): Runnable = new Runnable { + def run(): Unit = + try { + val sourceFiles = dir.listFiles.filter(f => f.getName.endsWith(".scala") || f.getName.endsWith(".java")) + + val expectedErrors = dir.listFiles.filter(_.getName.endsWith(".scala")).foldLeft(0) { (acc, file) => + acc + Source.fromFile(file).sliding("// error".length).count(_.mkString == "// error") + } + + val errors = compile(sourceFiles, flags ++ Array("-d", dir.getAbsolutePath), true) + val actualErrors = errors.length + + if (expectedErrors != actualErrors) { + System.err.println { + s"\nWrong number of errors encountered when compiling $dir, expected: $expectedErrors, actual: $actualErrors\n" + } + fail() + } + + completeCompilation(actualErrors) + } + catch { + case NonFatal(e) => { + System.err.println(s"\n${e.getMessage}\n") + completeCompilation(1) + throw e + } + } + } + } + private val driver = new Driver { override def newCompiler(implicit ctx: Context) = new Compiler } @@ -103,9 +141,9 @@ trait ParallelTesting { def errors = _errors override def doReport(m: MessageContainer)(implicit ctx: Context) = { - if (!suppress && m.level == ERROR) { + if (m.level == ERROR) { _errors = m :: _errors - System.err.println(messageAndPos(m.contained, m.pos, diagnosticLevel(m))) + if (!suppress) System.err.println(messageAndPos(m.contained, m.pos, diagnosticLevel(m))) } } } @@ -145,6 +183,11 @@ trait ParallelTesting { val run = new PosCompileRun(targetDirs, fromDir, flags).execute() assert(run.errors == 0, s"Expected no errors when compiling $fromDir") } + + def neg: Unit = assert( + !(new NegCompileRun(targetDirs, fromDir, flags).execute().didFail), + s"Wrong number of errors encountered when compiling $fromDir" + ) } def compileFilesInDir(f: String, flags: Array[String])(implicit outDirectory: String): CompilationTest = { diff --git a/tests/neg/i941.scala b/tests/neg/i941.scala index 2643c2546..fc29cc27d 100644 --- a/tests/neg/i941.scala +++ b/tests/neg/i941.scala @@ -1,7 +1,7 @@ object Test { def bar(tl: => String) = { - val x = tl _ //error + val x = tl _ // error val y = x _ // error val s: String = x() // error } diff --git a/tests/neg/instantiateAbstract.scala b/tests/neg/instantiateAbstract.scala index 10eeac64d..a2ff38ef4 100644 --- a/tests/neg/instantiateAbstract.scala +++ b/tests/neg/instantiateAbstract.scala @@ -15,7 +15,7 @@ object Test { @scala.annotation.Annotation type T = String // error @scala.annotation.Annotation val x = 1 // error - @scala.annotation.Annotation def f = 1 //error + @scala.annotation.Annotation def f = 1 // error (1: @scala.annotation.Annotation) // error |