Skip to content

Commit 22fda02

Browse files
Checkfiles use actual error message format
1 parent 3ef991d commit 22fda02

File tree

2 files changed

+22
-22
lines changed

2 files changed

+22
-22
lines changed

compiler/test/dotty/tools/dotc/reporting/TestReporter.scala

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ package dotty.tools
22
package dotc
33
package reporting
44

5-
import java.io.{ PrintStream, PrintWriter, File => JFile, FileOutputStream }
5+
import java.io.{ PrintStream, PrintWriter, File => JFile, FileOutputStream, StringWriter }
66
import java.text.SimpleDateFormat
77
import java.util.Date
88
import core.Decorators._
@@ -26,6 +26,10 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
2626
protected final val _messageBuf = mutable.ArrayBuffer.empty[String]
2727
final def messages: Iterator[String] = _messageBuf.iterator
2828

29+
protected final val _consoleBuf = new StringWriter
30+
protected final val _consoleReporter = new ConsoleReporter(null, new PrintWriter(_consoleBuf))
31+
final def consoleOutput: String = _consoleBuf.toString
32+
2933
private[this] var _didCrash = false
3034
final def compilerCrashed: Boolean = _didCrash
3135

@@ -63,6 +67,7 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
6367
}
6468

6569
override def doReport(m: MessageContainer)(implicit ctx: Context): Unit = {
70+
6671
// Here we add extra information that we should know about the error message
6772
val extra = m.contained() match {
6873
case pm: PatternMatchExhaustivity => s": ${pm.uncovered}"
@@ -72,6 +77,7 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
7277
m match {
7378
case m: Error => {
7479
_errorBuf.append(m)
80+
_consoleReporter.doReport(m)
7581
printMessageAndPos(m, extra)
7682
}
7783
case m =>

compiler/test/dotty/tools/vulpix/ParallelTesting.scala

Lines changed: 15 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,10 @@ trait ParallelTesting extends RunnerOrchestration { self =>
9090
sb.append(
9191
s"""|
9292
|Test '$title' compiled with $errors error(s) and $warnings warning(s),
93-
|the test can be reproduced by running:""".stripMargin
93+
|the test can be reproduced by running from SBT (prefix it with ./bin/ if you
94+
|want to run from the command line):""".stripMargin
9495
)
95-
sb.append("\n\n./bin/dotc ")
96+
sb.append("\n\ndotc ")
9697
flags.all.foreach { arg =>
9798
if (lineLen > maxLen) {
9899
sb.append(" \\\n ")
@@ -225,11 +226,10 @@ trait ParallelTesting extends RunnerOrchestration { self =>
225226
* Checks if the given actual lines are the same as the ones in the check file.
226227
* If not, fails the test.
227228
*/
228-
final def diffTest(testSource: TestSource, checkFile: JFile, actual: List[String]) = {
229+
final def diffTest(testSource: TestSource, checkFile: JFile, actual: List[String], reporters: Seq[TestReporter], logger: LoggedRunnable) = {
229230
val expected = Source.fromFile(checkFile, "UTF-8").getLines().toList
230231
for (msg <- diffMessage(testSource.title, actual, expected)) {
231-
echo(msg)
232-
failTestSource(testSource)
232+
onFailure(testSource, reporters, logger, Some(msg))
233233
dumpOutputToFile(checkFile, actual)
234234
}
235235
}
@@ -609,11 +609,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
609609
}
610610
}
611611

612-
private def verifyOutput(checkFile: Option[JFile], dir: JFile, testSource: TestSource, warnings: Int) = {
612+
private def verifyOutput(checkFile: Option[JFile], dir: JFile, testSource: TestSource, warnings: Int, reporters: Seq[TestReporter], logger: LoggedRunnable) = {
613613
if (Properties.testsNoRun) addNoRunWarning()
614614
else runMain(testSource.runClassPath) match {
615615
case Success(output) => checkFile match {
616-
case Some(file) if file.exists => diffTest(testSource, file, output.linesIterator.toList)
616+
case Some(file) if file.exists => diffTest(testSource, file, output.linesIterator.toList, reporters, logger)
617617
case _ =>
618618
}
619619
case Failure(output) =>
@@ -627,7 +627,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
627627
}
628628

629629
override def onSuccess(testSource: TestSource, reporters: Seq[TestReporter], logger: LoggedRunnable) =
630-
verifyOutput(checkFile(testSource), testSource.outDir, testSource, countWarnings(reporters))
630+
verifyOutput(checkFile(testSource), testSource.outDir, testSource, countWarnings(reporters), reporters, logger)
631631
}
632632

633633
private final class NegTest(testSources: List[TestSource], times: Int, threadLimit: Option[Int], suppressAllOutput: Boolean)(implicit summaryReport: SummaryReporting)
@@ -649,11 +649,10 @@ trait ParallelTesting extends RunnerOrchestration { self =>
649649
}
650650

651651
override def onSuccess(testSource: TestSource, reporters: Seq[TestReporter], logger: LoggedRunnable): Unit =
652-
checkFile(testSource).foreach(diffTest(testSource, _, reporterOutputLines(reporters)))
652+
checkFile(testSource).foreach(diffTest(testSource, _, reporterOutputLines(reporters), reporters, logger))
653653

654654
def reporterOutputLines(reporters: Seq[TestReporter]): List[String] =
655-
reporters.flatMap(_.allErrors).sortBy(_.pos.source.toString).flatMap { error =>
656-
(error.pos.span.toString + " in " + error.pos.source.file.name) :: error.getMessage().linesIterator.toList }.toList
655+
reporters.flatMap(_.consoleOutput.split("\n")).toList
657656

658657
// In neg-tests we allow two types of error annotations,
659658
// "nopos-error" which doesn't care about position and "error" which
@@ -715,16 +714,11 @@ trait ParallelTesting extends RunnerOrchestration { self =>
715714
def linesMatch =
716715
(outputLines, checkLines).zipped.forall(_ == _)
717716

718-
if (outputLines.length != checkLines.length || !linesMatch) {
719-
// Print diff to files and summary:
720-
val diff = DiffUtil.mkColoredLineDiff(checkLines :+ DiffUtil.EOF, outputLines :+ DiffUtil.EOF)
721-
722-
Some(
723-
s"""|Output from '$sourceTitle' did not match check file.
724-
|Diff (expected on the left, actual right):
725-
|""".stripMargin + diff + "\n")
726-
} else None
727-
717+
if (outputLines.length != checkLines.length || !linesMatch) Some(
718+
s"""|Output from '$sourceTitle' did not match check file. Actual output:
719+
|${outputLines.mkString(EOL)}
720+
|""".stripMargin + "\n")
721+
else None
728722
}
729723

730724
/** The `CompilationTest` is the main interface to `ParallelTesting`, it

0 commit comments

Comments
 (0)