diff options
Diffstat (limited to 'sonar-css-plugin/src/test')
3 files changed, 34 insertions, 3 deletions
| diff --git a/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssRuleSensorTest.java b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssRuleSensorTest.java index f44781b..782b10f 100644 --- a/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssRuleSensorTest.java +++ b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssRuleSensorTest.java @@ -26,6 +26,8 @@ import java.nio.charset.StandardCharsets;  import java.nio.file.Files;  import java.nio.file.Path;  import java.nio.file.Paths; +import java.util.concurrent.TimeUnit; +import org.awaitility.Awaitility;  import org.junit.Before;  import org.junit.Rule;  import org.junit.Test; @@ -46,6 +48,7 @@ import org.sonar.css.plugin.bundle.BundleHandler;  import org.sonar.css.plugin.bundle.CssBundleHandler;  import static org.assertj.core.api.Assertions.assertThat; +import static org.awaitility.Awaitility.await;  public class CssRuleSensorTest { @@ -68,6 +71,7 @@ public class CssRuleSensorTest {    @Before    public void setUp() {      context.fileSystem().setWorkDir(tmpDir.getRoot().toPath()); +    Awaitility.setDefaultTimeout(5, TimeUnit.MINUTES);    }    @Test @@ -128,12 +132,11 @@ public class CssRuleSensorTest {    @Test    public void test_error() { -    thrown.expect(IllegalStateException.class); -    thrown.expectMessage("Failed to parse json result of external process execution"); -      TestLinterCommandProvider commandProvider = new TestLinterCommandProvider().nodeScript("/executables/mockError.js", inputFile.absolutePath());      CssRuleSensor sensor = new CssRuleSensor(new TestBundleHandler(), checkFactory, commandProvider);      sensor.execute(context); + +    assertThat(logTester.logs(LoggerLevel.ERROR)).anyMatch(s -> s.startsWith("Failed to run external linting process"));    }    @Test @@ -146,6 +149,26 @@ public class CssRuleSensorTest {    }    @Test +  public void test_stylelint_throws() { +    TestLinterCommandProvider commandProvider = new TestLinterCommandProvider().nodeScript("/executables/mockThrow.js", inputFile.absolutePath()); +    CssRuleSensor sensor = new CssRuleSensor(new TestBundleHandler(), checkFactory, commandProvider); +    sensor.execute(context); + +    await().until(() -> logTester.logs(LoggerLevel.ERROR) +      .contains("throw new Error('houps!');")); +  } + +  @Test +  public void test_stylelint_exitvalue() { +    TestLinterCommandProvider commandProvider = new TestLinterCommandProvider().nodeScript("/executables/mockExit.js", "1"); +    CssRuleSensor sensor = new CssRuleSensor(new TestBundleHandler(), checkFactory, commandProvider); +    sensor.execute(context); + +    await().until(() -> logTester.logs(LoggerLevel.ERROR) +      .contains("Analysis didn't terminate normally, please verify ERROR and WARN logs above. Exit code 1")); +  } + +  @Test    public void test_syntax_error() {      SensorContextTester context = SensorContextTester.create(BASE_DIR);      context.fileSystem().setWorkDir(tmpDir.getRoot().toPath()); diff --git a/sonar-css-plugin/src/test/resources/executables/mockExit.js b/sonar-css-plugin/src/test/resources/executables/mockExit.js new file mode 100644 index 0000000..b18a959 --- /dev/null +++ b/sonar-css-plugin/src/test/resources/executables/mockExit.js @@ -0,0 +1,5 @@ +#!/usr/bin/env node + +console.log("[]"); + +process.exit(process.argv[2]); diff --git a/sonar-css-plugin/src/test/resources/executables/mockThrow.js b/sonar-css-plugin/src/test/resources/executables/mockThrow.js new file mode 100644 index 0000000..ca88c27 --- /dev/null +++ b/sonar-css-plugin/src/test/resources/executables/mockThrow.js @@ -0,0 +1,3 @@ +#!/usr/bin/env node + +throw new Error('houps!'); | 
