use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class BranchMediumTest method shouldNotSkipSensorForUnchangedFilesOnBranch.
@Test
public void shouldNotSkipSensorForUnchangedFilesOnBranch() throws Exception {
AnalysisResult result = getResult(tester.setBranchName("myBranch").setBranchTarget("master").setBranchType(BranchType.BRANCH));
final DefaultInputFile file = (DefaultInputFile) result.inputFile(FILE_PATH);
List<ScannerReport.Issue> issues = result.issuesFor(file);
assertThat(issues).isNotEmpty();
assertThat(logTester.logs()).doesNotContain(ONE_ISSUE_PER_LINE_IS_RESTRICTED_TO_CHANGED_FILES_ONLY);
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class BranchMediumTest method should_not_skip_report_for_unchanged_files_in_pr.
@Test
public void should_not_skip_report_for_unchanged_files_in_pr() {
// sanity check, normally report gets generated
AnalysisResult result = getResult(tester);
final DefaultInputFile file = (DefaultInputFile) result.inputFile(FILE_PATH);
assertThat(getResult(tester).getReportComponent(file)).isNotNull();
int fileId = file.scannerId();
assertThat(result.getReportReader().readChangesets(fileId)).isNotNull();
assertThat(result.getReportReader().hasCoverage(fileId)).isTrue();
assertThat(result.getReportReader().readFileSource(fileId)).isNotNull();
// file is not skipped for pull requests (need coverage, duplications coming soon)
AnalysisResult result2 = getResult(tester.setBranchType(BranchType.PULL_REQUEST));
final DefaultInputFile fileInPr = (DefaultInputFile) result2.inputFile(FILE_PATH);
assertThat(result2.getReportComponent(fileInPr)).isNotNull();
fileId = fileInPr.scannerId();
assertThat(result2.getReportReader().readChangesets(fileId)).isNull();
assertThat(result2.getReportReader().hasCoverage(fileId)).isTrue();
assertThat(result2.getReportReader().readFileSource(fileId)).isNull();
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class CoverageMediumTest method singleReport.
@Test
public void singleReport() throws IOException {
File baseDir = temp.getRoot();
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
File xooFile = new File(srcDir, "sample.xoo");
File xooUtCoverageFile = new File(srcDir, "sample.xoo.coverage");
FileUtils.write(xooFile, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8);
FileUtils.write(xooUtCoverageFile, "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").build()).execute();
InputFile file = result.inputFile("src/sample.xoo");
assertThat(result.coverageFor(file, 2).getHits()).isTrue();
assertThat(result.coverageFor(file, 2).getConditions()).isEqualTo(2);
assertThat(result.coverageFor(file, 2).getCoveredConditions()).isOne();
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class CoverageMediumTest method exclusionsAndForceToZeroOnModules.
// SONAR-9557
@Test
public void exclusionsAndForceToZeroOnModules() throws IOException {
File baseDir = temp.getRoot();
File srcDir = new File(baseDir, "module1/src");
srcDir.mkdir();
File xooFile1 = new File(srcDir, "sample1.xoo");
File measuresFile1 = new File(srcDir, "sample1.xoo.measures");
FileUtils.write(xooFile1, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8);
FileUtils.write(measuresFile1, "executable_lines_data:2=1;3=1;4=0", StandardCharsets.UTF_8);
File xooFile2 = new File(srcDir, "sample2.xoo");
File measuresFile2 = new File(srcDir, "sample2.xoo.measures");
FileUtils.write(xooFile2, "function foo() {\n if (a && b) {\nalert('hello');\n}\n}", StandardCharsets.UTF_8);
FileUtils.write(measuresFile2, "executable_lines_data:2=1;3=1;4=0", 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.modules", "module1").put("sonar.sources", "src").put("sonar.coverage.exclusions", "**/sample2.xoo").build()).execute();
InputFile file1 = result.inputFile("module1/src/sample1.xoo");
assertThat(result.coverageFor(file1, 1)).isNull();
assertThat(result.coverageFor(file1, 2).getHits()).isFalse();
assertThat(result.coverageFor(file1, 2).getConditions()).isZero();
assertThat(result.coverageFor(file1, 2).getCoveredConditions()).isZero();
assertThat(result.coverageFor(file1, 3).getHits()).isFalse();
assertThat(result.coverageFor(file1, 4)).isNull();
InputFile file2 = result.inputFile("module1/src/sample2.xoo");
assertThat(result.coverageFor(file2, 1)).isNull();
assertThat(result.coverageFor(file2, 2)).isNull();
assertThat(result.coverageFor(file2, 3)).isNull();
assertThat(result.coverageFor(file2, 4)).isNull();
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class CoverageMediumTest method warn_user_for_outdated_server_side_exclusions_for_multi_module_project.
@Test
public void warn_user_for_outdated_server_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, "sample.xoo");
File xooUtCoverageFileA = new File(srcDirA, "sample.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, "sample.xoo");
File xooUtCoverageFileB = new File(srcDirB, "sample.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);
tester.addProjectServerSettings("sonar.coverage.exclusions", "src/sample.xoo");
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").build()).execute();
InputFile fileA = result.inputFile("moduleA/src/sample.xoo");
assertThat(result.coverageFor(fileA, 2)).isNull();
InputFile fileB = result.inputFile("moduleB/src/sample.xoo");
assertThat(result.coverageFor(fileB, 2)).isNull();
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/sample.xoo', update this property so that patterns refer to project-relative paths.");
}
Aggregations