Created
October 23, 2018 17:55
-
-
Save modille/d0d64fcf853eee9eb85b8862c28e5fb4 to your computer and use it in GitHub Desktop.
Log failures in an error format that vim and other tooling can use
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
test { | |
// Log failures in an error format that vim and other tooling can use | |
// Something like: | |
// FILENAME:LINE_NUMBER failed: MESSAGE | |
// For example: | |
// src/test/java/TestFoo.java:42 failed: junit.framework.ComparisonFailure: null expected:<[b]ar> but was:<[B]ar> | |
afterTest { desc, result -> | |
if (result.resultType == TestResult.ResultType.FAILURE) { | |
result.getException().each { e -> | |
e.getStackTrace().each { el -> | |
if (el.getFileName()) { | |
// Take the filename from the stacktrace line and look up the corresponding project file | |
def projectFiles = new FileNameFinder().getFileNames(rootProject.projectDir.getPath(), '**/' + el.getFileName()) | |
projectFiles.each { | |
// Build up the path to the file relative to the project root | |
def relativePath = rootProject.projectDir.toPath().relativize(new File(it).toPath()) | |
logger.lifecycle(relativePath.toString() + ":" + el.getLineNumber() + " failed: " + e.getMessage()) | |
} | |
} | |
} | |
} | |
} | |
} | |
} | |
integrationTest { | |
// Log failures in an error format that vim and other tooling can use | |
// Something like: | |
// FILENAME:LINE_NUMBER failed: MESSAGE | |
// For example: | |
// src/test/java/TestFoo.java:42 failed: junit.framework.ComparisonFailure: null expected:<[b]ar> but was:<[B]ar> | |
afterTest { desc, result -> | |
if (result.resultType == TestResult.ResultType.FAILURE) { | |
result.getException().each { e -> | |
e.getStackTrace().each { el -> | |
if (el.getFileName()) { | |
// Take the filename from the stacktrace line and look up the corresponding project file | |
def projectFiles = new FileNameFinder().getFileNames(rootProject.projectDir.getPath(), '**/' + el.getFileName()) | |
projectFiles.each { | |
// Build up the path to the file relative to the project root | |
def relativePath = rootProject.projectDir.toPath().relativize(new File(it).toPath()) | |
logger.lifecycle(relativePath.toString() + ":" + el.getLineNumber() + " failed: " + e.getMessage()) | |
} | |
} | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment