Search in sources :

Example 1 with AnalysisResult

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'"));
}
Also used : InputFile(org.sonar.api.batch.fs.InputFile) XooPlugin(org.sonar.xoo.XooPlugin) List(java.util.List) Rule(org.junit.Rule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) ScannerMediumTester(org.sonar.scanner.mediumtest.ScannerMediumTester) AnalysisResult(org.sonar.scanner.mediumtest.AnalysisResult) File(java.io.File) ArrayList(java.util.ArrayList) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) AnalysisResult(org.sonar.scanner.mediumtest.AnalysisResult) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 2 with AnalysisResult

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'"));
}
Also used : InputFile(org.sonar.api.batch.fs.InputFile) XooPlugin(org.sonar.xoo.XooPlugin) List(java.util.List) Rule(org.junit.Rule) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Test(org.junit.Test) ScannerMediumTester(org.sonar.scanner.mediumtest.ScannerMediumTester) AnalysisResult(org.sonar.scanner.mediumtest.AnalysisResult) File(java.io.File) ArrayList(java.util.ArrayList) InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) AnalysisResult(org.sonar.scanner.mediumtest.AnalysisResult) InputFile(org.sonar.api.batch.fs.InputFile) Test(org.junit.Test)

Example 3 with AnalysisResult

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();
}
Also used : InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) ImmutableMap(com.google.common.collect.ImmutableMap) AnalysisResult(org.sonar.scanner.mediumtest.AnalysisResult) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Test(org.junit.Test)

Example 4 with AnalysisResult

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();
}
Also used : DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) AnalysisResult(org.sonar.scanner.mediumtest.AnalysisResult) Test(org.junit.Test)

Example 5 with AnalysisResult

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();
}
Also used : InputFile(org.sonar.api.batch.fs.InputFile) XooPlugin(org.sonar.xoo.XooPlugin) StringUtils(org.apache.commons.lang.StringUtils) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Random(java.util.Random) GlobalProjectSensor(org.sonar.xoo.global.GlobalProjectSensor) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) MessageException(org.sonar.api.utils.MessageException) PathUtils(org.sonar.api.utils.PathUtils) AnalysisBuilder(org.sonar.scanner.mediumtest.ScannerMediumTester.AnalysisBuilder) Path(java.nio.file.Path) Before(org.junit.Before) ImmutableMap(com.google.common.collect.ImmutableMap) Files(java.nio.file.Files) System2(org.sonar.api.utils.System2) Assertions.tuple(org.assertj.core.api.Assertions.tuple) CoreProperties(org.sonar.api.CoreProperties) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) Test(org.junit.Test) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) Rule(org.junit.Rule) LogTester(org.sonar.api.utils.log.LogTester) XooRulesDefinition(org.sonar.xoo.rule.XooRulesDefinition) SonarEdition(org.sonar.api.SonarEdition) ScannerMediumTester(org.sonar.scanner.mediumtest.ScannerMediumTester) DeprecatedGlobalSensor(org.sonar.xoo.global.DeprecatedGlobalSensor) Assume.assumeTrue(org.junit.Assume.assumeTrue) AnalysisResult(org.sonar.scanner.mediumtest.AnalysisResult) TemporaryFolder(org.junit.rules.TemporaryFolder) LoggerLevel(org.sonar.api.utils.log.LoggerLevel) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) InputFile(org.sonar.api.batch.fs.InputFile) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) AnalysisResult(org.sonar.scanner.mediumtest.AnalysisResult) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)86 AnalysisResult (org.sonar.scanner.mediumtest.AnalysisResult)86 File (java.io.File)80 InputFile (org.sonar.api.batch.fs.InputFile)54 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)33 ExternalIssue (org.sonar.scanner.protocol.output.ScannerReport.ExternalIssue)15 Issue (org.sonar.scanner.protocol.output.ScannerReport.Issue)15 List (java.util.List)6 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)6 Rule (org.junit.Rule)6 ScannerMediumTester (org.sonar.scanner.mediumtest.ScannerMediumTester)6 ScannerReport (org.sonar.scanner.protocol.output.ScannerReport)6 XooPlugin (org.sonar.xoo.XooPlugin)6 ImmutableMap (com.google.common.collect.ImmutableMap)4 ArrayList (java.util.ArrayList)4 Assertions.tuple (org.assertj.core.api.Assertions.tuple)3 AnalysisBuilder (org.sonar.scanner.mediumtest.ScannerMediumTester.AnalysisBuilder)3 XooRulesDefinition (org.sonar.xoo.rule.XooRulesDefinition)3 IOException (java.io.IOException)2 StandardCharsets (java.nio.charset.StandardCharsets)2