use of testutils.OnDiskTestClientInputFile in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTests method declare_module_should_create_a_module_container_with_loaded_extensions.
@Test
void declare_module_should_create_a_module_container_with_loaded_extensions() throws Exception {
sonarlint.declareModule(new ClientModuleInfo("key", aClientFileSystemWith(new OnDiskTestClientInputFile(Paths.get("main.py"), "main.py", false, StandardCharsets.UTF_8, null)))).get();
ComponentContainer moduleContainer = sonarlint.getAnalysisEngine().getModuleRegistry().getContainerFor("key");
assertThat(moduleContainer).isNotNull();
assertThat(moduleContainer.getComponentsByType(SonarLintModuleFileSystem.class)).isNotEmpty();
}
use of testutils.OnDiskTestClientInputFile in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTests method lazy_init_file_metadata.
@Test
void lazy_init_file_metadata() throws Exception {
final var inputFile1 = prepareInputFile(A_JAVA_FILE_PATH, "public class Foo {\n" + " public void foo() {\n" + " int x;\n" + " System.out.println(\"Foo\");\n" + " System.out.println(\"Foo\"); //NOSONAR\n" + " }\n" + "}", false);
var unexistingPath = new File(baseDir, "missing.bin");
assertThat(unexistingPath).doesNotExist();
ClientInputFile inputFile2 = new OnDiskTestClientInputFile(unexistingPath.toPath(), "missing.bin", false, StandardCharsets.UTF_8, null);
final List<Issue> issues = new ArrayList<>();
final List<String> logs = new CopyOnWriteArrayList<>();
var analysisResults = sonarlint.analyze(StandaloneAnalysisConfiguration.builder().setBaseDir(baseDir.toPath()).addInputFiles(inputFile1, inputFile2).build(), issues::add, (m, l) -> logs.add(m), null);
assertThat(analysisResults.failedAnalysisFiles()).isEmpty();
assertThat(analysisResults.indexedFileCount()).isEqualTo(2);
assertThat(logs).contains("Initializing metadata of file " + inputFile1.uri()).doesNotContain("Initializing metadata of file " + inputFile2.uri());
}
use of testutils.OnDiskTestClientInputFile in project sonarlint-core by SonarSource.
the class StandaloneIssueMediumTests method useRelativePathToEvaluatePathPatterns.
// SLCORE-162
@Test
void useRelativePathToEvaluatePathPatterns() throws Exception {
// Temporary file doesn't have the correct file suffix
final var file = new File(baseDir, "foo.tmp");
FileUtils.write(file, "def my_function(name):\n" + " print \"Hello\"\n" + " print \"world!\" # NOSONAR\n" + "\n", StandardCharsets.UTF_8);
ClientInputFile inputFile = new OnDiskTestClientInputFile(file.toPath(), "foo.py", false, StandardCharsets.UTF_8, null);
final List<Issue> issues = new ArrayList<>();
sonarlint.analyze(StandaloneAnalysisConfiguration.builder().setBaseDir(baseDir.toPath()).addInputFile(inputFile).build(), issues::add, null, null);
assertThat(issues).extracting(Issue::getRuleKey, Issue::getStartLine, i -> i.getInputFile().relativePath()).containsOnly(tuple("python:PrintStatementUsage", 2, "foo.py"));
}
use of testutils.OnDiskTestClientInputFile in project sonarlint-core by SonarSource.
the class ConnectedIssueMediumTests method stop_module_should_stop_the_module_container.
@Test
void stop_module_should_stop_the_module_container() throws Exception {
sonarlint.declareModule(new ClientModuleInfo("key", aClientFileSystemWith(new OnDiskTestClientInputFile(Paths.get("main.py"), "main.py", false, StandardCharsets.UTF_8, null)))).get();
ComponentContainer moduleContainer = sonarlint.getAnalysisEngine().getModuleRegistry().getContainerFor("key");
sonarlint.stopModule("key").get();
assertThat(moduleContainer.getPicoContainer().getLifecycleState().isStarted()).isFalse();
}
use of testutils.OnDiskTestClientInputFile in project sonarlint-core by SonarSource.
the class ConnectedIssueMediumTests method declare_module_should_create_a_module_container_with_loaded_extensions.
@Test
void declare_module_should_create_a_module_container_with_loaded_extensions() throws Exception {
sonarlint.declareModule(new ClientModuleInfo("key", aClientFileSystemWith(new OnDiskTestClientInputFile(Paths.get("main.py"), "main.py", false, StandardCharsets.UTF_8, null)))).get();
ComponentContainer moduleContainer = sonarlint.getAnalysisEngine().getModuleRegistry().getContainerFor("key");
assertThat(moduleContainer).isNotNull();
assertThat(moduleContainer.getComponentsByType(SonarLintModuleFileSystem.class)).isNotEmpty();
}
Aggregations