use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class CoverageMediumTest 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 {
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");
File xooUtCoverageFileA = new File(srcDirA, "sampleA.xoo.coverage");
FileUtils.write(xooFileA, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8);
FileUtils.write(xooUtCoverageFileA, "2:2:2:1\n3:1", StandardCharsets.UTF_8);
File xooFileB = new File(srcDirB, "sampleB.xoo");
File xooUtCoverageFileB = new File(srcDirB, "sampleB.xoo.coverage");
FileUtils.write(xooFileB, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8);
FileUtils.write(xooUtCoverageFileB, "2:2:2:1\n3:1", 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.coverage.exclusions", "src/sampleA.xoo").build()).execute();
InputFile fileA = result.inputFile("moduleA/src/sampleA.xoo");
assertThat(result.coverageFor(fileA, 2)).isNull();
InputFile fileB = result.inputFile("moduleB/src/sampleB.xoo");
assertThat(result.coverageFor(fileB, 2)).isNotNull();
assertThat(logTester.logs(LoggerLevel.WARN)).contains("Specifying module-relative paths at project level in the property 'sonar.coverage.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 CoverageMediumTest method dontFallbackOnExecutableLinesIfNoCoverageSaved.
// SONAR-11641
@Test
public void dontFallbackOnExecutableLinesIfNoCoverageSaved() throws IOException {
File baseDir = temp.getRoot();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File xooFile = new File(srcDir, "sample.xoo");
File measuresFile = new File(srcDir, "sample.xoo.measures");
File coverageFile = new File(srcDir, "sample.xoo.coverage");
FileUtils.write(xooFile, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8);
FileUtils.write(measuresFile, "# The code analyzer disagree with the coverage tool and consider some lines to be executable\nexecutable_lines_data:2=1;3=1;4=0", StandardCharsets.UTF_8);
FileUtils.write(coverageFile, "# No lines to cover in this file according to the coverage tool", 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").build()).execute();
InputFile file = result.inputFile("src/sample.xoo");
assertThat(result.coverageFor(file, 1)).isNull();
assertThat(result.coverageFor(file, 2)).isNull();
assertThat(result.coverageFor(file, 3)).isNull();
assertThat(result.coverageFor(file, 4)).isNull();
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class IssuesMediumTest method testIssueExclusionByRegexp.
@Test
public void testIssueExclusionByRegexp() throws Exception {
File projectDir = new File("test-resources/mediumtest/xoo/sample");
File tmpDir = temp.newFolder();
FileUtils.copyDirectory(projectDir, tmpDir);
AnalysisResult result = tester.newAnalysis(new File(tmpDir, "sonar-project.properties")).property("sonar.issue.ignore.allfile", "1").property("sonar.issue.ignore.allfile.1.fileRegexp", "object").execute();
assertThat(result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"))).hasSize(8);
assertThat(result.issuesFor(result.inputFile("xources/hello/helloscala.xoo"))).isEmpty();
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class IssuesMediumTest method testOneExternalIssueOnProject.
@Test
public void testOneExternalIssueOnProject() throws Exception {
File projectDir = new File("test-resources/mediumtest/xoo/sample");
File tmpDir = temp.newFolder();
FileUtils.copyDirectory(projectDir, tmpDir);
AnalysisResult result = tester.newAnalysis(new File(tmpDir, "sonar-project.properties")).property(OneExternalIssueOnProjectSensor.ACTIVATE, "true").execute();
List<ExternalIssue> externalIssues = result.externalIssuesFor(result.project());
assertThat(externalIssues).hasSize(1);
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class IssuesMediumTest method testIssueFilter.
@Test
public void testIssueFilter() throws Exception {
File projectDir = new File("test-resources/mediumtest/xoo/sample");
File tmpDir = temp.newFolder();
FileUtils.copyDirectory(projectDir, tmpDir);
AnalysisResult result = tester.newAnalysis(new File(tmpDir, "sonar-project.properties")).property("sonar.xoo.excludeAllIssuesOnOddLines", "true").execute();
List<Issue> issues = result.issuesFor(result.inputFile("xources/hello/HelloJava.xoo"));
assertThat(issues).hasSize(4);
}
Aggregations