Search in sources :

Example 1 with TaskResult

use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.

the class CoverageMediumTest method fallbackOnExecutableLines.

@Test
public void fallbackOnExecutableLines() throws IOException {
    File baseDir = temp.getRoot();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    File measuresFile = new File(srcDir, "sample.xoo.measures");
    FileUtils.write(xooFile, "function foo() {\n  if (a && b) {\nalert('hello');\n}\n}");
    FileUtils.write(measuresFile, "executable_lines_data:2=1;3=1;4=0");
    TaskResult result = tester.newTask().properties(ImmutableMap.<String, String>builder().put("sonar.task", "scan").put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project").put("sonar.sources", "src").build()).start();
    InputFile file = result.inputFile("src/sample.xoo");
    assertThat(result.coverageFor(file, 1)).isNull();
    assertThat(result.coverageFor(file, 2).getHits()).isFalse();
    assertThat(result.coverageFor(file, 2).getConditions()).isEqualTo(0);
    assertThat(result.coverageFor(file, 2).getCoveredConditions()).isEqualTo(0);
    assertThat(result.coverageFor(file, 3).getHits()).isFalse();
    assertThat(result.coverageFor(file, 4)).isNull();
    Map<String, List<org.sonar.scanner.protocol.output.ScannerReport.Measure>> allMeasures = result.allMeasures();
    assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value").contains(tuple(CoreMetrics.LINES_TO_COVER_KEY, 2), tuple(CoreMetrics.UNCOVERED_LINES_KEY, 2));
    assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey").doesNotContain(CoreMetrics.CONDITIONS_TO_COVER_KEY, CoreMetrics.UNCOVERED_CONDITIONS_KEY);
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) List(java.util.List) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 2 with TaskResult

use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.

the class CoverageMediumTest method exclusions.

@Test
public void exclusions() throws IOException {
    File baseDir = temp.getRoot();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    File xooUtCoverageFile = new File(srcDir, "sample.xoo.coverage");
    FileUtils.write(xooFile, "function foo() {\n  if (a && b) {\nalert('hello');\n}\n}");
    FileUtils.write(xooUtCoverageFile, "2:2:2:1\n3:1");
    TaskResult result = tester.newTask().properties(ImmutableMap.<String, String>builder().put("sonar.task", "scan").put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project").put("sonar.sources", "src").put("sonar.coverage.exclusions", "**/sample.xoo").build()).start();
    InputFile file = result.inputFile("src/sample.xoo");
    assertThat(result.coverageFor(file, 2)).isNull();
    Map<String, List<org.sonar.scanner.protocol.output.ScannerReport.Measure>> allMeasures = result.allMeasures();
    assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey").doesNotContain(CoreMetrics.LINES_TO_COVER_KEY, CoreMetrics.UNCOVERED_LINES_KEY, CoreMetrics.CONDITIONS_TO_COVER_KEY, CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY);
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) List(java.util.List) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 3 with TaskResult

use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.

the class CoverageMediumTest method singleReport.

@Test
public void singleReport() throws IOException {
    File baseDir = temp.getRoot();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    File xooUtCoverageFile = new File(srcDir, "sample.xoo.coverage");
    FileUtils.write(xooFile, "function foo() {\n  if (a && b) {\nalert('hello');\n}\n}");
    FileUtils.write(xooUtCoverageFile, "2:2:2:1\n3:1");
    TaskResult result = tester.newTask().properties(ImmutableMap.<String, String>builder().put("sonar.task", "scan").put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project").put("sonar.sources", "src").build()).start();
    InputFile file = result.inputFile("src/sample.xoo");
    assertThat(result.coverageFor(file, 2).getHits()).isTrue();
    assertThat(result.coverageFor(file, 2).getConditions()).isEqualTo(2);
    assertThat(result.coverageFor(file, 2).getCoveredConditions()).isEqualTo(1);
    Map<String, List<org.sonar.scanner.protocol.output.ScannerReport.Measure>> allMeasures = result.allMeasures();
    assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value").contains(tuple(CoreMetrics.LINES_TO_COVER_KEY, 2), tuple(CoreMetrics.UNCOVERED_LINES_KEY, 0), tuple(CoreMetrics.CONDITIONS_TO_COVER_KEY, 2), tuple(CoreMetrics.UNCOVERED_CONDITIONS_KEY, 1));
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) List(java.util.List) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 4 with TaskResult

use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.

the class GenericCoverageMediumTest method singleReport.

@Test
public void singleReport() throws IOException {
    File projectDir = new File("src/test/resources/mediumtest/xoo/sample-generic-coverage");
    TaskResult result = tester.newScanTask(new File(projectDir, "sonar-project.properties")).property("sonar.coverageReportPaths", "coverage.xml").start();
    InputFile noConditions = result.inputFile("xources/hello/NoConditions.xoo");
    assertThat(result.coverageFor(noConditions, 6).getHits()).isTrue();
    assertThat(result.coverageFor(noConditions, 6).getConditions()).isEqualTo(0);
    assertThat(result.coverageFor(noConditions, 6).getCoveredConditions()).isEqualTo(0);
    assertThat(result.coverageFor(noConditions, 7).getHits()).isFalse();
    assertThat(result.allMeasures().get(noConditions.key())).extracting("metricKey", "intValue.value", "stringValue.value").containsOnly(tuple(CoreMetrics.LINES_TO_COVER_KEY, 2, ""), tuple(CoreMetrics.UNCOVERED_LINES_KEY, 1, ""), tuple(CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY, 0, "6=1;7=0"));
    InputFile withConditions = result.inputFile("xources/hello/WithConditions.xoo");
    assertThat(result.coverageFor(withConditions, 3).getHits()).isTrue();
    assertThat(result.coverageFor(withConditions, 3).getConditions()).isEqualTo(2);
    assertThat(result.coverageFor(withConditions, 3).getCoveredConditions()).isEqualTo(1);
    assertThat(result.allMeasures().get(withConditions.key())).extracting("metricKey", "intValue.value", "stringValue.value").containsOnly(tuple(CoreMetrics.LINES_TO_COVER_KEY, 1, ""), tuple(CoreMetrics.UNCOVERED_LINES_KEY, 0, ""), tuple(CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY, 0, "3=1"), tuple(CoreMetrics.CONDITIONS_TO_COVER_KEY, 2, ""), tuple(CoreMetrics.UNCOVERED_CONDITIONS_KEY, 1, ""), tuple(CoreMetrics.CONDITIONS_BY_LINE_KEY, 0, "3=2"), tuple(CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY, 0, "3=1"));
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 5 with TaskResult

use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.

the class GenericCoverageMediumTest method twoReports.

@Test
public void twoReports() throws IOException {
    File projectDir = new File("src/test/resources/mediumtest/xoo/sample-generic-coverage");
    TaskResult result = tester.newScanTask(new File(projectDir, "sonar-project.properties")).property("sonar.coverageReportPaths", "coverage.xml,coverage2.xml").start();
    InputFile noConditions = result.inputFile("xources/hello/NoConditions.xoo");
    assertThat(result.coverageFor(noConditions, 6).getHits()).isTrue();
    assertThat(result.coverageFor(noConditions, 6).getConditions()).isEqualTo(0);
    assertThat(result.coverageFor(noConditions, 6).getCoveredConditions()).isEqualTo(0);
    assertThat(result.coverageFor(noConditions, 7).getHits()).isTrue();
    assertThat(result.allMeasures().get(noConditions.key())).extracting("metricKey", "intValue.value", "stringValue.value").containsOnly(tuple(CoreMetrics.LINES_TO_COVER_KEY, 2, ""), tuple(CoreMetrics.UNCOVERED_LINES_KEY, 0, ""), tuple(CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY, 0, "6=1;7=1"));
    InputFile withConditions = result.inputFile("xources/hello/WithConditions.xoo");
    assertThat(result.coverageFor(withConditions, 3).getHits()).isTrue();
    assertThat(result.coverageFor(withConditions, 3).getConditions()).isEqualTo(2);
    assertThat(result.coverageFor(withConditions, 3).getCoveredConditions()).isEqualTo(2);
    assertThat(result.allMeasures().get(withConditions.key())).extracting("metricKey", "intValue.value", "stringValue.value").containsOnly(tuple(CoreMetrics.LINES_TO_COVER_KEY, 1, ""), tuple(CoreMetrics.UNCOVERED_LINES_KEY, 0, ""), tuple(CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY, 0, "3=2"), tuple(CoreMetrics.CONDITIONS_TO_COVER_KEY, 2, ""), tuple(CoreMetrics.UNCOVERED_CONDITIONS_KEY, 0, ""), tuple(CoreMetrics.CONDITIONS_BY_LINE_KEY, 0, "3=2"), tuple(CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY, 0, "3=2"));
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)61 TaskResult (org.sonar.scanner.mediumtest.TaskResult)61 File (java.io.File)59 InputFile (org.sonar.api.batch.fs.InputFile)31 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)21 List (java.util.List)8 Issue (org.sonar.scanner.protocol.output.ScannerReport.Issue)7 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)6 Path (java.nio.file.Path)3 InputDir (org.sonar.api.batch.fs.InputDir)3 ScannerMediumTester (org.sonar.scanner.mediumtest.ScannerMediumTester)3 XooPlugin (org.sonar.xoo.XooPlugin)3 XooRulesDefinition (org.sonar.xoo.rule.XooRulesDefinition)3 TrackedIssue (org.sonar.scanner.issue.tracking.TrackedIssue)2 Date (java.util.Date)1 LogOutputRecorder (org.sonar.scanner.mediumtest.LogOutputRecorder)1