Skip to content

Commit 30a2333

Browse files
Merge pull request #14339 from dotty-staging/fix-#14303
Output other compiler errors
2 parents bf78ea9 + 8b2faa5 commit 30a2333

File tree

4 files changed

+54
-19
lines changed

4 files changed

+54
-19
lines changed

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

Lines changed: 45 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import dotc.interfaces.Diagnostic.ERROR
2727
import dotc.reporting.{Reporter, TestReporter}
2828
import dotc.reporting.Diagnostic
2929
import dotc.config.Config
30-
import dotc.util.{DiffUtil, SourceFile, SourcePosition, Spans}
30+
import dotc.util.{DiffUtil, SourceFile, SourcePosition, Spans, NoSourcePosition}
3131
import io.AbstractFile
3232
import dotty.tools.vulpix.TestConfiguration.defaultOptions
3333

@@ -504,20 +504,45 @@ trait ParallelTesting extends RunnerOrchestration { self =>
504504
reporter
505505
}
506506

507-
private def parseErrors(errorsText: String, compilerVersion: String) =
508-
val errorPattern = """.*Error: (.*\.scala):(\d+):(\d+).*""".r
509-
errorsText.linesIterator.toSeq.collect {
510-
case errorPattern(filePath, line, column) =>
511-
val lineNum = line.toInt
512-
val columnNum = column.toInt
513-
val abstractFile = AbstractFile.getFile(filePath)
514-
val sourceFile = SourceFile(abstractFile, Codec.UTF8)
515-
val offset = sourceFile.lineToOffset(lineNum - 1) + columnNum - 1
516-
val span = Spans.Span(offset)
517-
val sourcePos = SourcePosition(sourceFile, span)
518-
519-
Diagnostic.Error(s"Compilation of $filePath with Scala $compilerVersion failed at line: $line, column: $column. Full error output:\n\n$errorsText\n", sourcePos)
520-
}
507+
private def parseErrors(errorsText: String, compilerVersion: String, pageWidth: Int) =
508+
val errorPattern = """^.*Error: (.*\.scala):(\d+):(\d+).*""".r
509+
val brokenClassPattern = """^class file (.*) is broken.*""".r
510+
val warnPattern = """^.*Warning: (.*\.scala):(\d+):(\d+).*""".r
511+
val summaryPattern = """\d+ (?:warning|error)s? found""".r
512+
val indent = " "
513+
var diagnostics = List.empty[Diagnostic.Error]
514+
def barLine(start: Boolean) = s"$indent${if start then "" else ""}${"" * pageWidth}${if start then "" else ""}\n"
515+
def errorLine(line: String) = s"$indent${String.format(s"%-${pageWidth}s", stripAnsi(line))}\n"
516+
def stripAnsi(str: String): String = str.replaceAll("\u001b\\[\\d+m", "")
517+
def addToLast(str: String): Unit =
518+
diagnostics match
519+
case head :: tail =>
520+
diagnostics = Diagnostic.Error(s"${head.msg.rawMessage}$str", head.pos) :: tail
521+
case Nil =>
522+
var inError = false
523+
for line <- errorsText.linesIterator do
524+
line match
525+
case error @ warnPattern(filePath, line, column) =>
526+
inError = false
527+
case error @ errorPattern(filePath, line, column) =>
528+
inError = true
529+
val lineNum = line.toInt
530+
val columnNum = column.toInt
531+
val abstractFile = AbstractFile.getFile(filePath)
532+
val sourceFile = SourceFile(abstractFile, Codec.UTF8)
533+
val offset = sourceFile.lineToOffset(lineNum - 1) + columnNum - 1
534+
val span = Spans.Span(offset)
535+
val sourcePos = SourcePosition(sourceFile, span)
536+
addToLast(barLine(start = false))
537+
diagnostics ::= Diagnostic.Error(s"Compilation of $filePath with Scala $compilerVersion failed at line: $line, column: $column.\nFull error output:\n${barLine(start = true)}${errorLine(error)}", sourcePos)
538+
case error @ brokenClassPattern(filePath) =>
539+
inError = true
540+
diagnostics ::= Diagnostic.Error(s"$error\nFull error output:\n${barLine(start = true)}${errorLine(error)}", NoSourcePosition)
541+
case summaryPattern() => // Ignored
542+
case line if inError => addToLast(errorLine(line))
543+
case _ =>
544+
addToLast(barLine(start = false))
545+
diagnostics.reverse
521546

522547
protected def compileWithOtherCompiler(compiler: String, files: Array[JFile], flags: TestFlags, targetDir: JFile): TestReporter =
523548
val compilerDir = getCompiler(compiler).toString
@@ -528,18 +553,20 @@ trait ParallelTesting extends RunnerOrchestration { self =>
528553
else o
529554
}.mkString(JFile.pathSeparator)
530555

556+
val pageWidth = TestConfiguration.pageWidth - 20
531557
val flags1 = flags.copy(defaultClassPath = substituteClasspath(flags.defaultClassPath))
532558
.withClasspath(targetDir.getPath)
533559
.and("-d", targetDir.getPath)
560+
.and("-pagewidth", pageWidth.toString)
534561

535-
val dummyStream = new PrintStream(new ByteArrayOutputStream())
536-
val reporter = TestReporter.reporter(dummyStream, ERROR)
562+
val reporter = TestReporter.reporter(realStdout, logLevel =
563+
if (suppressErrors || suppressAllOutput) ERROR + 1 else ERROR)
537564

538565
val command = Array(compilerDir + "/bin/scalac") ++ flags1.all ++ files.map(_.getPath)
539566
val process = Runtime.getRuntime.exec(command)
540567
val errorsText = Source.fromInputStream(process.getErrorStream).mkString
541568
if process.waitFor() != 0 then
542-
val diagnostics = parseErrors(errorsText, compiler)
569+
val diagnostics = parseErrors(errorsText, compiler, pageWidth)
543570
diagnostics.foreach { diag =>
544571
val context = (new ContextBase).initialCtx
545572
reporter.report(diag)(using context)

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ import java.io.File
66

77
object TestConfiguration {
88

9+
val pageWidth = 120
10+
911
val noCheckOptions = Array(
10-
"-pagewidth", "120",
12+
"-pagewidth", pageWidth.toString,
1113
"-color:never",
1214
"-Xtarget", defaultTarget
1315
)

tests/neg/i14303/A_1_c3.0.0.scala

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
def a: Int = {
2+
3
3+
4
4+
}
5+
def f: Int = match // error // error

tests/neg/i14303/B_2.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
def test() = f // error

0 commit comments

Comments
 (0)