use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class SurefireUtilsTest method should_get_reports_path_from_deprecated_property.
@Test
public void should_get_reports_path_from_deprecated_property() {
MapSettings settings = new MapSettings();
settings.setProperty("sonar.junit.reportsPath", "target/surefire");
DefaultFileSystem fs = new DefaultFileSystem(new File("src/test/resources/org/sonar/plugins/surefire/api/SurefireUtilsTest/shouldGetReportsPathFromDeprecatedProperty"));
PathResolver pathResolver = new PathResolver();
assertThat(logTester.logs(LoggerLevel.INFO)).isEmpty();
List<File> directories = SurefireUtils.getReportsDirectories(settings.asConfig(), fs, pathResolver);
assertThat(directories).hasSize(1);
File directory = directories.get(0);
assertThat(directory.exists()).isTrue();
assertThat(directory.isDirectory()).isTrue();
assertThat(logTester.logs(LoggerLevel.INFO)).contains("Property 'sonar.junit.reportsPath' is deprecated. Use property 'sonar.junit.reportPaths' instead.");
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-java by SonarSource.
the class RulesSanityTest method sonarComponents.
private static SonarComponents sonarComponents(File moduleBaseDir, List<InputFile> inputFiles) {
SensorContextTester context = SensorContextTester.create(moduleBaseDir).setRuntime(SonarRuntimeImpl.forSonarLint(Version.create(6, 7)));
context.setSettings(new MapSettings().setProperty(SonarComponents.FAIL_ON_EXCEPTION_KEY, true));
DefaultFileSystem fileSystem = context.fileSystem();
SonarComponents sonarComponents = new SonarComponents(null, fileSystem, null, null, null) {
@Override
public boolean reportAnalysisError(RecognitionException re, InputFile inputFile) {
return false;
}
};
sonarComponents.setSensorContext(context);
inputFiles.forEach(inputFile -> fileSystem.add(inputFile));
return sonarComponents;
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-go by SonarSource.
the class GoTestSensorTest method relative_package_path_in_report.
@Test
void relative_package_path_in_report() throws IOException {
GoTestSensor goTestSensor = new GoTestSensor();
goTestSensor.goPathContext = new GoPathContext(File.separatorChar, File.pathSeparator, goPath.toString());
TestInfo testInfo = new TestInfo("pass", packagePath.toString(), "TestFoo", 42.);
Path baseDir = goPath.resolve("src").resolve(packagePath);
SensorContextTester contextTester = SensorContextTester.create(baseDir);
DefaultFileSystem fs = contextTester.fileSystem();
DefaultInputFile testFile = getTestInputFile(fs, "func TestFoo(", "foo_test.go");
InputFile foundTestFile = goTestSensor.findTestFile(fs, testInfo);
assertThat(foundTestFile).isEqualTo(testFile);
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-go by SonarSource.
the class GoTestSensorTest method import_report.
@Test
void import_report() {
GoTestSensor goTestSensor = new GoTestSensor();
goTestSensor.goPathContext = new GoPathContext(File.separatorChar, File.pathSeparator, goPath.toString());
Path baseDir = goPath.resolve("src").resolve(packagePath);
SensorContextTester context = SensorContextTester.create(baseDir);
DefaultFileSystem fs = context.fileSystem();
DefaultInputFile fooTestFile = getTestInputFile(fs, "something \nfunc TestFoo1( \nfunc TestFoo2( ", "foo_test.go");
DefaultInputFile barTestFile = getTestInputFile(fs, "func TestBar(", "bar_test.go");
MapSettings settings = new MapSettings();
String absoluteReportPath = baseDir.resolve("report1.out").toString();
settings.setProperty(GoTestSensor.REPORT_PATH_KEY, "report.out,invilid/report/path," + absoluteReportPath);
context.setSettings(settings);
goTestSensor.execute(context);
// one test comes from report1.out
assertThat(context.measure(fooTestFile.key(), CoreMetrics.TESTS).value()).isEqualTo(3);
assertThat(context.measure(fooTestFile.key(), CoreMetrics.SKIPPED_TESTS).value()).isEqualTo(0);
assertThat(context.measure(fooTestFile.key(), CoreMetrics.TEST_FAILURES).value()).isEqualTo(1);
assertThat(context.measure(fooTestFile.key(), CoreMetrics.TEST_ERRORS)).isNull();
assertThat(context.measure(fooTestFile.key(), CoreMetrics.TEST_EXECUTION_TIME).value()).isEqualTo(4);
assertThat(context.measure(barTestFile.key(), CoreMetrics.TESTS).value()).isEqualTo(1);
assertThat(context.measure(barTestFile.key(), CoreMetrics.SKIPPED_TESTS).value()).isEqualTo(1);
assertThat(context.measure(barTestFile.key(), CoreMetrics.TEST_FAILURES).value()).isEqualTo(0);
assertThat(context.measure(barTestFile.key(), CoreMetrics.TEST_ERRORS)).isNull();
assertThat(context.measure(barTestFile.key(), CoreMetrics.TEST_EXECUTION_TIME).value()).isEqualTo(7);
assertThat(String.join("\n", logTester.logs(LoggerLevel.ERROR))).contains("Test report can't be loaded, file not found");
}
use of org.sonar.api.batch.fs.internal.DefaultFileSystem in project sonar-go by SonarSource.
the class GoTestSensorTest method subtests.
@Test
void subtests() throws Exception {
GoTestSensor goTestSensor = new GoTestSensor();
goTestSensor.goPathContext = new GoPathContext(File.separatorChar, File.pathSeparator, goPath.toString());
Path baseDir = goPath.resolve("src").resolve(packagePath);
SensorContextTester context = SensorContextTester.create(baseDir);
DefaultFileSystem fs = context.fileSystem();
DefaultInputFile mulTestFile = getTestInputFile(fs, new String(Files.readAllBytes(baseDir.resolve("mul_test.go"))), "mul_test.go");
MapSettings settings = new MapSettings();
String absoluteReportPath = baseDir.resolve("subtest_report.json").toString();
settings.setProperty(GoTestSensor.REPORT_PATH_KEY, absoluteReportPath);
context.setSettings(settings);
goTestSensor.execute(context);
assertThat(context.measure(mulTestFile.key(), CoreMetrics.TESTS).value()).isEqualTo(4);
}
Aggregations