Make sure unrecognized CLI command message is printed (#11357)

This commit is contained in:
Jaroslav Tulach 2024-10-18 17:13:02 +02:00 committed by GitHub
parent 7522acf925
commit 6a506161cb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 25 additions and 1 deletions

View File

@ -518,7 +518,7 @@ public class Main {
}
/** Prints the help message to the standard output. */
private static void printHelp() {
void printHelp() {
new HelpFormatter().printHelp(LanguageInfo.ID, CLI_OPTIONS);
}
@ -1436,6 +1436,7 @@ public class Main {
System.currentTimeMillis() - startParsing);
return line;
} catch (Exception e) {
println(e.getMessage());
printHelp();
throw exitFail();
}

View File

@ -3,6 +3,7 @@ package org.enso.runner;
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;
@ -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 {
@ -76,6 +92,8 @@ public class EngineMainTest {
}
private final class MainMock extends Main {
boolean helpPrinted;
@Override
RuntimeException doExit(int exitCode) {
throw new ExitCode(exitCode);
@ -85,6 +103,11 @@ public class EngineMainTest {
void println(String msg) {
linesOut.add(msg);
}
@Override
void printHelp() {
helpPrinted = true;
}
}
private static final class ExitCode extends RuntimeException {