mirror of
https://github.com/enso-org/enso.git
synced 2024-12-22 23:01:29 +03:00
Make sure unrecognized CLI command message is printed (#11357)
This commit is contained in:
parent
7522acf925
commit
6a506161cb
@ -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();
|
||||
}
|
||||
|
@ -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 {
|
||||
|
Loading…
Reference in New Issue
Block a user