From c6cb6e144fe0238bdb181fc2713374a4bab7a9dc Mon Sep 17 00:00:00 2001 From: Duarte Meneses Date: Tue, 8 Mar 2016 14:23:02 +0100 Subject: SONARUNNER-153 sonar.verbose and sonar.log.level do not work --- .../java/org/sonarsource/scanner/cli/CliTest.java | 9 ++--- .../java/org/sonarsource/scanner/cli/MainTest.java | 45 +++++++++++++++++++++- 2 files changed, 47 insertions(+), 7 deletions(-) (limited to 'src/test') 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 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 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); -- cgit v1.2.3