Skip to content

Commit

Permalink
Include value from Exception.stacktrace if available
Browse files Browse the repository at this point in the history
  • Loading branch information
mpkorstanje committed Mar 23, 2024
1 parent a73086b commit 52ee83c
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 7 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Added
- Include value from Exception.stacktrace if available ([#30](https://github.com/cucumber/cucumber-junit-xml-formatter/pull/30), M.P. Korstanje)

### Fixed
- Do not overwrite results of retried tests ([#29](https://github.com/cucumber/cucumber-junit-xml-formatter/pull/29), M.P. Korstanje)

Expand Down
2 changes: 1 addition & 1 deletion java/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@
<dependency>
<groupId>io.cucumber</groupId>
<artifactId>messages</artifactId>
<version>[21.0.1,25.0.0)</version>
<version>[24.0.0,25.0.0)</version>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,8 +100,10 @@ private void writeNonPassedElement(EscapingXmlStreamWriter writer, TestCaseStart
Optional<String> message = result.getMessage();
Optional<String> exceptionType = result.getException().map(Exception::getType);
Optional<String> exceptionMessage = result.getException().flatMap(Exception::getMessage);
Optional<String> exceptionStackTrace = result.getException().flatMap(Exception::getStackTrace);

if (message.isPresent()) {
boolean hasMessageOrStackTrace = message.isPresent() || exceptionStackTrace.isPresent();
if (hasMessageOrStackTrace) {
writer.writeStartElement(elementName);
} else {
writer.writeEmptyElement(elementName);
Expand All @@ -113,13 +115,21 @@ private void writeNonPassedElement(EscapingXmlStreamWriter writer, TestCaseStart
if (exceptionMessage.isPresent()) {
writer.writeAttribute("message", exceptionMessage.get());
}
if (message.isPresent()) {
writer.newLine();
writer.writeCData(message.get());
writer.newLine();
if (hasMessageOrStackTrace) {
if (exceptionStackTrace.isPresent()) {
writer.newLine();
writer.writeCData(exceptionStackTrace.get());
writer.newLine();
} else {
// Fall back to message for older implementations
// that put the stack trace in the message
writer.newLine();
writer.writeCData(message.get());
writer.newLine();
}
}

if (message.isPresent()) {
if (hasMessageOrStackTrace) {
writer.writeEndElement();
}
writer.newLine();
Expand Down

0 comments on commit 52ee83c

Please sign in to comment.