aboutsummaryrefslogtreecommitdiffstats
path: root/src/test
diff options
context:
space:
mode:
authorDuarte Meneses <duarte.meneses@sonarsource.com>2016-03-08 14:23:02 +0100
committerDuarte Meneses <duarte.meneses@sonarsource.com>2016-03-08 16:48:14 +0100
commitc6cb6e144fe0238bdb181fc2713374a4bab7a9dc (patch)
treecbc7f833a59885c3a4e6430e79d4ed83cfc8f311 /src/test
parent6dcf5f86801005d810d895e881d21b7181e4473e (diff)
downloadsonar-scanner-cli-c6cb6e144fe0238bdb181fc2713374a4bab7a9dc.tar.gz
sonar-scanner-cli-c6cb6e144fe0238bdb181fc2713374a4bab7a9dc.zip
SONARUNNER-153 sonar.verbose and sonar.log.level do not work
Diffstat (limited to 'src/test')
-rw-r--r--src/test/java/org/sonarsource/scanner/cli/CliTest.java9
-rw-r--r--src/test/java/org/sonarsource/scanner/cli/MainTest.java45
2 files changed, 47 insertions, 7 deletions
diff --git a/src/test/java/org/sonarsource/scanner/cli/CliTest.java b/src/test/java/org/sonarsource/scanner/cli/CliTest.java
index c1b4a4e..8e9a4ed 100644
--- a/src/test/java/org/sonarsource/scanner/cli/CliTest.java
+++ b/src/test/java/org/sonarsource/scanner/cli/CliTest.java
@@ -37,7 +37,7 @@ public class CliTest {
public void should_parse_empty_arguments() {
cli.parse(new String[0]);
assertThat(cli.properties()).isNotEmpty();
- assertThat(cli.isDebugMode()).isFalse();
+ assertThat(cli.isDebugEnabled()).isFalse();
assertThat(cli.isDisplayStackTrace()).isFalse();
assertThat(cli.isDisplayVersionOnly()).isFalse();
}
@@ -69,15 +69,14 @@ public class CliTest {
@Test
public void should_enable_debug_mode() {
cli.parse(new String[] {"-X"});
- assertThat(cli.isDebugMode()).isTrue();
- assertThat(cli.isDisplayStackTrace()).isTrue();
+ assertThat(cli.isDebugEnabled()).isTrue();
assertThat(cli.properties().get("sonar.verbose")).isEqualTo("true");
}
@Test
public void should_enable_stacktrace_log() {
cli.parse(new String[] {"-e"});
- assertThat(cli.isDebugMode()).isFalse();
+ assertThat(cli.isDebugEnabled()).isFalse();
assertThat(cli.isDisplayStackTrace()).isTrue();
assertThat(cli.properties().get("sonar.verbose")).isNull();
}
@@ -85,7 +84,7 @@ public class CliTest {
@Test
public void should_disable_debug_mode_and_stacktrace_log_by_default() {
cli.parse(new String[0]);
- assertThat(cli.isDebugMode()).isFalse();
+ assertThat(cli.isDebugEnabled()).isFalse();
assertThat(cli.isDisplayStackTrace()).isFalse();
assertThat(cli.properties().get("sonar.verbose")).isNull();
}
diff --git a/src/test/java/org/sonarsource/scanner/cli/MainTest.java b/src/test/java/org/sonarsource/scanner/cli/MainTest.java
index 8e9cdf3..e2fd69c 100644
--- a/src/test/java/org/sonarsource/scanner/cli/MainTest.java
+++ b/src/test/java/org/sonarsource/scanner/cli/MainTest.java
@@ -27,12 +27,14 @@ import java.nio.charset.StandardCharsets;
import java.util.Properties;
import org.junit.Before;
import org.junit.Test;
+import org.mockito.ArgumentCaptor;
import org.mockito.InOrder;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.MockitoAnnotations;
import org.sonar.runner.api.EmbeddedRunner;
+import static org.fest.assertions.Assertions.assertThat;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
@@ -62,7 +64,6 @@ public class MainTest {
MockitoAnnotations.initMocks(this);
when(runnerFactory.create(any(Properties.class))).thenReturn(runner);
when(conf.properties()).thenReturn(properties);
-
}
@Test
@@ -149,6 +150,46 @@ public class MainTest {
inOrder.verify(shutdown, times(1)).exit(Exit.SUCCESS);
}
+ @Test
+ public void should_configure_logging() throws IOException {
+ Properties p = new Properties();
+ p.put("sonar.verbose", "true");
+ when(conf.properties()).thenReturn(p);
+
+ Main main = new Main(shutdown, cli, conf, runnerFactory, logs);
+ main.execute();
+
+ // Logger used for callback should have debug enabled
+ verify(logs).setDebugEnabled(true);
+ verify(logs).setDisplayStackTrace(true);
+
+ ArgumentCaptor<Properties> propertiesCapture = ArgumentCaptor.forClass(Properties.class);
+ verify(runner).runAnalysis(propertiesCapture.capture());
+
+ Properties analysisProps = propertiesCapture.getValue();
+ assertThat(analysisProps.getProperty("sonar.verbose")).isEqualTo("true");
+ }
+
+ @Test
+ public void should_configure_logging_trace() throws IOException {
+ Properties p = new Properties();
+ p.put("sonar.log.level", "TRACE");
+ when(conf.properties()).thenReturn(p);
+
+ Main main = new Main(shutdown, cli, conf, runnerFactory, logs);
+ main.execute();
+
+ // Logger used for callback should have debug enabled
+ verify(logs).setDebugEnabled(true);
+ verify(logs).setDisplayStackTrace(true);
+
+ ArgumentCaptor<Properties> propertiesCapture = ArgumentCaptor.forClass(Properties.class);
+ verify(runner).runAnalysis(propertiesCapture.capture());
+
+ Properties analysisProps = propertiesCapture.getValue();
+ assertThat(analysisProps.getProperty("sonar.log.level")).isEqualTo("TRACE");
+ }
+
@Test(timeout = 30000)
public void test_interactive_mode() throws IOException {
String inputStr = "qwe" + System.lineSeparator() + "qwe" + System.lineSeparator();
@@ -157,7 +198,7 @@ public class MainTest {
input.close();
when(cli.isInteractive()).thenReturn(true);
- when(cli.isDebugMode()).thenReturn(true);
+ when(cli.isDebugEnabled()).thenReturn(true);
when(cli.isDisplayStackTrace()).thenReturn(true);
Main main = new Main(shutdown, cli, conf, runnerFactory, logs);