Skip to content
Open
Show file tree
Hide file tree
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 @@ -27,17 +27,29 @@ public class CommandLineLauncher {
public static final CommandLineArgs cmdArgs = new CommandLineArgs();

public static void main(String[] args) {
int exitCode = run(args);
// exit only on failure, so a passing run under `mvn exec:java` does not stop Maven early
if (exitCode != 0) {
System.exit(exitCode);
}
}

/**
* Runs the command line verifier and returns the process exit status: 1 if verification reported an error, 0
* otherwise. Unlike {@link #launch(String...)}, which the language server calls, this is only for the command line.
*/
public static int run(String... args) {
CommandLine cmd = new CommandLine(cmdArgs);
cmd.parseArgs(args);

if (cmd.isUsageHelpRequested()) {
cmd.usage(System.out);
return;
return 0;
}

if (cmd.isVersionHelpRequested()) {
System.out.println("liquidjava " + cmdArgs.getVersionString());
return;
return 0;
}

launch(cmdArgs.paths.stream().toArray(String[]::new));
Expand All @@ -48,10 +60,11 @@ public static void main(String[] args) {
}
if (diagnostics.foundError()) {
System.out.println(diagnostics.getErrorOutput());
return;
return 1;
}

System.out.println("Correct! Passed Verification.");
return 0;
}

public static void launch(String... paths) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package liquidjava.api.tests;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.Test;

import liquidjava.api.CommandLineLauncher;

/** The command line exit status must tell a failed verification from a passing one (#562). */
public class TestCommandLineExitCode {

private static final String TEST_SUITE = "../liquidjava-example/src/main/java/testSuite/";

@Test
public void verificationErrorExitsWithNonZeroStatus() {
assertEquals(1, CommandLineLauncher.run(TEST_SUITE + "ErrorSimpleAssignment.java"));
}

@Test
public void passingVerificationExitsWithZeroStatus() {
assertEquals(0, CommandLineLauncher.run(TEST_SUITE + "CorrectSimpleAssignment.java"));
}

@Test
public void missingPathExitsWithNonZeroStatus() {
assertEquals(1, CommandLineLauncher.run(TEST_SUITE + "DoesNotExist.java"));
}

@Test
public void errorFromEarlierRunDoesNotLeakIntoPassingRun() {
assertEquals(1, CommandLineLauncher.run(TEST_SUITE + "ErrorSimpleAssignment.java"));
assertEquals(0, CommandLineLauncher.run(TEST_SUITE + "CorrectSimpleAssignment.java"));
}
}
Loading