Search in sources :

Example 6 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.

the class SurefireUtilsTest method should_only_use_new_property_if_both_set.

@Test
public void should_only_use_new_property_if_both_set() {
    MapSettings settings = new MapSettings();
    settings.setProperty("sonar.junit.reportsPath", "../shouldGetReportsPathFromDeprecatedProperty/target/surefire");
    settings.setProperty("sonar.junit.reportPaths", "target/surefire,submodule/target/surefire");
    DefaultFileSystem fs = new DefaultFileSystem(new File("src/test/resources/org/sonar/plugins/surefire/api/SurefireUtilsTest/shouldGetReportsPathFromProperty"));
    PathResolver pathResolver = new PathResolver();
    assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
    List<File> directories = SurefireUtils.getReportsDirectories(settings.asConfig(), fs, pathResolver);
    assertThat(directories).hasSize(2);
    File directory1 = directories.get(0);
    assertThat(directory1.exists()).isTrue();
    assertThat(directory1.isDirectory()).isTrue();
    File directory2 = directories.get(1);
    assertThat(directory2.exists()).isTrue();
    assertThat(directory2.isDirectory()).isTrue();
    assertThat(logTester.logs(LoggerLevel.DEBUG)).contains("Property 'sonar.junit.reportsPath' is deprecated and will be ignored, as property 'sonar.junit.reportPaths' is also set.");
    assertThat(logTester.logs(LoggerLevel.INFO)).doesNotContain("Property 'sonar.junit.reportsPath' is deprecated. Use property 'sonar.junit.reportPaths' instead.");
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) PathResolver(org.sonar.api.scan.filesystem.PathResolver) File(java.io.File) DefaultFileSystem(org.sonar.api.batch.fs.internal.DefaultFileSystem) Test(org.junit.Test)

Example 7 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonar-java by SonarSource.

the class JaCoCoSensorTest method should_log_when_class_are_not_matching_with_report.

@Test
public void should_log_when_class_are_not_matching_with_report() throws Exception {
    String testDir = "/org/sonar/plugins/jacoco/JaCoCoNoMatch/";
    outputDir = TestUtils.getResource(testDir);
    jacocoExecutionData = new File(outputDir, "jacoco.exec");
    Files.copy(TestUtils.getResource(testDir + "org/foo/bar/Example2.class.toCopy"), new File(outputDir, "org/foo/bar/Example2.class"));
    Files.copy(TestUtils.getResource(testDir + "Example.class.toCopy"), new File(outputDir, "Example.class"));
    DefaultInputFile resource = new TestInputFileBuilder("", "").setLines(10).build();
    when(javaResourceLocator.findResourceByClassName(anyString())).thenReturn(resource);
    when(javaClasspath.getBinaryDirs()).thenReturn(ImmutableList.of(outputDir));
    SensorContextTester context = SensorContextTester.create(outputDir);
    context.setRuntime(SonarRuntimeImpl.forSonarQube(SQ_6_7, SonarQubeSide.SCANNER));
    context.fileSystem().setWorkDir(temp.newFolder().toPath());
    context.setSettings(new MapSettings().setProperty(REPORT_PATHS_PROPERTY, jacocoExecutionData.getAbsolutePath()));
    sensor.execute(context);
    List<String> warnLogs = logTester.logs(LoggerLevel.WARN);
    assertThat(warnLogs).contains("The following class(es) did not match with execution data:", "> 'org/foo/bar/Example2'", "> 'Example'", "In order to have accurate coverage measures, the same class files must be used as at runtime for report generation.");
}
Also used : TestInputFileBuilder(org.sonar.api.batch.fs.internal.TestInputFileBuilder) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) MapSettings(org.sonar.api.config.internal.MapSettings) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) DefaultInputFile(org.sonar.api.batch.fs.internal.DefaultInputFile) File(java.io.File) Test(org.junit.Test)

Example 8 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonar-go by SonarSource.

the class GoCoverageReportTest method get_report_paths.

@Test
public void get_report_paths() {
    SensorContextTester context = SensorContextTester.create(COVERAGE_DIR);
    context.setSettings(new MapSettings());
    Path coverageFile1 = COVERAGE_DIR.resolve("coverage.linux.relative.out").toAbsolutePath();
    context.settings().setProperty("sonar.go.coverage.reportPaths", coverageFile1 + ",coverage.linux.absolute.out");
    List<Path> reportPaths = GoCoverageReport.getReportPaths(context);
    assertThat(reportPaths).containsExactlyInAnyOrder(coverageFile1, Paths.get("src", "test", "resources", "coverage", "coverage.linux.absolute.out"));
}
Also used : Path(java.nio.file.Path) SensorContextTester(org.sonar.api.batch.sensor.internal.SensorContextTester) MapSettings(org.sonar.api.config.internal.MapSettings) Test(org.junit.jupiter.api.Test)

Example 9 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonar-go by SonarSource.

the class GoLanguageTest method should_have_correct_file_extensions.

@Test
void should_have_correct_file_extensions() {
    MapSettings mapSettings = new MapSettings();
    GoLanguage typeScriptLanguage = new GoLanguage(mapSettings.asConfig());
    assertThat(typeScriptLanguage.getFileSuffixes()).containsExactly(".go");
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) Test(org.junit.jupiter.api.Test)

Example 10 with MapSettings

use of org.sonar.api.config.internal.MapSettings in project sonar-go by SonarSource.

the class GoLanguageTest method can_override_file_extensions.

@Test
void can_override_file_extensions() {
    MapSettings mapSettings = new MapSettings();
    mapSettings.setProperty("sonar.go.file.suffixes", ".go1,.go2");
    GoLanguage typeScriptLanguage = new GoLanguage(mapSettings.asConfig());
    assertThat(typeScriptLanguage.getFileSuffixes()).containsExactly(".go1", ".go2");
}
Also used : MapSettings(org.sonar.api.config.internal.MapSettings) Test(org.junit.jupiter.api.Test)

Aggregations

MapSettings (org.sonar.api.config.internal.MapSettings)24 Test (org.junit.Test)11 DefaultFileSystem (org.sonar.api.batch.fs.internal.DefaultFileSystem)11 File (java.io.File)9 InputFile (org.sonar.api.batch.fs.InputFile)5 TestInputFileBuilder (org.sonar.api.batch.fs.internal.TestInputFileBuilder)5 SensorContextTester (org.sonar.api.batch.sensor.internal.SensorContextTester)5 Before (org.junit.Before)4 Test (org.junit.jupiter.api.Test)4 DefaultInputFile (org.sonar.api.batch.fs.internal.DefaultInputFile)4 PathResolver (org.sonar.api.scan.filesystem.PathResolver)4 SonarComponents (org.sonar.java.SonarComponents)4 JavaClasspath (org.sonar.java.JavaClasspath)3 Path (java.nio.file.Path)2 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)2 SonarRuntime (org.sonar.api.SonarRuntime)2 NoSonarFilter (org.sonar.api.issue.NoSonarFilter)2 FileLinesContext (org.sonar.api.measures.FileLinesContext)2 FileLinesContextFactory (org.sonar.api.measures.FileLinesContextFactory)2 DefaultJavaResourceLocator (org.sonar.java.DefaultJavaResourceLocator)2