예제 #1
0
  @Test
  // SONARJS-301
  public void print_log_for_not_found_resource() throws InterruptedException {
    SonarRunner build =
        Tests.createSonarRunnerBuild()
            .setProjectDir(TestUtils.projectDir("lcov"))
            .setProjectKey("project")
            .setProjectName("project")
            .setProjectVersion("1.0")
            .setSourceDirs(".")
            .setProperty(
                "sonar.javascript.lcov.reportPath",
                TestUtils.file("projects/lcov/coverage-wrong-file-name.lcov").getAbsolutePath())
            .setDebugLogs(true);
    BuildResult result = orchestrator.executeBuild(build);

    // Check that a log is printed
    String logs = result.getLogs();
    assertThat(Pattern.compile("Analysing .*coverage-wrong-file-name\\.lcov").matcher(logs).find())
        .isTrue();
    assertThat(
            Pattern.compile("Default value of zero will be saved for file: .*file\\.js")
                .matcher(logs)
                .find())
        .isTrue();
    assertThat(
            Pattern.compile(
                    "INFO.*Could not resolve 1 file paths in coverage-wrong-file-name\\.lcov, "
                        + "first unresolved path: \\./wrong/fileName\\.js")
                .matcher(logs)
                .find())
        .isTrue();
  }
예제 #2
0
  @Test
  public void no_coverage_information_saved() {
    SonarRunner build =
        Tests.createSonarRunnerBuild()
            .setProjectDir(TestUtils.projectDir("lcov"))
            .setProjectKey("project")
            .setProjectName("project")
            .setProjectVersion("1.0")
            .setSourceDirs(".");
    orchestrator.executeBuild(build);

    assertThat(getProjectMeasure("lines_to_cover")).isNull();
    assertThat(getProjectMeasure("uncovered_lines")).isNull();
    assertThat(getProjectMeasure("conditions_to_cover")).isNull();
    assertThat(getProjectMeasure("uncovered_conditions")).isNull();
  }
예제 #3
0
  @Test
  public void LCOV_path_can_be_relative() throws Exception {
    SonarRunner build =
        Tests.createSonarRunnerBuild()
            .setProjectDir(TestUtils.projectDir("lcov"))
            .setProjectKey("project")
            .setProjectName("project")
            .setProjectVersion("1.0")
            .setSourceDirs(".")
            .setProperty("sonar.javascript.lcov.reportPath", "coverage.lcov");
    orchestrator.executeBuild(build);

    assertThat(getProjectMeasure("lines_to_cover").getValue()).isEqualTo(4);
    assertThat(getProjectMeasure("uncovered_lines").getValue()).isEqualTo(1);
    assertThat(getProjectMeasure("conditions_to_cover").getValue()).isEqualTo(4);
    assertThat(getProjectMeasure("uncovered_conditions").getValue()).isEqualTo(2);
  }
예제 #4
0
  @Test
  public void LCOV_it_coverage() {
    if (Tests.is_strictly_after_plugin("2.5")) {
      SonarRunner build =
          Tests.createSonarRunnerBuild()
              .setProjectDir(TestUtils.projectDir("lcov"))
              .setProjectKey("project")
              .setProjectName("project")
              .setProjectVersion("1.0")
              .setSourceDirs(".")
              .setProperty(
                  "sonar.javascript.lcov.itReportPath",
                  TestUtils.file("projects/lcov/coverage.lcov").getAbsolutePath());
      orchestrator.executeBuild(build);

      assertThat(getProjectMeasure("it_lines_to_cover").getValue()).isEqualTo(4);
      assertThat(getProjectMeasure("it_uncovered_lines").getValue()).isEqualTo(1);
      assertThat(getProjectMeasure("it_conditions_to_cover").getValue()).isEqualTo(4);
      assertThat(getProjectMeasure("it_uncovered_conditions").getValue()).isEqualTo(2);
    }
  }
예제 #5
0
  @Test
  public void force_zero_coverage() {
    SonarRunner build =
        Tests.createSonarRunnerBuild()
            .setProjectDir(TestUtils.projectDir("lcov"))
            .setProjectKey("project")
            .setProjectKey("project")
            .setProjectName("project")
            .setProjectVersion("1.0")
            .setSourceDirs(".")
            .setProperty("sonar.javascript.forceZeroCoverage", "true");
    orchestrator.executeBuild(build);

    assertThat(getProjectMeasure("lines_to_cover").getValue()).isEqualTo(4);
    assertThat(getProjectMeasure("uncovered_lines").getValue()).isEqualTo(4);
    if (Tests.is_strictly_after_plugin("2.4")) {
      assertThat(getFileMeasure("coverage_line_hits_data").getData()).isEqualTo("3=0;4=0;5=0;7=0");
    }
    assertThat(getProjectMeasure("conditions_to_cover")).isNull();
    assertThat(getProjectMeasure("uncovered_conditions")).isNull();
  }