Search in sources :

Example 11 with TaskResult

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

the class ScanOnlyChangedTest method testScanOnlyChangedFiles.

@Test
public void testScanOnlyChangedFiles() throws Exception {
    File projectDir = copyProject("/mediumtest/xoo/sample");
    TaskResult result = tester.newScanTask(new File(projectDir, "sonar-project.properties")).start();
    /*
     * We have:
     * 6 new issues per line (open) in helloscala.xoo
     * 2 new issues per file in helloscala.xoo / ClassOneTest.xoo
     * 1 server issue (open, not new) copied from server in HelloJava.xoo (this file is unchanged)
     * 1 manual issue (open, not new) in HelloJava.xoo
     * 1 existing issue on the project (open, not new)
     */
    assertNumberIssues(result, 8, 2, 0);
    // should only have server issues (HelloJava.xoo should not have been analyzed)
    assertNumberIssuesOnFile(result, "HelloJava.xoo", 1);
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) File(java.io.File) Test(org.junit.Test)

Example 12 with TaskResult

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

the class BranchMediumTest method scanMultiModuleWithBranch.

@Test
public void scanMultiModuleWithBranch() throws IOException {
    Path srcDir = baseDir.toPath().resolve("moduleA").resolve("src");
    Files.createDirectories(srcDir);
    File xooFile = new File(srcDir.toFile(), "sample.xoo");
    FileUtils.write(xooFile, "Sample xoo\ncontent");
    TaskResult result = tester.newTask().properties(ImmutableMap.<String, String>builder().putAll(commonProps).put("sonar.branch", "branch").put("sonar.modules", "moduleA").build()).start();
    assertThat(result.inputFiles()).hasSize(1);
    assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:moduleA:src/sample.xoo");
    // no branch in the report
    DefaultInputFile inputfile = (DefaultInputFile) result.inputFile("src/sample.xoo");
    assertThat(result.getReportReader().readComponent(inputfile.batchId()).getPath()).isEqualTo("src/sample.xoo");
    // no branch in InputModule's key or in report
    assertThat(result.getReportComponent("com.foo.project:moduleA").getKey()).isEqualTo("com.foo.project:moduleA");
    assertThat(result.getReportReader().readMetadata().getBranch()).isEqualTo("branch");
    result = tester.newTask().properties(ImmutableMap.<String, String>builder().putAll(commonProps).put("sonar.branch", "").put("sonar.modules", "moduleA").build()).start();
    assertThat(result.inputFiles()).hasSize(1);
    assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:moduleA:src/sample.xoo");
}
Also used : Path(java.nio.file.Path) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) TaskResult(org.sonar.scanner.mediumtest.TaskResult) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Example 13 with TaskResult

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

the class CoverageMediumTest method twoReports.

@Test
public void twoReports() throws IOException {
    File baseDir = temp.getRoot();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    FileUtils.write(xooFile, "function foo() {\n  if (a && b) {\nalert('hello');\n}\n}");
    File xooUtCoverageFile = new File(srcDir, "sample.xoo.coverage");
    FileUtils.write(xooUtCoverageFile, "2:2:2:2\n4:0");
    File xooItCoverageFile = new File(srcDir, "sample.xoo.itcoverage");
    FileUtils.write(xooItCoverageFile, "2:2:2:1\n3:1\n5: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, 2).getHits()).isTrue();
    assertThat(result.coverageFor(file, 2).getConditions()).isEqualTo(2);
    assertThat(result.coverageFor(file, 2).getCoveredConditions()).isEqualTo(2);
    assertThat(result.coverageFor(file, 3).getHits()).isTrue();
    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", "stringValue.value").contains(// 2, 3, 4, 5
    tuple(CoreMetrics.LINES_TO_COVER_KEY, 4, ""), // 4, 5
    tuple(CoreMetrics.UNCOVERED_LINES_KEY, 2, ""), // 2 x 2
    tuple(CoreMetrics.CONDITIONS_TO_COVER_KEY, 2, ""), tuple(CoreMetrics.UNCOVERED_CONDITIONS_KEY, 0, ""), tuple(CoreMetrics.COVERAGE_LINE_HITS_DATA_KEY, 0, "2=4;3=1;4=0;5=0"), tuple(CoreMetrics.CONDITIONS_BY_LINE_KEY, 0, "2=2"), tuple(CoreMetrics.COVERED_CONDITIONS_BY_LINE_KEY, 0, "2=2"));
}
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 14 with TaskResult

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

the class IssuesMediumTest method testIssueExclusion.

@Test
public void testIssueExclusion() throws Exception {
    File projectDir = new File(IssuesMediumTest.class.getResource("/mediumtest/xoo/sample").toURI());
    File tmpDir = temp.newFolder();
    FileUtils.copyDirectory(projectDir, tmpDir);
    TaskResult result = tester.newScanTask(new File(tmpDir, "sonar-project.properties")).property("sonar.issue.ignore.allfile", "1").property("sonar.issue.ignore.allfile.1.fileRegexp", "object").start();
    assertThat(result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"))).hasSize(8);
    assertThat(result.issuesFor(result.inputFile("xources/hello/helloscala.xoo"))).isEmpty();
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) File(java.io.File) Test(org.junit.Test)

Example 15 with TaskResult

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

the class IssuesOnDirMediumTest method issueOnRootFolder.

@Test
public void issueOnRootFolder() throws IOException {
    File baseDir = temp.getRoot();
    File xooFile1 = new File(baseDir, "sample1.xoo");
    FileUtils.write(xooFile1, "Sample1 xoo\ncontent");
    File xooFile2 = new File(baseDir, "sample2.xoo");
    FileUtils.write(xooFile2, "Sample2 xoo\ncontent");
    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", ".").build()).start();
    assertThat(result.issuesFor(result.inputDir(""))).hasSize(2);
}
Also used : TaskResult(org.sonar.scanner.mediumtest.TaskResult) File(java.io.File) 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