From 098c0297b82cd3384b6f4cf8718d4e59732865f8 Mon Sep 17 00:00:00 2001 From: Nicolas Stucki Date: Tue, 16 Apr 2019 10:41:11 +0200 Subject: [PATCH] Dump output file when test fails --- .gitignore | 3 + .../dotty/tools/vulpix/ParallelTesting.scala | 55 +++++++++---------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/.gitignore b/.gitignore index 4c65f9b5126f..b0b14c04e17d 100644 --- a/.gitignore +++ b/.gitignore @@ -82,3 +82,6 @@ vscode-dotty/.vscode-test community-build/dotty-bootstrapped.version community-build/sbt-dotty-sbt + +# Vulpix output files +*.check.out diff --git a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala index fbd025b36b1c..9f6ac155f49f 100644 --- a/compiler/test/dotty/tools/vulpix/ParallelTesting.scala +++ b/compiler/test/dotty/tools/vulpix/ParallelTesting.scala @@ -514,10 +514,22 @@ trait ParallelTesting extends RunnerOrchestration { self => this } - protected def updateCheckFile(checkFile: JFile, lines: Seq[String]): Unit = { - val outFile = dotty.tools.io.File(checkFile.toPath) - outFile.writeAll(lines.mkString("", EOL, EOL)) - echo("Updated checkfile: " + checkFile.getPath) + protected def dumpOutputToFile(checkFile: JFile, lines: Seq[String]): Unit = { + if (updateCheckFiles) { + val outFile = dotty.tools.io.File(checkFile.toPath) + outFile.writeAll(lines.mkString("", EOL, EOL)) + echo("Updated checkfile: " + checkFile.getPath) + } else { + val outFile = dotty.tools.io.File(checkFile.toPath.resolveSibling(checkFile.toPath.getFileName + ".out")) + outFile.writeAll(lines.mkString("", EOL, EOL)) + echo( + s"""Test output dumped in: ${outFile.path} + | See diff of the checkfile + | > diff $checkFile $outFile + | Replace checkfile with current output output + | > mv $outFile $checkFile + """.stripMargin) + } } /** Returns all files in directory or the file if not a directory */ @@ -558,26 +570,15 @@ trait ParallelTesting extends RunnerOrchestration { self => .mkString(EOL) if (output.mkString(EOL) != check) { - val outFile = dotty.tools.io.File(checkFile.toPath).addExtension(".out") - if (updateCheckFiles) { - updateCheckFile(checkFile, output) - } else { - outFile.writeAll(output.mkString("", EOL, "")) - val msg = - s"""Output differed for test $name, use the following command to see the diff: - | > diff $checkFile $outFile - """.stripMargin - - echo(msg) - addFailureInstruction(msg) - - // Print build instructions to file and summary: - val buildInstr = testSource.buildInstructions(0, rep.warningCount) - addFailureInstruction(buildInstr) - - // Fail target: - failTestSource(testSource) - } + + dumpOutputToFile(checkFile, output) + + // Print build instructions to file and summary: + val buildInstr = testSource.buildInstructions(0, rep.warningCount) + addFailureInstruction(buildInstr) + + // Fail target: + failTestSource(testSource) } case _ => } @@ -651,8 +652,7 @@ trait ParallelTesting extends RunnerOrchestration { self => // Fail target: failTestSource(testSource) - if (updateCheckFiles) - updateCheckFile(checkFile.get, outputLines) + dumpOutputToFile(checkFile.get, outputLines) } } @@ -790,8 +790,7 @@ trait ParallelTesting extends RunnerOrchestration { self => val expexted = Source.fromFile(checkFile, "UTF-8").getLines().toList for (msg <- diffMessage(sourceName, actual, expexted)) { fail(msg) - if (updateCheckFiles) - updateCheckFile(checkFile, actual) + dumpOutputToFile(checkFile, actual) } }