aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-runner-dist/src/test/java/org/sonar/runner/CliTest.java
blob: dd63f3690367b716f265bdd5ad0ebd9f45bb8cab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/*
 * SonarQube Runner - Distribution
 * Copyright (C) 2011 SonarSource
 * dev@sonar.codehaus.org
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 3 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02
 */
package org.sonar.runner;

import org.junit.Test;

import static org.fest.assertions.Assertions.assertThat;

public class CliTest {

  Cli cli = new Cli();

  @Test
  public void should_parse_empty_arguments() {
    cli.parse(new String[0]);
    assertThat(cli.properties()).isNotEmpty();
    assertThat(cli.isDebugMode()).isFalse();
    assertThat(cli.isDisplayStackTrace()).isFalse();
    assertThat(cli.isDisplayVersionOnly()).isFalse();
  }

  @Test
  public void should_extract_properties() {
    cli.parse(new String[]{"-D", "foo=bar", "--define", "hello=world", "-Dboolean"});
    assertThat(cli.properties().get("foo")).isEqualTo("bar");
    assertThat(cli.properties().get("hello")).isEqualTo("world");
    assertThat(cli.properties().get("boolean")).isEqualTo("true");
  }

  @Test
  public void should_parse_optional_task() {
    cli.parse(new String[]{"-D", "foo=bar"});
    assertThat(cli.properties().get("sonar.task")).isNull();

    cli.parse(new String[]{"views", "-D", "foo=bar"});
    assertThat(cli.properties().get("sonar.task")).isEqualTo("views");
  }

  @Test
  public void should_enable_debug_mode() {
    cli.parse(new String[]{"-X"});
    assertThat(cli.isDebugMode()).isTrue();
    assertThat(cli.isDisplayStackTrace()).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.isDisplayStackTrace()).isTrue();
    assertThat(cli.properties().get("sonar.verbose")).isNull();
  }

  @Test
  public void should_disable_debug_mode_and_stacktrace_log_by_default() {
    cli.parse(new String[0]);
    assertThat(cli.isDebugMode()).isFalse();
    assertThat(cli.isDisplayStackTrace()).isFalse();
    assertThat(cli.properties().get("sonar.verbose")).isNull();
  }
}