aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2016-09-14 17:51:40 +0200
committerJulien HENRY <julien.henry@sonarsource.com>2016-09-14 18:08:36 +0200
commit89fac82713095f2ff85703fb6223a02e4b5b818d (patch)
tree3453fb7bdb88efd0f5bc7b713084475bcdc89e09 /src
parent516ba9b922f4dab9f72077ee5ebf6eebda6c0d3a (diff)
downloadsonar-scanner-cli-89fac82713095f2ff85703fb6223a02e4b5b818d.tar.gz
sonar-scanner-cli-89fac82713095f2ff85703fb6223a02e4b5b818d.zip
SQSCANNER-29 Exit code should not be 0 when script fails due to ERROR: Unrecognized option
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/sonarsource/scanner/cli/Cli.java3
-rw-r--r--src/test/java/org/sonarsource/scanner/cli/CliTest.java20
2 files changed, 22 insertions, 1 deletions
diff --git a/src/main/java/org/sonarsource/scanner/cli/Cli.java b/src/main/java/org/sonarsource/scanner/cli/Cli.java
index 9019c6a..784f6c1 100644
--- a/src/main/java/org/sonarsource/scanner/cli/Cli.java
+++ b/src/main/java/org/sonarsource/scanner/cli/Cli.java
@@ -62,6 +62,7 @@ class Cli {
} else if ("-h".equals(arg) || "--help".equals(arg)) {
printUsage();
+ exit.exit(Exit.SUCCESS);
} else if ("-v".equals(arg) || "--version".equals(arg)) {
displayVersionOnly = true;
@@ -120,6 +121,7 @@ class Cli {
private void printError(String message) {
logger.error(message);
printUsage();
+ exit.exit(Exit.ERROR);
}
private void printUsage() {
@@ -133,6 +135,5 @@ class Cli {
logger.info(" -v,--version Display version information");
logger.info(" -X,--debug Produce execution debug output");
logger.info(" -i,--interactive Run interactively");
- exit.exit(Exit.SUCCESS);
}
}
diff --git a/src/test/java/org/sonarsource/scanner/cli/CliTest.java b/src/test/java/org/sonarsource/scanner/cli/CliTest.java
index 6bac2d0..840f35b 100644
--- a/src/test/java/org/sonarsource/scanner/cli/CliTest.java
+++ b/src/test/java/org/sonarsource/scanner/cli/CliTest.java
@@ -23,6 +23,7 @@ import org.junit.Test;
import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.verify;
public class CliTest {
Exit exit = mock(Exit.class);
@@ -77,4 +78,23 @@ public class CliTest {
assertThat(cli.isDisplayStackTrace()).isFalse();
assertThat(cli.properties().get("sonar.verbose")).isNull();
}
+
+ @Test
+ public void should_show_usage() {
+ logs = mock(Logs.class);
+ cli = new Cli(exit, logs);
+ cli.parse(new String[] {"-h"});
+ verify(logs).info("usage: sonar-scanner [options]");
+ verify(exit).exit(Exit.SUCCESS);
+ }
+
+ @Test
+ public void should_show_usage_on_bad_syntax() {
+ logs = mock(Logs.class);
+ cli = new Cli(exit, logs);
+ cli.parse(new String[] {"-w"});
+ verify(logs).error("Unrecognized option: -w");
+ verify(logs).info("usage: sonar-scanner [options]");
+ verify(exit).exit(Exit.ERROR);
+ }
}