From c9e1bc5b6324d2a896d731eeec32bdd941d1629b Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Thu, 13 Apr 2017 09:41:12 +0200 Subject: Fix #2243: improve failing test output --- compiler/test/dotty/tools/vulpix/SummaryReport.scala | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'compiler/test/dotty/tools/vulpix/SummaryReport.scala') diff --git a/compiler/test/dotty/tools/vulpix/SummaryReport.scala b/compiler/test/dotty/tools/vulpix/SummaryReport.scala index 8f3047f49..efca94bba 100644 --- a/compiler/test/dotty/tools/vulpix/SummaryReport.scala +++ b/compiler/test/dotty/tools/vulpix/SummaryReport.scala @@ -95,7 +95,7 @@ final class SummaryReport extends SummaryReporting { startingMessages.foreach(rep.append) - failedTests.map(x => " " + x).foreach(rep.append) + failedTests.map(x => s" $x\n").foreach(rep.append) // If we're compiling locally, we don't need instructions on how to // reproduce failures -- cgit v1.2.3 From 7e33bc4c11ffc5e6ecc6fb7bcbfd54c497db2c02 Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Thu, 13 Apr 2017 10:09:37 +0200 Subject: Fix #2242: let user know which file got logged to --- .../dotty/tools/dotc/reporting/TestReporter.scala | 28 ++++++++++++++++++---- .../test/dotty/tools/vulpix/SummaryReport.scala | 11 +++++---- 2 files changed, 29 insertions(+), 10 deletions(-) (limited to 'compiler/test/dotty/tools/vulpix/SummaryReport.scala') diff --git a/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala b/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala index 7952ed728..213181b56 100644 --- a/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala +++ b/compiler/test/dotty/tools/dotc/reporting/TestReporter.scala @@ -91,23 +91,41 @@ extends Reporter with UniqueMessagePositions with HideNonSensicalMessages with M } object TestReporter { - val logWriter = { + private[this] var outFile: JFile = _ + private[this] var logWriter: PrintWriter = _ + + private[this] def initLog() = if (logWriter eq null) { val df = new SimpleDateFormat("yyyy-MM-dd-HH:mm") val timestamp = df.format(new Date) new JFile("../testlogs").mkdirs() - new PrintWriter(new FileOutputStream(new JFile(s"../testlogs/tests-$timestamp.log"), true)) + outFile = new JFile(s"../testlogs/tests-$timestamp.log") + logWriter = new PrintWriter(new FileOutputStream(outFile, true)) } - def writeToLog(str: String) = { + def logPrintln(str: String) = { + initLog() logWriter.println(str) logWriter.flush() } + def logPrint(str: String): Unit = { + initLog() + logWriter.println(str) + } + + def logFlush(): Unit = + if (logWriter ne null) logWriter.flush() + + def logPath: String = { + initLog() + outFile.getCanonicalPath + } + def reporter(ps: PrintStream, logLevel: Int): TestReporter = - new TestReporter(new PrintWriter(ps, true), writeToLog, logLevel) + new TestReporter(new PrintWriter(ps, true), logPrintln, logLevel) def simplifiedReporter(writer: PrintWriter): TestReporter = { - val rep = new TestReporter(writer, writeToLog, WARNING) { + val rep = new TestReporter(writer, logPrintln, WARNING) { /** Prints the message with the given position indication in a simplified manner */ override def printMessageAndPos(m: MessageContainer, extra: String)(implicit ctx: Context): Unit = { def report() = { diff --git a/compiler/test/dotty/tools/vulpix/SummaryReport.scala b/compiler/test/dotty/tools/vulpix/SummaryReport.scala index efca94bba..81da634f7 100644 --- a/compiler/test/dotty/tools/vulpix/SummaryReport.scala +++ b/compiler/test/dotty/tools/vulpix/SummaryReport.scala @@ -102,10 +102,11 @@ final class SummaryReport extends SummaryReporting { if (isInteractive) { println(rep.toString) if (failed > 0) println { - """| - |---------------------------------------------------------- - |Note: reproduction instructed have been dumped to log file - |----------------------------------------------------------""".stripMargin + s"""| + |-------------------------------------------------------------------------------- + |Note - reproduction instructions have been dumped to log file: + | ${TestReporter.logPath} + |--------------------------------------------------------------------------------""".stripMargin } } @@ -116,7 +117,7 @@ final class SummaryReport extends SummaryReporting { // If we're on the CI, we want everything if (!isInteractive) println(rep.toString) - TestReporter.writeToLog(rep.toString) + TestReporter.logPrintln(rep.toString) // Perform cleanup callback: if (cleanUps.nonEmpty) cleanUps.foreach(_.apply()) -- cgit v1.2.3 From 64db05bc9aa5e82e68209ec4f72b1f87279c8c3a Mon Sep 17 00:00:00 2001 From: Felix Mulder Date: Thu, 13 Apr 2017 10:10:14 +0200 Subject: Fix #2244: make sure logging goes through appropriate interface --- compiler/test/dotty/tools/vulpix/ParallelTesting.scala | 7 ++----- compiler/test/dotty/tools/vulpix/SummaryReport.scala | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'compiler/test/dotty/tools/vulpix/SummaryReport.scala') diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index 1315da3a4..355a4046e 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -192,8 +192,6 @@ trait ParallelTesting extends RunnerOrchestration { self => /** A runnable that logs its contents in a buffer */ trait LoggedRunnable extends Runnable { - import TestReporter.logWriter - /** Instances of `LoggedRunnable` implement this method instead of the * `run` method */ @@ -212,8 +210,7 @@ trait ParallelTesting extends RunnerOrchestration { self => final def run(): Unit = { checkTestSource() - logBuffer.iterator.foreach(logWriter.println) - logWriter.flush() + summaryReport.echoToLog(logBuffer.iterator) } } @@ -309,7 +306,7 @@ trait ParallelTesting extends RunnerOrchestration { self => protected def tryCompile(testSource: TestSource)(op: => Unit): Unit = try { val testing = s"Testing ${testSource.title}" - TestReporter.logWriter.println(testing) + summaryReport.echoToLog(testing) if (!isInteractive) realStdout.println(testing) op } catch { diff --git a/compiler/test/dotty/tools/vulpix/SummaryReport.scala b/compiler/test/dotty/tools/vulpix/SummaryReport.scala index 81da634f7..678d88809 100644 --- a/compiler/test/dotty/tools/vulpix/SummaryReport.scala +++ b/compiler/test/dotty/tools/vulpix/SummaryReport.scala @@ -34,6 +34,12 @@ trait SummaryReporting { /** Echo the summary report to the appropriate locations */ def echoSummary(): Unit + + /** Echoes *immediately* to file */ + def echoToLog(msg: String): Unit + + /** Echoes contents of `it` to file *immediately* then flushes */ + def echoToLog(it: Iterator[String]): Unit } /** A summary report that doesn't do anything */ @@ -45,6 +51,8 @@ final class NoSummaryReport extends SummaryReporting { def addStartingMessage(msg: String): Unit = () def addCleanup(f: () => Unit): Unit = () def echoSummary(): Unit = () + def echoToLog(msg: String): Unit = () + def echoToLog(it: Iterator[String]): Unit = () } /** A summary report that logs to both stdout and the `TestReporter.logWriter` @@ -122,6 +130,14 @@ final class SummaryReport extends SummaryReporting { // Perform cleanup callback: if (cleanUps.nonEmpty) cleanUps.foreach(_.apply()) } + + def echoToLog(msg: String): Unit = + TestReporter.logPrintln(msg) + + def echoToLog(it: Iterator[String]): Unit = { + it.foreach(TestReporter.logPrint) + TestReporter.logFlush() + } } object SummaryReport { -- cgit v1.2.3