Search in sources :

Example 16 with TaskResult

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

the class IssuesOnDirMediumTest method scanTempProject.

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

Example 17 with TaskResult

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

the class EmptyFileTest method testIssueTrackingWithIssueOnEmptyFile.

@Test
public void testIssueTrackingWithIssueOnEmptyFile() throws Exception {
    File projectDir = copyProject("/mediumtest/xoo/sample-with-empty-file");
    TaskResult result = tester.newScanTask(new File(projectDir, "sonar-project.properties")).property("sonar.xoo.internalKey", "my/internal/key").start();
    for (TrackedIssue i : result.trackedIssues()) {
        System.out.println(i.startLine() + " " + i.getMessage());
    }
    assertThat(result.trackedIssues()).hasSize(11);
}
Also used : TrackedIssue(org.sonar.scanner.issue.tracking.TrackedIssue) TaskResult(org.sonar.scanner.mediumtest.TaskResult) File(java.io.File) Test(org.junit.Test)

Example 18 with TaskResult

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

the class ProjectBuilderMediumTest method testProjectBuilder.

@Test
public void testProjectBuilder() throws IOException {
    File baseDir = prepareProject();
    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", ".").put("sonar.verbose", "true").put("sonar.xoo.enableProjectBuilder", "true").build()).start();
    List<Issue> issues = result.issuesFor(result.inputFile("src/sample.xoo"));
    assertThat(issues).hasSize(10);
    assertThat(issues).extracting("msg", "textRange.startLine", "gap").contains(tuple("This issue is generated on each line", 1, 0.0));
}
Also used : Issue(org.sonar.scanner.protocol.output.ScannerReport.Issue) TaskResult(org.sonar.scanner.mediumtest.TaskResult) File(java.io.File) Test(org.junit.Test)

Example 19 with TaskResult

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

the class ChecksMediumTest method testCheckWithTemplate.

@Test
public void testCheckWithTemplate() throws IOException {
    File baseDir = temp.getRoot();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    FileUtils.write(xooFile, "foo\nbar");
    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();
    List<Issue> issues = result.issuesFor(result.inputFile("src/sample.xoo"));
    assertThat(issues).extracting("msg", "textRange.startLine").containsOnly(tuple("A template rule", 1), tuple("Another template rule", 2));
}
Also used : Issue(org.sonar.scanner.protocol.output.ScannerReport.Issue) TaskResult(org.sonar.scanner.mediumtest.TaskResult) File(java.io.File) Test(org.junit.Test)

Example 20 with TaskResult

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

the class IssuesMediumTest method testOneIssuePerLine.

@Test
public void testOneIssuePerLine() 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")).start();
    List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"));
    assertThat(issues).hasSize(8);
    Issue issue = issues.get(0);
    assertThat(issue.getTextRange().getStartLine()).isEqualTo(issue.getTextRange().getStartLine());
}
Also used : Issue(org.sonar.scanner.protocol.output.ScannerReport.Issue) 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