aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJulien HENRY <julien.henry@sonarsource.com>2019-06-21 23:36:13 +0200
committerDuarte Meneses <duarte.meneses@sonarsource.com>2019-06-25 01:19:40 -0500
commit24c7dea34bbec0b53b199fc443d37dd63a01d709 (patch)
tree904cc72aabaa3d2866352cbd2f24c4048f04eef9 /src
parent93baed3d564c422458ae1d348b1e326a71f9438a (diff)
downloadsonar-scanner-cli-24c7dea34bbec0b53b199fc443d37dd63a01d709.tar.gz
sonar-scanner-cli-24c7dea34bbec0b53b199fc443d37dd63a01d709.zip
SQSCANNER-56 Stacktrace are only displayed in verbose mode
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/sonarsource/scanner/cli/Main.java2
-rw-r--r--src/test/java/org/sonarsource/scanner/cli/MainTest.java44
2 files changed, 30 insertions, 16 deletions
diff --git a/src/main/java/org/sonarsource/scanner/cli/Main.java b/src/main/java/org/sonarsource/scanner/cli/Main.java
index 3e74b17..5764423 100644
--- a/src/main/java/org/sonarsource/scanner/cli/Main.java
+++ b/src/main/java/org/sonarsource/scanner/cli/Main.java
@@ -122,7 +122,7 @@ public class Main {
}
private void showError(String message, Throwable e, boolean debug) {
- if (debug && !isUserError(e)) {
+ if (debug || !isUserError(e)) {
logger.error(message, e);
} else {
logger.error(message);
diff --git a/src/test/java/org/sonarsource/scanner/cli/MainTest.java b/src/test/java/org/sonarsource/scanner/cli/MainTest.java
index 7090196..dc1013b 100644
--- a/src/test/java/org/sonarsource/scanner/cli/MainTest.java
+++ b/src/test/java/org/sonarsource/scanner/cli/MainTest.java
@@ -34,6 +34,7 @@ import org.sonarsource.scanner.api.ScanProperties;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.ArgumentMatchers.any;
+import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -111,46 +112,59 @@ public class MainTest {
}
@Test
- public void show_error_MessageException() {
+ public void show_stacktrace() {
+ Exception e = createException(false);
+ testException(e, false, false, Exit.INTERNAL_ERROR);
+
+ verify(logs).error("Error during SonarQube Scanner execution", e);
+ verify(logs).error("Re-run SonarQube Scanner using the -X switch to enable full debug logging.");
+ }
+
+ @Test
+ public void dont_show_MessageException_stacktrace() {
Exception e = createException(true);
testException(e, false, false, Exit.USER_ERROR);
+ verify(logs, times(5)).error(anyString());
verify(logs).error("Error during SonarQube Scanner execution");
- verify(logs).error("Caused by: NPE");
+ verify(logs).error("my message");
+ verify(logs).error("Caused by: A functional cause");
+ verify(logs).error("");
verify(logs).error("Re-run SonarQube Scanner using the -X switch to enable full debug logging.");
}
@Test
- public void show_error_MessageException_embedded() {
+ public void dont_show_MessageException_stacktrace_embedded() {
Exception e = createException(true);
testException(e, false, true, Exit.USER_ERROR);
+ verify(logs, times(4)).error(anyString());
verify(logs).error("Error during SonarQube Scanner execution");
- verify(logs).error("Caused by: NPE");
+ verify(logs).error("my message");
+ verify(logs).error("Caused by: A functional cause");
+ verify(logs).error("");
}
-
+
@Test
- public void show_error_MessageException_debug() {
+ public void show_MessageException_stacktrace_in_debug() {
Exception e = createException(true);
testException(e, true, false, Exit.USER_ERROR);
- verify(logs).error("Error during SonarQube Scanner execution");
- verify(logs).error("my message");
- verify(logs).error("Caused by: NPE");
+ verify(logs, times(1)).error(anyString(), any(Throwable.class));
+ verify(logs).error("Error during SonarQube Scanner execution", e);
}
@Test
- public void show_error_MessageException_debug_embedded() {
+ public void show_MessageException_stacktrace_in_debug_embedded() {
Exception e = createException(true);
testException(e, true, true, Exit.USER_ERROR);
- verify(logs).error("Error during SonarQube Scanner execution");
- verify(logs).error("my message");
- verify(logs).error("Caused by: NPE");
+ verify(logs, times(1)).error(anyString(), any(Throwable.class));
+ verify(logs).error("Error during SonarQube Scanner execution", e);
}
@Test
- public void show_error_debug() {
+ public void show_stacktrace_in_debug() {
Exception e = createException(false);
testException(e, true, false, Exit.INTERNAL_ERROR);
@@ -175,7 +189,7 @@ public class MainTest {
private Exception createException(boolean messageException) {
Exception e;
if (messageException) {
- e = new MessageException("my message", new NullPointerException("NPE"));
+ e = new MessageException("my message", new IllegalStateException("A functional cause"));
} else {
e = new IllegalStateException("Error", new NullPointerException("NPE"));
}