Search in sources :

Example 46 with AnalysisResult

use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.

the class GenericTestExecutionMediumTest method twoReports.

@Test
public void twoReports() {
    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,unittest2.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, 4, 0L), tuple(CoreMetrics.SKIPPED_TESTS_KEY, 2, 0L), tuple(CoreMetrics.TEST_ERRORS_KEY, 1, 0L), tuple(CoreMetrics.TEST_EXECUTION_TIME_KEY, 0, 1610L), tuple(CoreMetrics.TEST_FAILURES_KEY, 1, 0L));
    assertThat(logs).noneMatch(l -> l.contains("Please use 'sonar.testExecutionReportPaths'"));
}
Also used : InputFile(org.sonar.api.batch.fs.InputFile) XooPlugin(org.sonar.xoo.XooPlugin) List(java.util.List) Rule(org.junit.Rule) Assertions.tuple(org.assertj.core.api.Assertions.tuple) 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) CoreMetrics(org.sonar.api.measures.CoreMetrics) 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 47 with AnalysisResult

use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.

the class CpdMediumTest method testFilesWithoutBlocks.

@Test
public void testFilesWithoutBlocks() throws IOException {
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    String file1 = "Sample xoo\ncontent\n" + "foo\nbar\ntoto\ntiti\n" + "foo\nbar\ntoto\ntiti\n" + "bar\ntoto\ntiti\n" + "foo\nbar\ntoto\ntiti";
    String file2 = "string\n";
    File xooFile1 = new File(srcDir, "sample1.xoo");
    FileUtils.write(xooFile1, file1, StandardCharsets.UTF_8);
    File xooFile2 = new File(srcDir, "sample2.xoo");
    FileUtils.write(xooFile2, file2, StandardCharsets.UTF_8);
    AnalysisResult result = tester.newAnalysis().properties(builder.put("sonar.sources", "src").put("sonar.cpd.xoo.minimumTokens", "10").put("sonar.verbose", "true").build()).execute();
    assertThat(result.inputFiles()).hasSize(2);
    assertThat(logTester.logs()).contains("Not enough content in 'src/sample2.xoo' to have CPD blocks, it will not be part of the duplication detection");
    assertThat(logTester.logs()).contains("CPD Executor 1 file had no CPD blocks");
}
Also used : InputFile(org.sonar.api.batch.fs.InputFile) File(java.io.File) AnalysisResult(org.sonar.scanner.mediumtest.AnalysisResult) Test(org.junit.Test)

Example 48 with AnalysisResult

use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.

the class FileSystemMediumTest method scanProjectWithWrongCase.

// SONAR-6719
@Test
public void scanProjectWithWrongCase() {
    // To please the quality gate, don't use assumeTrue, or the test will be reported as skipped
    File projectDir = new File("test-resources/mediumtest/xoo/sample");
    AnalysisBuilder analysis = tester.newAnalysis(new File(projectDir, "sonar-project.properties")).property("sonar.sources", "XOURCES").property("sonar.tests", "TESTX").property("sonar.scm.exclusions.disabled", "true");
    if (System2.INSTANCE.isOsWindows()) {
        // Windows is file path case-insensitive
        AnalysisResult result = analysis.execute();
        assertThat(result.inputFiles()).hasSize(8);
        assertThat(result.inputFiles()).extractingResultOf("relativePath").containsOnly("testx/ClassOneTest.xoo.measures", "xources/hello/helloscala.xoo.measures", "xources/hello/HelloJava.xoo.measures", "testx/ClassOneTest.xoo", "xources/hello/HelloJava.xoo.scm", "xources/hello/helloscala.xoo", "testx/ClassOneTest.xoo.scm", "xources/hello/HelloJava.xoo");
    } else if (System2.INSTANCE.isOsMac()) {
        AnalysisResult result = analysis.execute();
        assertThat(result.inputFiles()).hasSize(8);
        assertThat(result.inputFiles()).extractingResultOf("relativePath").containsOnly("TESTX/ClassOneTest.xoo.measures", "XOURCES/hello/helloscala.xoo.measures", "XOURCES/hello/HelloJava.xoo.measures", "TESTX/ClassOneTest.xoo", "XOURCES/hello/HelloJava.xoo.scm", "XOURCES/hello/helloscala.xoo", "TESTX/ClassOneTest.xoo.scm", "XOURCES/hello/HelloJava.xoo");
    } else {
        assertThatThrownBy(() -> analysis.execute()).isInstanceOf(MessageException.class).hasMessageContaining("The folder 'TESTX' does not exist for 'sample'");
    }
}
Also used : AnalysisBuilder(org.sonar.scanner.mediumtest.ScannerMediumTester.AnalysisBuilder) 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 49 with AnalysisResult

use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.

the class FileSystemMediumTest method index_basedir_by_default.

@Test
public void index_basedir_by_default() throws IOException {
    writeFile(baseDir, "sample.xoo", "Sample xoo\ncontent");
    AnalysisResult result = tester.newAnalysis().properties(builder.build()).execute();
    assertThat(logTester.logs()).contains("1 file indexed");
    assertThat(result.inputFile("sample.xoo")).isNotNull();
}
Also used : AnalysisResult(org.sonar.scanner.mediumtest.AnalysisResult) Test(org.junit.Test)

Example 50 with AnalysisResult

use of org.sonar.scanner.mediumtest.AnalysisResult in project sonarqube by SonarSource.

the class FileSystemMediumTest method scanMultiModuleProject.

@Test
public void scanMultiModuleProject() {
    File projectDir = new File("test-resources/mediumtest/xoo/multi-modules-sample");
    AnalysisResult result = tester.newAnalysis(new File(projectDir, "sonar-project.properties")).execute();
    assertThat(result.inputFiles()).hasSize(4);
}
Also used : 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