Skip to content

Commit 171f4c9

Browse files
Use ConsoleReporter instead of hacking TestReporter
1 parent 4de59b8 commit 171f4c9

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

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

Lines changed: 10 additions & 6 deletions
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._
@@ -20,14 +20,16 @@ class TestReporter protected (outWriter: PrintWriter, filePrintln: String => Uni
2020
extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with MessageRendering {
2121
import MessageContainer._
2222

23-
protected final val _errorBuf = mutable.ArrayBuffer.empty[(MessageContainer, String)]
24-
final def errors: Iterator[(MessageContainer, String)] = _errorBuf.iterator
25-
def logError(err: Error)(implicit ctx: Context) =
26-
_errorBuf.append(err -> messageAndPos(err.contained(), err.pos, diagnosticLevel(err)))
23+
protected final val _errorBuf = mutable.ArrayBuffer.empty[MessageContainer]
24+
final def errors: Iterator[MessageContainer] = _errorBuf.iterator
2725

2826
protected final val _messageBuf = mutable.ArrayBuffer.empty[String]
2927
final def messages: Iterator[String] = _messageBuf.iterator
3028

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+
3133
private[this] var _didCrash = false
3234
final def compilerCrashed: Boolean = _didCrash
3335

@@ -65,6 +67,8 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
6567
}
6668

6769
override def doReport(m: MessageContainer)(implicit ctx: Context): Unit = {
70+
_consoleReporter.doReport(m)
71+
6872
// Here we add extra information that we should know about the error message
6973
val extra = m.contained() match {
7074
case pm: PatternMatchExhaustivity => s": ${pm.uncovered}"
@@ -73,7 +77,7 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M
7377

7478
m match {
7579
case m: Error => {
76-
logError(m)
80+
_errorBuf.append(m)
7781
printMessageAndPos(m, extra)
7882
}
7983
case m =>

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,10 @@ trait ParallelTesting extends RunnerOrchestration { self =>
9191
sb.append(
9292
s"""|
9393
|Test '$title' compiled with $errors error(s) and $warnings warning(s),
94-
|the test can be reproduced by running:""".stripMargin
94+
|the test can be reproduced by running from SBT (prefix it with ./bin/ if you
95+
|want to run from the command line):""".stripMargin
9596
)
96-
sb.append("\n\n./bin/dotc ")
97+
sb.append("\n\ndotc ")
9798
flags.all.foreach { arg =>
9899
if (lineLen > maxLen) {
99100
sb.append(delimiter)
@@ -638,7 +639,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
638639
def compilerCrashed = reporters.exists(_.compilerCrashed)
639640
lazy val (errorMap, expectedErrors) = getErrorMapAndExpectedCount(testSource.sourceFiles)
640641
lazy val actualErrors = reporters.foldLeft(0)(_ + _.errorCount)
641-
def hasMissingAnnotations = getMissingExpectedErrors(errorMap, reporters.iterator.flatMap(_.errors).map(_._1))
642+
def hasMissingAnnotations = getMissingExpectedErrors(errorMap, reporters.iterator.flatMap(_.errors))
642643

643644
if (compilerCrashed) Some(s"Compiler crashed when compiling: ${testSource.title}" )
644645
else if (actualErrors == 0) Some(s"\nNo errors found when compiling neg test $testSource" )
@@ -652,7 +653,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
652653
checkFile(testSource).foreach(diffTest(testSource, _, reporterOutputLines(reporters), reporters, logger))
653654

654655
def reporterOutputLines(reporters: Seq[TestReporter]): List[String] =
655-
reporters.flatMap(_.errors).sortBy(_._1.pos.source.toString).map(_._2).toList
656+
reporters.flatMap(_.consoleOutput.split("\n")).toList
656657

657658
// In neg-tests we allow two types of error annotations,
658659
// "nopos-error" which doesn't care about position and "error" which

0 commit comments

Comments
 (0)