Search in sources :

Example 11 with ClientModuleInfo

use of org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo in project sonarlint-core by SonarSource.

the class AnalysisEngineMediumTests method should_analyze_a_file_inside_a_module.

@Test
void should_analyze_a_file_inside_a_module(@TempDir Path baseDir) throws Exception {
    var content = "def foo():\n" + "  x = 9; # trailing comment\n";
    ClientInputFile inputFile = preparePythonInputFile(baseDir, content);
    AnalysisConfiguration analysisConfig = AnalysisConfiguration.builder().addInputFiles(inputFile).addActiveRules(trailingCommentRule()).setBaseDir(baseDir).build();
    List<Issue> issues = new ArrayList<>();
    analysisEngine.post(new RegisterModuleCommand(new ClientModuleInfo("moduleKey", aModuleFileSystem())), progressMonitor).get();
    analysisEngine.post(new AnalyzeCommand("moduleKey", analysisConfig, issues::add, null), progressMonitor).get();
    assertThat(issues).extracting("ruleKey", "message", "inputFile", "flows", "quickFixes", "textRange.startLine", "textRange.startLineOffset", "textRange.endLine", "textRange.endLineOffset").containsOnly(tuple("python:S139", "Move this trailing comment on the previous empty line.", inputFile, List.of(), List.of(), 2, 9, 2, 27));
}
Also used : Issue(org.sonarsource.sonarlint.core.analysis.api.Issue) AnalysisConfiguration(org.sonarsource.sonarlint.core.analysis.api.AnalysisConfiguration) ArrayList(java.util.ArrayList) ClientModuleInfo(org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo) OnDiskTestClientInputFile(testutils.OnDiskTestClientInputFile) ClientInputFile(org.sonarsource.sonarlint.core.analysis.api.ClientInputFile) RegisterModuleCommand(org.sonarsource.sonarlint.core.analysis.command.RegisterModuleCommand) AnalyzeCommand(org.sonarsource.sonarlint.core.analysis.command.AnalyzeCommand) Test(org.junit.jupiter.api.Test)

Example 12 with ClientModuleInfo

use of org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo in project sonarlint-core by SonarSource.

the class AnalysisEngineMediumTests method should_cancel_pending_commands_when_stopping.

@Test
void should_cancel_pending_commands_when_stopping() {
    var futureLongCommand = analysisEngine.post((moduleRegistry, progressMonitor) -> {
        while (!engineStopped) ;
        return null;
    }, progressMonitor);
    var futureRegister = analysisEngine.post(new RegisterModuleCommand(new ClientModuleInfo("moduleKey", aModuleFileSystem())), progressMonitor);
    // let the engine run the first command
    pause(500);
    analysisEngine.stop();
    engineStopped = true;
    await().until(futureLongCommand::isDone);
    assertThat(futureRegister).isCancelled();
}
Also used : ClientModuleInfo(org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo) RegisterModuleCommand(org.sonarsource.sonarlint.core.analysis.command.RegisterModuleCommand) Test(org.junit.jupiter.api.Test)

Aggregations

ClientModuleInfo (org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo)12 Test (org.junit.jupiter.api.Test)10 OnDiskTestClientInputFile (testutils.OnDiskTestClientInputFile)7 ComponentContainer (org.sonarsource.sonarlint.core.plugin.commons.pico.ComponentContainer)5 ArrayList (java.util.ArrayList)4 StandaloneSonarLintEngineImpl (org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl)4 ClientInputFile (org.sonarsource.sonarlint.core.analysis.api.ClientInputFile)4 File (java.io.File)3 IOException (java.io.IOException)3 StandardCharsets (java.nio.charset.StandardCharsets)3 List (java.util.List)3 FileUtils (org.apache.commons.io.FileUtils)3 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)3 BeforeEach (org.junit.jupiter.api.BeforeEach)3 TempDir (org.junit.jupiter.api.io.TempDir)3 Mockito.mock (org.mockito.Mockito.mock)3 ClientModuleFileSystem (org.sonarsource.sonarlint.core.analysis.api.ClientModuleFileSystem)3 Language (org.sonarsource.sonarlint.core.commons.Language)3 Path (java.nio.file.Path)2 Paths (java.nio.file.Paths)2