From 57a11776480ab5259281dd29777c45af9ea3ca78 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Fri, 31 Mar 2017 11:49:43 +0200 Subject: Improve summary report by dumping all to stdout on CI --- .../test/dotty/tools/dotc/CompilationTests.scala | 2 +- .../dotty/tools/dotc/ParallelSummaryReport.java | 8 +++++++- .../test/dotty/tools/dotc/ParallelTesting.scala | 23 ++++++++++++++++++++-- .../dotty/tools/dotc/reporting/TestReporter.scala | 15 ++++++++++---- 4 files changed, 40 insertions(+), 8 deletions(-) (limited to 'compiler/test') diff --git a/compiler/test/dotty/tools/dotc/CompilationTests.scala b/compiler/test/dotty/tools/dotc/CompilationTests.scala index 788e30aa3..742b93fae 100644 --- a/compiler/test/dotty/tools/dotc/CompilationTests.scala +++ b/compiler/test/dotty/tools/dotc/CompilationTests.scala @@ -12,7 +12,7 @@ import scala.util.matching.Regex class CompilationTests extends ParallelSummaryReport with ParallelTesting { import CompilationTests._ - def isInteractive: Boolean = !sys.env.contains("DRONE") + def isInteractive: Boolean = ParallelSummaryReport.isInteractive def testFilter: Option[Regex] = sys.props.get("dotty.partest.filter").map(r => new Regex(r)) diff --git a/compiler/test/dotty/tools/dotc/ParallelSummaryReport.java b/compiler/test/dotty/tools/dotc/ParallelSummaryReport.java index 9214e7d25..d32cda974 100644 --- a/compiler/test/dotty/tools/dotc/ParallelSummaryReport.java +++ b/compiler/test/dotty/tools/dotc/ParallelSummaryReport.java @@ -11,6 +11,8 @@ import dotty.tools.dotc.reporting.TestReporter$; * this class */ public class ParallelSummaryReport { + public final static boolean isInteractive = !System.getenv().containsKey("DRONE"); + private static TestReporter rep = TestReporter.reporter(-1); private static ArrayDeque failedTests = new ArrayDeque<>(); private static ArrayDeque reproduceInstructions = new ArrayDeque<>(); @@ -54,7 +56,8 @@ public class ParallelSummaryReport { .map(x -> " " + x) .forEach(rep::echo); - rep.flushToStdErr(); + // If we're compiling locally, we don't need reproduce instructions + if (isInteractive) rep.flushToStdErr(); rep.echo(""); @@ -62,6 +65,9 @@ public class ParallelSummaryReport { .stream() .forEach(rep::echo); + // If we're on the CI, we want everything + if (!isInteractive) rep.flushToStdErr(); + if (failed > 0) rep.flushToFile(); } } diff --git a/compiler/test/dotty/tools/dotc/ParallelTesting.scala b/compiler/test/dotty/tools/dotc/ParallelTesting.scala index 8e87c1170..990a856ca 100644 --- a/compiler/test/dotty/tools/dotc/ParallelTesting.scala +++ b/compiler/test/dotty/tools/dotc/ParallelTesting.scala @@ -51,6 +51,16 @@ trait ParallelTesting { self => def outDir: JFile def flags: Array[String] + + def title: String = self match { + case self: JointCompilationSource => + if (self.files.length > 1) name + else self.files.head.getPath + + case self: SeparateCompilationSource => + self.dir.getPath + } + /** Adds the flags specified in `newFlags0` if they do not already exist */ def withFlags(newFlags0: String*) = { val newFlags = newFlags0.toArray @@ -69,7 +79,11 @@ trait ParallelTesting { self => val maxLen = 80 var lineLen = 0 - sb.append(s"\n\nTest compiled with $errors error(s) and $warnings warning(s), the test can be reproduced by running:") + sb.append( + s"""| + |Test '$title' compiled with $errors error(s) and $warnings warning(s), + |the test can be reproduced by running:""".stripMargin + ) sb.append("\n\n./bin/dotc ") flags.foreach { arg => if (lineLen > maxLen) { @@ -447,6 +461,7 @@ trait ParallelTesting { self => private def verifyOutput(checkFile: JFile, dir: JFile, testSource: TestSource, warnings: Int) = { val outputLines = runMain(dir, testSource) val checkLines = Source.fromFile(checkFile).getLines.toArray + val sourceTitle = testSource.title def linesMatch = outputLines @@ -458,7 +473,11 @@ trait ParallelTesting { self => val diff = outputLines.zip(checkLines).map { case (act, exp) => DiffUtil.mkColoredLineDiff(exp, act) }.mkString("\n") - val msg = s"\nOutput from run test '$checkFile' did not match expected, output:\n$diff\n" + + val msg = + s"""|Output from '$sourceTitle' did not match check file. + |Diff ('e' is expected, 'a' is actual): + |""".stripMargin + diff + "\n" echo(msg) addFailureInstruction(msg) diff --git a/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala b/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala index 521cf9576..2d7e6c70a 100644 --- a/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala +++ b/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala @@ -25,10 +25,16 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M protected final val _messageBuf = mutable.ArrayBuffer.empty[String] final def flushToFile(): Unit = - _messageBuf.iterator.foreach(filePrintln) + _messageBuf + .iterator + .map(_.replaceAll("\u001b\\[.*?m", "")) + .foreach(filePrintln) final def flushToStdErr(): Unit = - _messageBuf.iterator.foreach(System.err.println) + _messageBuf + .iterator + .map(_.replaceAll("\u001b\\[.*?m", "")) + .foreach(System.err.println) final def inlineInfo(pos: SourcePosition): String = if (pos.exists) { @@ -75,10 +81,11 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M } object TestReporter { - private[this] val logWriter = { + private[this] lazy val logWriter = { val df = new SimpleDateFormat("yyyy-MM-dd-HH:mm") val timestamp = df.format(new Date) - new PrintWriter(new FileOutputStream(new JFile(s"../tests-$timestamp.log"), true)) + new JFile("../testlogs").mkdirs() + new PrintWriter(new FileOutputStream(new JFile(s"../testlogs/tests-$timestamp.log"), true)) } def writeToLog(str: String) = { -- cgit v1.2.3