Search in sources :

Example 1 with Issue

use of org.sonar.scanner.protocol.output.ScannerReport.Issue in project sonarqube by SonarSource.

the class MultilineIssuesMediumTest method testIssueRange.

@Test
public void testIssueRange() throws Exception {
    List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/Single.xoo"));
    assertThat(issues).hasSize(1);
    Issue issue = issues.get(0);
    assertThat(issue.getMsg()).isEqualTo("Primary location");
    assertThat(issue.getTextRange().getStartLine()).isEqualTo(6);
    assertThat(issue.getTextRange().getStartOffset()).isEqualTo(23);
    assertThat(issue.getTextRange().getEndLine()).isEqualTo(6);
    assertThat(issue.getTextRange().getEndOffset()).isEqualTo(50);
}
Also used : Issue(org.sonar.scanner.protocol.output.ScannerReport.Issue) Test(org.junit.Test)

Example 2 with Issue

use of org.sonar.scanner.protocol.output.ScannerReport.Issue in project sonarqube by SonarSource.

the class MultilineIssuesMediumTest method testMultilineIssueRange.

@Test
public void testMultilineIssueRange() throws Exception {
    List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/Multiline.xoo"));
    assertThat(issues).hasSize(1);
    Issue issue = issues.get(0);
    assertThat(issue.getMsg()).isEqualTo("Primary location");
    assertThat(issue.getTextRange().getStartLine()).isEqualTo(6);
    assertThat(issue.getTextRange().getStartOffset()).isEqualTo(23);
    assertThat(issue.getTextRange().getEndLine()).isEqualTo(7);
    assertThat(issue.getTextRange().getEndOffset()).isEqualTo(23);
}
Also used : Issue(org.sonar.scanner.protocol.output.ScannerReport.Issue) Test(org.junit.Test)

Example 3 with Issue

use of org.sonar.scanner.protocol.output.ScannerReport.Issue 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 4 with Issue

use of org.sonar.scanner.protocol.output.ScannerReport.Issue 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 5 with Issue

use of org.sonar.scanner.protocol.output.ScannerReport.Issue 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

Issue (org.sonar.scanner.protocol.output.ScannerReport.Issue)12 Test (org.junit.Test)11 File (java.io.File)7 TaskResult (org.sonar.scanner.mediumtest.TaskResult)7 Flow (org.sonar.scanner.protocol.output.ScannerReport.Flow)2 IOException (java.io.IOException)1 IssueLocation (org.sonar.scanner.protocol.output.ScannerReport.IssueLocation)1