@@ -27,7 +27,7 @@ import dotc.interfaces.Diagnostic.ERROR
27
27
import dotc .reporting .{Reporter , TestReporter }
28
28
import dotc .reporting .Diagnostic
29
29
import dotc .config .Config
30
- import dotc .util .{DiffUtil , SourceFile , SourcePosition , Spans }
30
+ import dotc .util .{DiffUtil , SourceFile , SourcePosition , Spans , NoSourcePosition }
31
31
import io .AbstractFile
32
32
import dotty .tools .vulpix .TestConfiguration .defaultOptions
33
33
@@ -504,20 +504,45 @@ trait ParallelTesting extends RunnerOrchestration { self =>
504
504
reporter
505
505
}
506
506
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. \n Full error output: \n ${barLine(start = true )}${errorLine(error)}" , sourcePos)
538
+ case error @ brokenClassPattern(filePath) =>
539
+ inError = true
540
+ diagnostics ::= Diagnostic .Error (s " $error\n Full 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
521
546
522
547
protected def compileWithOtherCompiler (compiler : String , files : Array [JFile ], flags : TestFlags , targetDir : JFile ): TestReporter =
523
548
val compilerDir = getCompiler(compiler).toString
@@ -528,18 +553,20 @@ trait ParallelTesting extends RunnerOrchestration { self =>
528
553
else o
529
554
}.mkString(JFile .pathSeparator)
530
555
556
+ val pageWidth = TestConfiguration .pageWidth - 20
531
557
val flags1 = flags.copy(defaultClassPath = substituteClasspath(flags.defaultClassPath))
532
558
.withClasspath(targetDir.getPath)
533
559
.and(" -d" , targetDir.getPath)
560
+ .and(" -pagewidth" , pageWidth.toString)
534
561
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 )
537
564
538
565
val command = Array (compilerDir + " /bin/scalac" ) ++ flags1.all ++ files.map(_.getPath)
539
566
val process = Runtime .getRuntime.exec(command)
540
567
val errorsText = Source .fromInputStream(process.getErrorStream).mkString
541
568
if process.waitFor() != 0 then
542
- val diagnostics = parseErrors(errorsText, compiler)
569
+ val diagnostics = parseErrors(errorsText, compiler, pageWidth )
543
570
diagnostics.foreach { diag =>
544
571
val context = (new ContextBase ).initialCtx
545
572
reporter.report(diag)(using context)
0 commit comments