Skip to content

Commit

Permalink
Dump output file when test fails
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolasstucki committed Apr 16, 2019
1 parent e7708c6 commit 098c029
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 28 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,6 @@ vscode-dotty/.vscode-test

community-build/dotty-bootstrapped.version
community-build/sbt-dotty-sbt

# Vulpix output files
*.check.out
55 changes: 27 additions & 28 deletions compiler/test/dotty/tools/vulpix/ParallelTesting.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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 _ =>
}
Expand Down Expand Up @@ -651,8 +652,7 @@ trait ParallelTesting extends RunnerOrchestration { self =>
// Fail target:
failTestSource(testSource)

if (updateCheckFiles)
updateCheckFile(checkFile.get, outputLines)
dumpOutputToFile(checkFile.get, outputLines)
}
}

Expand Down Expand Up @@ -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)
}
}

Expand Down

0 comments on commit 098c029

Please sign in to comment.