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 /compiler/test/dotty/tools/dotc/ParallelTesting.scala | |
parent | fc2bdc85381d93dcf7010cf13347569e14efb29c (diff) | |
download | dotty-57f8d1b1f7962f99cf27501994b1440e369fe597.tar.gz dotty-57f8d1b1f7962f99cf27501994b1440e369fe597.tar.bz2 dotty-57f8d1b1f7962f99cf27501994b1440e369fe597.zip |
Add neg testing capability to ParallelTesting
Diffstat (limited to 'compiler/test/dotty/tools/dotc/ParallelTesting.scala')
-rw-r--r-- | compiler/test/dotty/tools/dotc/ParallelTesting.scala | 47 |
1 files changed, 45 insertions, 2 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 = { |