Search in sources :

Example 1 with SkipReason

use of org.sonarsource.sonarlint.core.plugin.commons.SkipReason in project sonarlint-core by SonarSource.

the class StandaloneNodeJsTests method unsatisfied_node_version.

@Test
void unsatisfied_node_version() throws Exception {
    List<String> logs = new ArrayList<>();
    var configBuilder = StandaloneGlobalConfiguration.builder().addPlugin(PluginLocator.getJavaScriptPluginPath()).addEnabledLanguages(Language.JS, Language.TS).setSonarLintUserHome(sonarlintUserHome).setNodeJs(Paths.get("node"), Version.create("1.0")).setModulesProvider(() -> singletonList(new ClientModuleInfo("key", mock(ClientModuleFileSystem.class)))).setLogOutput((msg, level) -> logs.add(msg));
    sonarlint = new StandaloneSonarLintEngineImpl(configBuilder.build());
    assertThat(logs).contains("Plugin 'JavaScript/TypeScript Code Quality and Security' requires Node.js 8.0.0 while current is 1.0. Skip loading it.");
    var skipReason = sonarlint.getPluginDetails().stream().filter(p -> p.key().equals("javascript")).findFirst().get().skipReason();
    assertThat(skipReason).isNotEmpty();
    assertThat(skipReason.get()).isInstanceOf(SkipReason.UnsatisfiedRuntimeRequirement.class);
    var unsatisfiedNode = (SkipReason.UnsatisfiedRuntimeRequirement) skipReason.get();
    assertThat(unsatisfiedNode.getRuntime()).isEqualTo(SkipReason.UnsatisfiedRuntimeRequirement.RuntimeRequirement.NODEJS);
    assertThat(unsatisfiedNode.getCurrentVersion()).isEqualTo("1.0");
    assertThat(unsatisfiedNode.getMinVersion()).isEqualTo("8.0.0");
    assertThat(sonarlint.getRuleDetails(JAVASCRIPT_S1481)).isEmpty();
    final var issues = analyze();
    assertThat(issues).isEmpty();
}
Also used : Assertions.fail(org.junit.jupiter.api.Assertions.fail) BeforeEach(org.junit.jupiter.api.BeforeEach) UnsatisfiedRuntimeRequirement(org.sonarsource.sonarlint.core.plugin.commons.SkipReason.UnsatisfiedRuntimeRequirement) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Language(org.sonarsource.sonarlint.core.commons.Language) StandaloneRuleDetails(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneRuleDetails) SkipReason(org.sonarsource.sonarlint.core.plugin.commons.SkipReason) Version(org.sonarsource.sonarlint.core.commons.Version) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) ArrayList(java.util.ArrayList) Collections.singletonList(java.util.Collections.singletonList) Charset(java.nio.charset.Charset) StandaloneGlobalConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneGlobalConfiguration) OnDiskTestClientInputFile(testutils.OnDiskTestClientInputFile) Path(java.nio.file.Path) Nullable(javax.annotation.Nullable) ClientModuleFileSystem(org.sonarsource.sonarlint.core.analysis.api.ClientModuleFileSystem) ClientModuleInfo(org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo) SystemUtils(org.apache.commons.lang3.SystemUtils) ClientInputFile(org.sonarsource.sonarlint.core.analysis.api.ClientInputFile) IOException(java.io.IOException) FileUtils(org.apache.commons.io.FileUtils) File(java.io.File) StandardCharsets(java.nio.charset.StandardCharsets) StandaloneAnalysisConfiguration(org.sonarsource.sonarlint.core.client.api.standalone.StandaloneAnalysisConfiguration) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) Paths(java.nio.file.Paths) TempDir(org.junit.jupiter.api.io.TempDir) Issue(org.sonarsource.sonarlint.core.client.api.common.analysis.Issue) Optional(java.util.Optional) PluginLocator(org.sonarsource.sonarlint.core.util.PluginLocator) Mockito.mock(org.mockito.Mockito.mock) UnsatisfiedRuntimeRequirement(org.sonarsource.sonarlint.core.plugin.commons.SkipReason.UnsatisfiedRuntimeRequirement) ArrayList(java.util.ArrayList) ClientModuleInfo(org.sonarsource.sonarlint.core.analysis.api.ClientModuleInfo) SkipReason(org.sonarsource.sonarlint.core.plugin.commons.SkipReason) StandaloneSonarLintEngineImpl(org.sonarsource.sonarlint.core.StandaloneSonarLintEngineImpl) Test(org.junit.jupiter.api.Test)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 Charset (java.nio.charset.Charset)1 StandardCharsets (java.nio.charset.StandardCharsets)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Collections.singletonList (java.util.Collections.singletonList)1 List (java.util.List)1 Optional (java.util.Optional)1 Nullable (javax.annotation.Nullable)1 FileUtils (org.apache.commons.io.FileUtils)1 SystemUtils (org.apache.commons.lang3.SystemUtils)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 AfterEach (org.junit.jupiter.api.AfterEach)1 Assertions.fail (org.junit.jupiter.api.Assertions.fail)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 TempDir (org.junit.jupiter.api.io.TempDir)1 Mockito.mock (org.mockito.Mockito.mock)1