Skip to content

Commit 4feace8

Browse files
authored
Fix ParameterizedTests suppressing PreconditionViolationException (#1)
Fixes codewars/runner#230
1 parent f4306ba commit 4feace8

File tree

1 file changed

+20
-1
lines changed

1 file changed

+20
-1
lines changed

src/main/java/com/codewars/junit5/CodewarsListener.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,14 @@ public void executionFinished(TestIdentifier testIdentifier, TestExecutionResult
122122
} else {
123123
System.out.println("\n<FAILED::>Failed for unknown cause");
124124
}
125+
} else {
126+
++failures;
127+
Optional<Throwable> th = testExecutionResult.getThrowable();
128+
if (th.isPresent()) {
129+
outputError("Crashed", th.get());
130+
} else {
131+
System.out.println("\n<ERROR::>Unexpected error occurred");
132+
}
125133
}
126134
System.out.printf("\n<COMPLETEDIN::>%d\n", getDuration(testIdentifier));
127135
break;
@@ -161,6 +169,17 @@ private static void outputFailure(String kind, Throwable throwable) {
161169
System.out.printf("\n<LOG:ESC:-Stack Trace>%s\n", formatMessage(readStackTrace(throwable)));
162170
}
163171

172+
private static void outputError(String kind, Throwable throwable) {
173+
String msg = throwable.getMessage();
174+
String formattedStackTrace = formatMessage(readStackTrace(throwable));
175+
if (msg == null) {
176+
System.out.printf("\n<ERROR::>Test %s<:LF:><:LF:>%s\n", kind, formattedStackTrace);
177+
} else {
178+
String formattedMessage = formatMessage(msg);
179+
System.out.printf("\n<ERROR::>%s<:LF:><:LF:>%s\n", formattedMessage, formattedStackTrace);
180+
}
181+
}
182+
164183
// Read the stacktrace of the supplied {@link Throwable} into a String.
165184
// https://github.com/junit-team/junit5/blob/946c5980074f466de0688297a6d661d32679599a/junit-platform-commons/src/main/java/org/junit/platform/commons/util/ExceptionUtils.java#L76
166185
private static String readStackTrace(Throwable throwable) {
@@ -186,7 +205,7 @@ private long getDuration(TestIdentifier testIdentifier) {
186205
}
187206

188207
private static String formatMessage(final String s) {
189-
return (s == null) ? "" : s.replaceAll("\n", "<:LF:>");
208+
return (s == null) ? "" : s.replaceAll(System.lineSeparator(), "<:LF:>");
190209
}
191210

192211
private NavigableSet<String> reportEntries(TestIdentifier testIdentifier) {

0 commit comments

Comments
 (0)