use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class IssuesMediumTest method testIssueDetails.
@Test
public void testIssueDetails() throws IOException {
File baseDir = temp.newFolder();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File xooFile = new File(srcDir, "sample.xoo");
FileUtils.write(xooFile, "1\n2\n3\n4\n5\n6\n7\n8\n9\n10");
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).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 MeasuresMediumTest method deprecatedCoverageMeasuresAreConverted.
@Test
public void deprecatedCoverageMeasuresAreConverted() throws IOException {
File xooFile = new File(srcDir, "sample.xoo");
FileUtils.write(xooFile, "Sample xoo\n\ncontent");
File measures = new File(srcDir, "sample.xoo.measures");
FileUtils.write(measures, "it_lines_to_cover:2");
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();
Map<String, List<Measure>> allMeasures = result.allMeasures();
assertThat(allMeasures.get("com.foo.project:src/sample.xoo")).extracting("metricKey", "intValue.value").containsOnly(tuple("lines_to_cover", 2));
assertThat(logTester.logs(LoggerLevel.WARN)).contains("Coverage measure for metric 'lines_to_cover' should not be saved directly by a Sensor. Plugin should be updated to use SensorContext::newCoverage instead.");
}
use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class FileSystemMediumTest method fileInclusionsExclusions.
@Test
public void fileInclusionsExclusions() throws IOException {
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File xooFile = new File(srcDir, "sample.xoo");
FileUtils.write(xooFile, "Sample xoo\ncontent");
File xooFile2 = new File(baseDir, "another.xoo");
FileUtils.write(xooFile2, "Sample xoo 2\ncontent");
File testDir = new File(baseDir, "test");
testDir.mkdir();
File xooTestFile = new File(baseDir, "sampleTest2.xoo");
FileUtils.write(xooTestFile, "Sample test xoo\ncontent");
File xooTestFile2 = new File(testDir, "sampleTest.xoo");
FileUtils.write(xooTestFile2, "Sample test xoo 2\ncontent");
TaskResult result = tester.newTask().properties(builder.put("sonar.sources", "src,another.xoo").put("sonar.tests", "test,sampleTest2.xoo").put("sonar.inclusions", "src/**").put("sonar.exclusions", "**/another.*").put("sonar.test.inclusions", "**/sampleTest*.*").put("sonar.test.exclusions", "**/sampleTest2.xoo").build()).start();
assertThat(result.inputFiles()).hasSize(2);
}
use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class FileSystemMediumTest method dontPublishFilesWithoutDetectedLanguage.
@Test
public void dontPublishFilesWithoutDetectedLanguage() throws IOException {
builder = createBuilder();
Path mainDir = baseDir.toPath().resolve("src").resolve("main");
Files.createDirectories(mainDir);
Path testDir = baseDir.toPath().resolve("src").resolve("test");
Files.createDirectories(testDir);
Path testXooFile = testDir.resolve("sample.java");
Files.write(testXooFile, "Sample xoo\ncontent".getBytes(StandardCharsets.UTF_8));
Path xooFile = mainDir.resolve("sample.xoo");
Files.write(xooFile, "Sample xoo\ncontent".getBytes(StandardCharsets.UTF_8));
Path javaFile = mainDir.resolve("sample.java");
Files.write(javaFile, "Sample xoo\ncontent".getBytes(StandardCharsets.UTF_8));
TaskResult result = tester.newTask().properties(builder.put("sonar.sources", "src/main").put("sonar.tests", "src/test").build()).start();
assertThat(logs.getAllAsString()).contains("3 files indexed");
assertThat(logs.getAllAsString()).contains("'src/main/sample.xoo' generated metadata");
assertThat(logs.getAllAsString()).doesNotContain("'src/main/sample.java' generated metadata");
assertThat(logs.getAllAsString()).doesNotContain("'src/test/sample.java' generated metadata");
DefaultInputFile javaInputFile = (DefaultInputFile) result.inputFile("src/main/sample.java");
assertThat(result.getReportComponent(javaInputFile.key())).isNull();
}
use of org.sonar.scanner.mediumtest.TaskResult in project sonarqube by SonarSource.
the class FileSystemMediumTest method publishFilesWithIssues.
@Test
public void publishFilesWithIssues() throws IOException {
ScannerMediumTester tester2 = ScannerMediumTester.builder().registerPlugin("xoo", new XooPlugin()).addDefaultQProfile("xoo", "Sonar Way").addRules(new XooRulesDefinition()).addActiveRule("xoo", "OneIssueOnDirPerFile", null, "OneIssueOnDirPerFile", "MAJOR", null, "xoo").build();
tester2.start();
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 = tester2.newTask().properties(builder.put("sonar.sources", "src").build()).start();
DefaultInputFile file = (DefaultInputFile) result.inputFile("src/sample.xoo");
InputDir dir = result.inputDir("src");
assertThat(file.publish()).isTrue();
assertThat(result.getReportComponent(dir.key())).isNotNull();
assertThat(result.getReportComponent(file.key())).isNotNull();
tester2.stop();
}
Aggregations