Skip to content

Commit

Permalink
Fix #20: When calling System.exit() multiple times in a test, repor…
Browse files Browse the repository at this point in the history
…t the first exit code only (#21)
  • Loading branch information
tginsberg authored Oct 23, 2024
1 parent ab66a77 commit 61e7aae
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Change Log for `junit5-system-exit`

### 2.0.1
- TBD
- Bugfix: [[#20]](https://github.com/tginsberg/junit5-system-exit/issues/20): Multiple calls to `System.exit()` do not always report the first exit status code.

### 2.0.0
- Remove terminally deprecated `SecurityManager` approach for preventing `System.exit()` calls.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public static void handleExit(final int status) {
if (firstExitStatusCode == null) {
firstExitStatusCode = status;
}
throw new SystemExitPreventedException(status);
throw new SystemExitPreventedException(firstExitStatusCode);
} else {
System.exit(status);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,18 @@ void failsWhenNoExit() {
}
}

@Test
void multipleCallsToExit() {
assertThatCallsSystemExit(() -> {
try {
System.exit(42);
System.exit(1);
} catch (final Exception e) {
System.exit(2);
}
}).withExitCode(42);
}

private void justExit() {
System.exit(42);
}
Expand Down

0 comments on commit 61e7aae

Please sign in to comment.