use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class GenericCoverageMediumTest method singleReport.
@Test
public void singleReport() {
File projectDir = new File("test-resources/mediumtest/xoo/sample-generic-coverage");
AnalysisResult result = tester.setLogOutput((msg, level) -> logs.add(msg)).newAnalysis(new File(projectDir, "sonar-project.properties")).property("sonar.coverageReportPaths", "coverage.xml").execute();
InputFile noConditions = result.inputFile("xources/hello/NoConditions.xoo");
assertThat(result.coverageFor(noConditions, 6).getHits()).isTrue();
assertThat(result.coverageFor(noConditions, 6).getConditions()).isZero();
assertThat(result.coverageFor(noConditions, 6).getCoveredConditions()).isZero();
assertThat(result.coverageFor(noConditions, 7).getHits()).isFalse();
InputFile withConditions = result.inputFile("xources/hello/WithConditions.xoo");
assertThat(result.coverageFor(withConditions, 3).getHits()).isTrue();
assertThat(result.coverageFor(withConditions, 3).getConditions()).isEqualTo(2);
assertThat(result.coverageFor(withConditions, 3).getCoveredConditions()).isOne();
assertThat(logs).noneMatch(l -> l.contains("Please use 'sonar.coverageReportPaths'"));
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class GenericCoverageMediumTest method twoReports.
@Test
public void twoReports() {
File projectDir = new File("test-resources/mediumtest/xoo/sample-generic-coverage");
AnalysisResult result = tester.setLogOutput((msg, level) -> logs.add(msg)).newAnalysis(new File(projectDir, "sonar-project.properties")).property("sonar.coverageReportPaths", "coverage.xml,coverage2.xml").execute();
InputFile noConditions = result.inputFile("xources/hello/NoConditions.xoo");
assertThat(result.coverageFor(noConditions, 6).getHits()).isTrue();
assertThat(result.coverageFor(noConditions, 6).getConditions()).isZero();
assertThat(result.coverageFor(noConditions, 6).getCoveredConditions()).isZero();
assertThat(result.coverageFor(noConditions, 7).getHits()).isTrue();
InputFile withConditions = result.inputFile("xources/hello/WithConditions.xoo");
assertThat(result.coverageFor(withConditions, 3).getHits()).isTrue();
assertThat(result.coverageFor(withConditions, 3).getConditions()).isEqualTo(2);
assertThat(result.coverageFor(withConditions, 3).getCoveredConditions()).isEqualTo(2);
assertThat(logs).noneMatch(l -> l.contains("Please use 'sonar.coverageReportPaths'"));
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class FileSystemMediumTest method test_inclusions_on_multi_modules.
@Test
public void test_inclusions_on_multi_modules() throws IOException {
File baseDir = temp.getRoot();
File baseDirModuleA = new File(baseDir, "moduleA");
File baseDirModuleB = new File(baseDir, "moduleB");
File srcDirA = new File(baseDirModuleA, "tests");
srcDirA.mkdirs();
File srcDirB = new File(baseDirModuleB, "tests");
srcDirB.mkdirs();
writeFile(srcDirA, "sampleTestA.xoo", "Sample xoo\ncontent");
writeFile(srcDirB, "sampleTestB.xoo", "Sample xoo\ncontent");
final ImmutableMap.Builder<String, String> builder = ImmutableMap.<String, String>builder().put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.sources", "").put("sonar.tests", "tests").put("sonar.modules", "moduleA,moduleB");
AnalysisResult result = tester.newAnalysis().properties(builder.build()).execute();
assertThat(result.inputFiles()).hasSize(2);
InputFile fileA = result.inputFile("moduleA/tests/sampleTestA.xoo");
assertThat(fileA).isNotNull();
InputFile fileB = result.inputFile("moduleB/tests/sampleTestB.xoo");
assertThat(fileB).isNotNull();
result = tester.newAnalysis().properties(builder.put("sonar.test.inclusions", "moduleA/tests/**").build()).execute();
assertThat(result.inputFiles()).hasSize(1);
fileA = result.inputFile("moduleA/tests/sampleTestA.xoo");
assertThat(fileA).isNotNull();
fileB = result.inputFile("moduleB/tests/sampleTestB.xoo");
assertThat(fileB).isNull();
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class FileSystemMediumTest method scan_project_without_name.
@Test
public void scan_project_without_name() throws IOException {
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
writeFile(srcDir, "sample.xoo", "Sample xoo\ncontent");
AnalysisResult result = tester.newAnalysis().properties(builder.put("sonar.sources", "src").build()).execute();
int ref = result.getReportReader().readMetadata().getRootComponentRef();
assertThat(result.getReportReader().readComponent(ref).getName()).isEmpty();
assertThat(result.inputFiles()).hasSize(1);
DefaultInputFile file = (DefaultInputFile) result.inputFile("src/sample.xoo");
assertThat(file.type()).isEqualTo(InputFile.Type.MAIN);
assertThat(file.relativePath()).isEqualTo("src/sample.xoo");
assertThat(file.language()).isEqualTo("xoo");
// file was published, since language matched xoo
assertThat(file.isPublished()).isTrue();
assertThat(result.getReportComponent(file.scannerId())).isNotNull();
}
use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.
the class FileSystemMediumTest method language_without_publishAllFiles_should_not_auto_publish_files.
@Test
public void language_without_publishAllFiles_should_not_auto_publish_files() throws IOException {
File srcDir = new File(baseDir, "src");
srcDir.mkdir();
writeFile(srcDir, "sample.xoo3", "Sample xoo\ncontent");
writeFile(srcDir, "sample2.xoo3", "Sample xoo 2\ncontent");
AnalysisResult result = tester.newAnalysis().properties(builder.put("sonar.sources", "src").build()).execute();
assertThat(result.inputFiles()).extracting(InputFile::filename, InputFile::language, f -> ((DefaultInputFile) f).isPublished()).containsOnly(tuple("sample.xoo3", "xoo3", false), tuple("sample2.xoo3", "xoo3", false));
assertThat(result.getReportReader().readComponent(result.getReportReader().readMetadata().getRootComponentRef()).getChildRefCount()).isZero();
}
Aggregations