Skip to content

Commit

Permalink
Make sure unrecognized CLI command message is printed (#11357)
Browse files Browse the repository at this point in the history
  • Loading branch information
JaroslavTulach authored Oct 18, 2024
1 parent 7522acf commit 6a50616
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
3 changes: 2 additions & 1 deletion engine/runner/src/main/java/org/enso/runner/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ private static Options buildOptions() {
}

/** Prints the help message to the standard output. */
private static void printHelp() {
void printHelp() {
new HelpFormatter().printHelp(LanguageInfo.ID, CLI_OPTIONS);
}

Expand Down Expand Up @@ -1436,6 +1436,7 @@ final CommandLine preprocessArguments(String... args) {
System.currentTimeMillis() - startParsing);
return line;
} catch (Exception e) {
println(e.getMessage());
printHelp();
throw exitFail();
}
Expand Down
23 changes: 23 additions & 0 deletions engine/runner/src/test/java/org/enso/runner/EngineMainTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;

import java.io.IOException;
import java.util.ArrayList;
Expand All @@ -17,6 +18,21 @@ public class EngineMainTest {

private final List<String> linesOut = new ArrayList<>();

@Test
public void unknownCommandBecauseTwoAreConcatenated() throws Exception {
var m = new MainMock();
try {
var file = tempDir.newFile("some.enso");
var line = m.preprocessArguments("--repl --inspect", "--run", file.getAbsolutePath());
m.mainEntry(line, Level.INFO, false);
} catch (ExitCode ex) {
assertEquals("Execution fails", 1, ex.exitCode);
assertEquals("One line printed", 1, linesOut.size());
assertEquals("Unrecognized option: --repl --inspect", linesOut.get(0));
assertTrue("Also help was printed", m.helpPrinted);
}
}

@Test
public void cannotUseReplAndInspectAtOnce() throws Exception {
try {
Expand Down Expand Up @@ -76,6 +92,8 @@ public void systemPropertyArgumentIncorrectFormat() throws IOException {
}

private final class MainMock extends Main {
boolean helpPrinted;

@Override
RuntimeException doExit(int exitCode) {
throw new ExitCode(exitCode);
Expand All @@ -85,6 +103,11 @@ RuntimeException doExit(int exitCode) {
void println(String msg) {
linesOut.add(msg);
}

@Override
void printHelp() {
helpPrinted = true;
}
}

private static final class ExitCode extends RuntimeException {
Expand Down

0 comments on commit 6a50616

Please sign in to comment.