Search in sources :

Example 16 with AnalysisResult

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

the class SymbolMediumTest method computeSymbolReferencesOnTempProject.

@Test
public void computeSymbolReferencesOnTempProject() throws IOException {
    File baseDir = temp.getRoot();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    File xooSymbolFile = new File(srcDir, "sample.xoo.symbol");
    FileUtils.write(xooFile, "Sample xoo\ncontent\nanother xoo");
    // Highlight xoo symbol
    FileUtils.write(xooSymbolFile, "1:7:1:10,3:8:3:11");
    AnalysisResult result = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.task", "scan").put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project").put("sonar.sources", "src").build()).execute();
    InputFile file = result.inputFile("src/sample.xoo");
    assertThat(result.symbolReferencesFor(file, 1, 7)).containsOnly(ScannerReport.TextRange.newBuilder().setStartLine(3).setStartOffset(8).setEndLine(3).setEndOffset(11).build());
}
Also used : 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 17 with AnalysisResult

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

the class SymbolMediumTest method computeSymbolReferencesWithVariableLength.

@Test
public void computeSymbolReferencesWithVariableLength() throws IOException {
    File baseDir = temp.getRoot();
    File srcDir = new File(baseDir, "src");
    srcDir.mkdir();
    File xooFile = new File(srcDir, "sample.xoo");
    File xooSymbolFile = new File(srcDir, "sample.xoo.symbol");
    FileUtils.write(xooFile, "Sample xoo\ncontent\nanother xoo\nyet another");
    // Highlight xoo symbol
    FileUtils.write(xooSymbolFile, "1:7:1:10,3:8:4:1");
    AnalysisResult result = tester.newAnalysis().properties(ImmutableMap.<String, String>builder().put("sonar.task", "scan").put("sonar.projectBaseDir", baseDir.getAbsolutePath()).put("sonar.projectKey", "com.foo.project").put("sonar.projectName", "Foo Project").put("sonar.projectVersion", "1.0-SNAPSHOT").put("sonar.projectDescription", "Description of Foo Project").put("sonar.sources", "src").build()).execute();
    InputFile file = result.inputFile("src/sample.xoo");
    assertThat(result.symbolReferencesFor(file, 1, 7)).containsOnly(ScannerReport.TextRange.newBuilder().setStartLine(3).setStartOffset(8).setEndLine(4).setEndOffset(1).build());
}
Also used : 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 18 with AnalysisResult

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

the class GenericTestExecutionMediumTest method singleReport.

@Test
public void singleReport() {
    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").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, 3, 0L), tuple(CoreMetrics.SKIPPED_TESTS_KEY, 1, 0L), tuple(CoreMetrics.TEST_ERRORS_KEY, 1, 0L), tuple(CoreMetrics.TEST_EXECUTION_TIME_KEY, 0, 1105L), 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 19 with AnalysisResult

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

the class CpdMediumTest 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 {
    String duplicatedStuff = "Sample xoo\ncontent\n" + "foo\nbar\ntoto\ntiti\n" + "foo\nbar\ntoto\ntiti\n" + "bar\ntoto\ntiti\n" + "foo\nbar\ntoto\ntiti";
    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");
    FileUtils.write(xooFileA, duplicatedStuff, StandardCharsets.UTF_8);
    File xooFileB = new File(srcDirB, "sampleB.xoo");
    FileUtils.write(xooFileB, duplicatedStuff, 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.cpd.xoo.minimumTokens", "10").put("sonar.cpd.exclusions", "src/sampleA.xoo").build()).execute();
    InputFile inputFile1 = result.inputFile("moduleA/src/sampleA.xoo");
    InputFile inputFile2 = result.inputFile("moduleB/src/sampleB.xoo");
    List<ScannerReport.Duplication> duplicationGroupsFile1 = result.duplicationsFor(inputFile1);
    assertThat(duplicationGroupsFile1).isEmpty();
    List<ScannerReport.Duplication> duplicationGroupsFile2 = result.duplicationsFor(inputFile2);
    assertThat(duplicationGroupsFile2).isEmpty();
    assertThat(logTester.logs(LoggerLevel.WARN)).contains("Specifying module-relative paths at project level in the property 'sonar.cpd.exclusions' is deprecated. " + "To continue matching files like 'moduleA/src/sampleA.xoo', update this property so that patterns refer to project-relative paths.");
}
Also used : 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 20 with AnalysisResult

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

the class CpdMediumTest method module_level_exclusions_override_parent_for_multi_module_project.

@Test
public void module_level_exclusions_override_parent_for_multi_module_project() throws IOException {
    String duplicatedStuff = "Sample xoo\ncontent\n" + "foo\nbar\ntoto\ntiti\n" + "foo\nbar\ntoto\ntiti\n" + "bar\ntoto\ntiti\n" + "foo\nbar\ntoto\ntiti";
    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");
    FileUtils.write(xooFileA, duplicatedStuff, StandardCharsets.UTF_8);
    File xooFileB = new File(srcDirB, "sampleB.xoo");
    FileUtils.write(xooFileB, duplicatedStuff, 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.cpd.xoo.minimumTokens", "10").put("sonar.cpd.exclusions", "**/*").put("moduleA.sonar.cpd.exclusions", "**/*.nothing").put("moduleB.sonar.cpd.exclusions", "**/*.nothing").build()).execute();
    InputFile inputFile1 = result.inputFile("moduleA/src/sampleA.xoo");
    InputFile inputFile2 = result.inputFile("moduleB/src/sampleB.xoo");
    List<ScannerReport.Duplication> duplicationGroupsFile1 = result.duplicationsFor(inputFile1);
    assertThat(duplicationGroupsFile1).isNotEmpty();
    List<ScannerReport.Duplication> duplicationGroupsFile2 = result.duplicationsFor(inputFile2);
    assertThat(duplicationGroupsFile2).isNotEmpty();
}
Also used : 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)

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