use of org.sonar.scanner.mediumtest.AnalysisResult 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, "1:7:1:10,3:8:3:11");
AnalysisResult result = tester.newAnalysis().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()).execute();
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.AnalysisResult 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, "1:7:1:10,3:8:4:1");
AnalysisResult result = tester.newAnalysis().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()).execute();
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.AnalysisResult in project sonarqube by SonarSource.
the class GenericTestExecutionMediumTest method singleReport.
@Test
public void singleReport() {
File projectDir = new File("test-resources/mediumtest/xoo/sample-generic-test-exec");
AnalysisResult result = tester.setLogOutput((msg, level) -> logs.add(msg)).newAnalysis(new File(projectDir, "sonar-project.properties")).property("sonar.testExecutionReportPaths", "unittest.xml").execute();
InputFile testFile = result.inputFile("testx/ClassOneTest.xoo");
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));
assertThat(logs).noneMatch(l -> l.contains("Please use 'sonar.testExecutionReportPaths'"));
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class CpdMediumTest method warn_user_for_outdated_inherited_scanner_side_exclusions_for_multi_module_project.
@Test
public void warn_user_for_outdated_inherited_scanner_side_exclusions_for_multi_module_project() throws IOException {
String duplicatedStuff = "Sample xoo\ncontent\n" + "foo\nbar\ntoto\ntiti\n" + "foo\nbar\ntoto\ntiti\n" + "bar\ntoto\ntiti\n" + "foo\nbar\ntoto\ntiti";
File baseDir = temp.getRoot();
File baseDirModuleA = new File(baseDir, "moduleA");
File baseDirModuleB = new File(baseDir, "moduleB");
File srcDirA = new File(baseDirModuleA, "src");
srcDirA.mkdirs();
File srcDirB = new File(baseDirModuleB, "src");
srcDirB.mkdirs();
File xooFileA = new File(srcDirA, "sampleA.xoo");
FileUtils.write(xooFileA, duplicatedStuff, StandardCharsets.UTF_8);
File xooFileB = new File(srcDirB, "sampleB.xoo");
FileUtils.write(xooFileB, duplicatedStuff, StandardCharsets.UTF_8);
AnalysisResult result = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.sources", "src").put("sonar.modules", "moduleA,moduleB").put("sonar.cpd.xoo.minimumTokens", "10").put("sonar.cpd.exclusions", "src/sampleA.xoo").build()).execute();
InputFile inputFile1 = result.inputFile("moduleA/src/sampleA.xoo");
InputFile inputFile2 = result.inputFile("moduleB/src/sampleB.xoo");
List<ScannerReport.Duplication> duplicationGroupsFile1 = result.duplicationsFor(inputFile1);
assertThat(duplicationGroupsFile1).isEmpty();
List<ScannerReport.Duplication> duplicationGroupsFile2 = result.duplicationsFor(inputFile2);
assertThat(duplicationGroupsFile2).isEmpty();
assertThat(logTester.logs(LoggerLevel.WARN)).contains("Specifying module-relative paths at project level in the property 'sonar.cpd.exclusions' is deprecated. " + "To continue matching files like 'moduleA/src/sampleA.xoo', update this property so that patterns refer to project-relative paths.");
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class CpdMediumTest method module_level_exclusions_override_parent_for_multi_module_project.
@Test
public void module_level_exclusions_override_parent_for_multi_module_project() throws IOException {
String duplicatedStuff = "Sample xoo\ncontent\n" + "foo\nbar\ntoto\ntiti\n" + "foo\nbar\ntoto\ntiti\n" + "bar\ntoto\ntiti\n" + "foo\nbar\ntoto\ntiti";
File baseDir = temp.getRoot();
File baseDirModuleA = new File(baseDir, "moduleA");
File baseDirModuleB = new File(baseDir, "moduleB");
File srcDirA = new File(baseDirModuleA, "src");
srcDirA.mkdirs();
File srcDirB = new File(baseDirModuleB, "src");
srcDirB.mkdirs();
File xooFileA = new File(srcDirA, "sampleA.xoo");
FileUtils.write(xooFileA, duplicatedStuff, StandardCharsets.UTF_8);
File xooFileB = new File(srcDirB, "sampleB.xoo");
FileUtils.write(xooFileB, duplicatedStuff, StandardCharsets.UTF_8);
AnalysisResult result = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.sources", "src").put("sonar.modules", "moduleA,moduleB").put("sonar.cpd.xoo.minimumTokens", "10").put("sonar.cpd.exclusions", "**/*").put("moduleA.sonar.cpd.exclusions", "**/*.nothing").put("moduleB.sonar.cpd.exclusions", "**/*.nothing").build()).execute();
InputFile inputFile1 = result.inputFile("moduleA/src/sampleA.xoo");
InputFile inputFile2 = result.inputFile("moduleB/src/sampleB.xoo");
List<ScannerReport.Duplication> duplicationGroupsFile1 = result.duplicationsFor(inputFile1);
assertThat(duplicationGroupsFile1).isNotEmpty();
List<ScannerReport.Duplication> duplicationGroupsFile2 = result.duplicationsFor(inputFile2);
assertThat(duplicationGroupsFile2).isNotEmpty();
}
Aggregations