Skip to content

Commit

Permalink
Integrated code lifecycle: Fix handling of empty error text nodes in …
Browse files Browse the repository at this point in the history
…XML result parser (#9204)
  • Loading branch information
just-max authored Aug 12, 2024
1 parent b54898e commit 985a918
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ private BuildResult parseTestResults(TarArchiveInputStream testResultsTarInputSt
}
catch (Exception e) {
// Exceptions due to one invalid file should not lead to the whole build to fail.
String msg = "Error while parsing report file" + fileName + ", ignoring.";
String msg = "Error while parsing report file " + fileName + ", ignoring.";
buildLogsMap.appendBuildLogEntry(buildJobId, msg);
log.warn(msg, e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,15 @@ static final class Failure {
private String detailedMessage;

private String extractMessage() {
return message != null ? message : detailedMessage;
if (message != null) {
return message;
}
else if (detailedMessage != null) {
return detailedMessage;
}
// empty text nodes are deserialized as null instead of a string, see: https://github.com/FasterXML/jackson-dataformat-xml/issues/565
// note that this workaround does not fix the issue entirely, as strings of only whitespace become the empty string
return "";
}

@JacksonXmlProperty(isAttribute = true, localName = "message")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,4 +187,25 @@ void testOutputInvalidXMLCharacters() throws IOException {
assertThat(test.getName()).isEqualTo("CompileLinkedList");
assertThat(test.getTestMessages().getFirst()).isEqualTo("Build for directory ../assignment/build failed. Returncode is 2.");
}

@Test
void testEmptyTestMessage() throws IOException {
String input = """
<testsuites>
<testsuite package="mwe-package" id="0" name="mwe-suite-name" timestamp="2024-08-09T12:34:56"
hostname="localhost" tests="1" failures="1" errors="0" time="0">
<properties></properties>
<testcase name="mwe-name" classname="mwe-class" time="0">
<failure type="empty"></failure>
</testcase>
</testsuite>
</testsuites>
""";

TestResultXmlParser.processTestResultFile(input, failedTests, successfulTests);
assertThat(failedTests).hasSize(1);
var test = failedTests.getFirst();
assertThat(test.getName()).isEqualTo("mwe-name");
assertThat(test.getTestMessages()).hasSize(1).contains("");
}
}

0 comments on commit 985a918

Please sign in to comment.