use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class FileSystemMediumTest method scanProjectWithoutProjectName.
@Test
public void scanProjectWithoutProjectName() throws IOException {
builder = createBuilder();
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(builder.put("sonar.sources", "src").build()).start();
int ref = result.getReportReader().readMetadata().getRootComponentRef();
assertThat(result.getReportReader().readComponent(ref).getName()).isEmpty();
assertThat(result.inputFiles()).hasSize(1);
assertThat(result.inputDirs()).hasSize(1);
DefaultInputFile file = (DefaultInputFile) result.inputFile("src/sample.xoo");
InputDir dir = result.inputDir("src");
assertThat(file.type()).isEqualTo(InputFile.Type.MAIN);
assertThat(file.relativePath()).isEqualTo("src/sample.xoo");
assertThat(file.language()).isEqualTo("xoo");
assertThat(dir.relativePath()).isEqualTo("src");
// file and dirs were published, since language matched xoo
assertThat(file.publish()).isTrue();
assertThat(result.getReportComponent(dir.key())).isNotNull();
assertThat(result.getReportComponent(file.key())).isNotNull();
}
use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class FileSystemMediumTest method scanBigProject.
@Test
public void scanBigProject() throws IOException {
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
int nbFiles = 100;
int ruleCount = 100000;
for (int nb = 1; nb <= nbFiles; nb++) {
File xooFile = new File(srcDir, "sample" + nb + ".xoo");
FileUtils.write(xooFile, StringUtils.repeat(StringUtils.repeat("a", 100) + "\n", ruleCount / 1000));
}
TaskResult result = tester.newTask().properties(builder.put("sonar.sources", "src").build()).start();
assertThat(result.inputFiles()).hasSize(100);
assertThat(result.inputDirs()).hasSize(1);
}
use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class SymbolMediumTest method computeSymbolReferencesWithVariableLength.
@Test
public void computeSymbolReferencesWithVariableLength() throws IOException {
File baseDir = temp.getRoot();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File xooFile = new File(srcDir, "sample.xoo");
File xooSymbolFile = new File(srcDir, "sample.xoo.symbol");
FileUtils.write(xooFile, "Sample xoo\ncontent\nanother xoo\nyet another");
// Highlight xoo symbol
FileUtils.write(xooSymbolFile, "7:10,27:32");
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.symbolReferencesFor(file, 1, 7)).containsOnly(ScannerReport.TextRange.newBuilder().setStartLine(3).setStartOffset(8).setEndLine(4).setEndOffset(1).build());
}
use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class SymbolMediumTest method computeSymbolReferencesOnTempProject.
@Test
public void computeSymbolReferencesOnTempProject() throws IOException {
File baseDir = temp.getRoot();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File xooFile = new File(srcDir, "sample.xoo");
File xooSymbolFile = new File(srcDir, "sample.xoo.symbol");
FileUtils.write(xooFile, "Sample xoo\ncontent\nanother xoo");
// Highlight xoo symbol
FileUtils.write(xooSymbolFile, "7:10,27");
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.symbolReferencesFor(file, 1, 7)).containsOnly(ScannerReport.TextRange.newBuilder().setStartLine(3).setStartOffset(8).setEndLine(3).setEndOffset(11).build());
}
use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class GenericTestExecutionMediumTest method singleReport.
@Test
public void singleReport() throws IOException {
File projectDir = new File("src/test/resources/mediumtest/xoo/sample-generic-test-exec");
TaskResult result = tester.newScanTask(new File(projectDir, "sonar-project.properties")).property("sonar.testExecutionReportPaths", "unittest.xml").start();
InputFile testFile = result.inputFile("testx/ClassOneTest.xoo");
ScannerReport.Test success = result.firstTestExecutionForName(testFile, "test1");
assertThat(success.getDurationInMs()).isEqualTo(5);
assertThat(success.getStatus()).isEqualTo(TestStatus.OK);
ScannerReport.Test skipped = result.firstTestExecutionForName(testFile, "test2");
assertThat(skipped.getDurationInMs()).isEqualTo(500);
assertThat(skipped.getStatus()).isEqualTo(TestStatus.SKIPPED);
assertThat(skipped.getMsg()).isEqualTo("short message");
assertThat(skipped.getStacktrace()).isEqualTo("other");
ScannerReport.Test failed = result.firstTestExecutionForName(testFile, "test3");
assertThat(failed.getDurationInMs()).isEqualTo(100);
assertThat(failed.getStatus()).isEqualTo(TestStatus.FAILURE);
assertThat(failed.getMsg()).isEqualTo("short");
assertThat(failed.getStacktrace()).isEqualTo("stacktrace");
ScannerReport.Test error = result.firstTestExecutionForName(testFile, "test4");
assertThat(error.getDurationInMs()).isEqualTo(500);
assertThat(error.getStatus()).isEqualTo(TestStatus.ERROR);
assertThat(error.getMsg()).isEqualTo("short");
assertThat(error.getStacktrace()).isEqualTo("stacktrace");
assertThat(result.allMeasures().get(testFile.key())).extracting("metricKey", "intValue.value", "longValue.value").containsOnly(tuple(CoreMetrics.TESTS_KEY, 3, 0L), tuple(CoreMetrics.SKIPPED_TESTS_KEY, 1, 0L), tuple(CoreMetrics.TEST_ERRORS_KEY, 1, 0L), tuple(CoreMetrics.TEST_EXECUTION_TIME_KEY, 0, 1105L), tuple(CoreMetrics.TEST_FAILURES_KEY, 1, 0L));
}
Aggregations