use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class TestExecutionMediumTest method unitTests.
@Test
public void unitTests() throws IOException {
File baseDir = temp.getRoot();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File testDir = new File(baseDir, "test");
testDir.mkdir();
File xooFile = new File(srcDir, "sample.xoo");
FileUtils.write(xooFile, "foo");
File xooTestFile = new File(testDir, "sampleTest.xoo");
FileUtils.write(xooTestFile, "failure\nerror\nok\nskipped");
File xooTestExecutionFile = new File(testDir, "sampleTest.xoo.test");
FileUtils.write(xooTestExecutionFile, "skipped::::SKIPPED:UNIT\n" + "failure:2:Failure::FAILURE:UNIT\n" + "error:2:Error:The stack:ERROR:UNIT\n" + "success:4:::OK:INTEGRATION");
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.tests", "test").build()).start();
InputFile file = result.inputFile("test/sampleTest.xoo");
org.sonar.scanner.protocol.output.ScannerReport.Test success = result.firstTestExecutionForName(file, "success");
assertThat(success.getDurationInMs()).isEqualTo(4);
assertThat(success.getStatus()).isEqualTo(TestStatus.OK);
org.sonar.scanner.protocol.output.ScannerReport.Test error = result.firstTestExecutionForName(file, "error");
assertThat(error.getDurationInMs()).isEqualTo(2);
assertThat(error.getStatus()).isEqualTo(TestStatus.ERROR);
assertThat(error.getMsg()).isEqualTo("Error");
assertThat(error.getStacktrace()).isEqualTo("The stack");
}
use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class BranchMediumTest method scanProjectWithBranch.
@Test
public void scanProjectWithBranch() throws IOException {
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File xooFile = new File(srcDir, "sample.xoo");
FileUtils.write(xooFile, "Sample xoo\ncontent");
TaskResult result = tester.newTask().properties(ImmutableMap.<String, String>builder().putAll(commonProps).put("sonar.branch", "branch").build()).start();
assertThat(result.inputFiles()).hasSize(1);
assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:src/sample.xoo");
DefaultInputFile inputfile = (DefaultInputFile) result.inputFile("src/sample.xoo");
assertThat(result.getReportReader().readComponent(inputfile.batchId()).getPath()).isEqualTo("src/sample.xoo");
assertThat(result.getReportReader().readMetadata().getBranch()).isEqualTo("branch");
result = tester.newTask().properties(ImmutableMap.<String, String>builder().putAll(commonProps).put("sonar.branch", "").build()).start();
assertThat(result.inputFiles()).hasSize(1);
assertThat(result.inputFile("src/sample.xoo").key()).isEqualTo("com.foo.project:src/sample.xoo");
}
use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class ProjectBuilderMediumTest method testProjectBuilderWithBranch.
@Test
public void testProjectBuilderWithBranch() 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.branch", "my-branch").put("sonar.sources", ".").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));
}
use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class HighlightingMediumTest method computeSyntaxHighlightingOnTempProject.
@Test
public void computeSyntaxHighlightingOnTempProject() throws IOException {
File baseDir = temp.newFolder();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File xooFile = new File(srcDir, "sample.xoo");
File xoohighlightingFile = new File(srcDir, "sample.xoo.highlighting");
FileUtils.write(xooFile, "Sample xoo\ncontent plop");
FileUtils.write(xoohighlightingFile, "0:10:s\n11:18:k");
TaskResult result = tester.newTask().properties(ImmutableMap.<String, String>builder().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.highlightingTypeFor(file, 1, 0)).containsExactly(TypeOfText.STRING);
assertThat(result.highlightingTypeFor(file, 1, 9)).containsExactly(TypeOfText.STRING);
assertThat(result.highlightingTypeFor(file, 2, 0)).containsExactly(TypeOfText.KEYWORD);
assertThat(result.highlightingTypeFor(file, 2, 8)).isEmpty();
}
use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class IssuesIssuesModeMediumTest method testIssueCallback.
@Test
public void testIssueCallback() throws Exception {
File projectDir = new File(IssuesMediumTest.class.getResource("/mediumtest/xoo/sample").toURI());
File tmpDir = temp.getRoot();
FileUtils.copyDirectory(projectDir, tmpDir);
IssueRecorder issueListener = new IssueRecorder();
TaskResult result1 = testerPreview.newScanTask(new File(tmpDir, "sonar-project.properties")).setIssueListener(issueListener).property(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES).start();
assertThat(result1.trackedIssues()).hasSize(14);
assertThat(issueListener.issueList).hasSize(14);
issueListener = new IssueRecorder();
TaskResult result2 = testerPreview.newScanTask(new File(tmpDir, "sonar-project.properties")).setIssueListener(issueListener).property(CoreProperties.ANALYSIS_MODE, CoreProperties.ANALYSIS_MODE_ISSUES).start();
assertThat(result2.trackedIssues()).hasSize(14);
assertThat(issueListener.issueList).hasSize(14);
}
Aggregations