Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add stacktrace #51

Merged
merged 1 commit into from
Apr 24, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,13 @@ public class Allure2ExportFormatter implements ExportFormatter {
private static final String FAILURE_MESSAGE = "message";
private static final String FAILURE_TIMESTAMP = "timestamp";

private static final String SOURCE_CODE_CONTEXT = "sourceCodeContext";
private static final String SYMBOL_INFO = "symbolInfo";
private static final String CALL_STACK = "callStack";
private static final String LOCATION = "location";
private static final String FILE_PATH = "filePath";
private static final String LINE_NUMBER = "lineNumber";

private static final String SUBACTIVITIES = "subactivities";

private static final String ATTACHMENTS = "attachments";
Expand Down Expand Up @@ -304,9 +311,11 @@ private Boolean isTopLevelFailure(final JsonNode activityFailure) {
private StepResult getFailureStep(final JsonNode activityFailure) {
final Long timestamp = parseDate(activityFailure.get(FAILURE_TIMESTAMP).get(VALUE).asText());
final String message = activityFailure.get(FAILURE_MESSAGE).get(VALUE).asText();
final String trace = getStackTrace(activityFailure);
final Status failedStatus = Status.FAILED;
final StatusDetails failedDetails = new StatusDetails()
.setMessage(message);
.setMessage(message)
.setTrace(trace);
final StepResult failureStep = new StepResult()
.setStatus(failedStatus)
.setName(message)
Expand All @@ -319,6 +328,32 @@ private StepResult getFailureStep(final JsonNode activityFailure) {
return failureStep;
}

private String getStackTrace(final JsonNode activityFailure) {
if (activityFailure.has(SOURCE_CODE_CONTEXT)) {
final JsonNode context = activityFailure.get(SOURCE_CODE_CONTEXT);
if (context.has(CALL_STACK)) {
final List<String> lines = new ArrayList<>();
for (JsonNode line : context.findValue(CALL_STACK).get(VALUES)) {
Optional.ofNullable(line.get(SYMBOL_INFO))
.map(v -> v.findValue(LOCATION))
.flatMap(this::getFileLineNumber)
.ifPresent(lines::add);
}
return String.join("\n", lines);
}
}
return null;
}

private Optional<String> getFileLineNumber(final JsonNode location) {
if (location.has(FILE_PATH) && location.has(LINE_NUMBER)) {
final String filePath = location.get(FILE_PATH).get(VALUE).asText();
final String lineNumber = location.get(LINE_NUMBER).get(VALUE).asText();
return Optional.of(String.format("%s:%s", filePath, lineNumber));
}
return Optional.empty();
}

private class StepContext {

private TestResult result;
Expand Down