Skip to content

Commit

Permalink
Unify messages about exit codes in StandaloneTests
Browse files Browse the repository at this point in the history
Some tests in StandaloneTests provide concatenation of standard output
and standard error as a message for the assertion about exit code, while
other tests provide only standard output.  Some use method
de.sormuras.bartholdy.Result#getOutput while others use method
de.sormuras.bartholdy.Result#getOutputLines.

Unify these approaches by replacing the messages with a supplier that
gives a) a human-readable message about exit codes, and b) both standard
output and standard error.
  • Loading branch information
rybak committed Aug 6, 2023
1 parent 4d51cd6 commit 3f2590d
Showing 1 changed file with 12 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ void listAllObservableEngines() {
.addArguments("engines", "--disable-banner").build() //
.run(false);

assertEquals(0, result.getExitCode(), String.join("\n", result.getOutputLines("out")));
assertEquals(0, result.getExitCode(), () -> getExitCodeMessage(result));

var jupiterVersion = Helper.version("junit-jupiter-engine");
var suiteVersion = Helper.version("junit-platform-suite-engine");
Expand Down Expand Up @@ -98,7 +98,7 @@ void compile() throws Exception {
.addArguments(workspace.resolve("src/standalone/VintageIntegration.java")).build() //
.run();

assertEquals(0, result.getExitCode(), result.getOutput("out") + result.getOutput("err"));
assertEquals(0, result.getExitCode(), () -> getExitCodeMessage(result));
assertTrue(result.getOutput("out").isEmpty());
assertTrue(result.getOutput("err").isEmpty());

Expand Down Expand Up @@ -327,7 +327,7 @@ private static Result discover(String... args) {
.build() //
.run(false);

assertEquals(0, result.getExitCode(), String.join("\n", result.getOutputLines("out")));
assertEquals(0, result.getExitCode(), () -> getExitCodeMessage(result));
return result;
}

Expand All @@ -349,7 +349,7 @@ void execute() throws IOException {
.addArguments("--classpath", "bin").build() //
.run(false);

assertEquals(1, result.getExitCode(), String.join("\n", result.getOutputLines("out")));
assertEquals(1, result.getExitCode(), () -> getExitCodeMessage(result));

var workspace = Request.WORKSPACE.resolve("standalone");
var expectedOutLines = Files.readAllLines(workspace.resolve("expected-out.txt"));
Expand Down Expand Up @@ -384,7 +384,7 @@ void executeOnJava8() throws IOException {
.addArguments("--classpath", "bin").build() //
.run(false);

assertEquals(1, result.getExitCode(), String.join("\n", result.getOutputLines("out")));
assertEquals(1, result.getExitCode(), () -> getExitCodeMessage(result));

var workspace = Request.WORKSPACE.resolve("standalone");
var expectedOutLines = Files.readAllLines(workspace.resolve("expected-out.txt"));
Expand Down Expand Up @@ -420,7 +420,7 @@ void executeOnJava8SelectPackage() throws IOException {
.addArguments("--classpath", "bin").build() //
.run(false);

assertEquals(1, result.getExitCode(), String.join("\n", result.getOutputLines("out")));
assertEquals(1, result.getExitCode(), () -> getExitCodeMessage(result));

var workspace = Request.WORKSPACE.resolve("standalone");
var expectedOutLines = Files.readAllLines(workspace.resolve("expected-out.txt"));
Expand Down Expand Up @@ -461,6 +461,11 @@ void executeWithJarredTestClasses() {
.build() //
.run(false);

assertEquals(1, result.getExitCode(), String.join("\n", result.getOutputLines("out")));
assertEquals(1, result.getExitCode(), () -> getExitCodeMessage(result));
}

private static String getExitCodeMessage(Result result) {
return "Exit codes don't match. Stdout:\n" + result.getOutput("out") + //
"\n\nStderr:\n" + result.getOutput("err") + "\n";
}
}

0 comments on commit 3f2590d

Please sign in to comment.