diff options
| author | Elena Vilchik | 2018-06-22 09:55:16 +0200 | 
|---|---|---|
| committer | GitHub | 2018-06-22 09:55:16 +0200 | 
| commit | 3922c3cd97c13f08bd2ec833e84ac167432d7de8 (patch) | |
| tree | 6727599afcb79c2c3a554471280c96a765cd3fc1 /sonar-css-plugin/src/test/java | |
| parent | bd7c66b25b4f6779e622df81908ae5c11be5798b (diff) | |
| download | sonar-css-3922c3cd97c13f08bd2ec833e84ac167432d7de8.tar.bz2 | |
Fix analysis of project with non-css files (#58)
Diffstat (limited to 'sonar-css-plugin/src/test/java')
| -rw-r--r-- | sonar-css-plugin/src/test/java/org/sonar/css/plugin/CssRuleSensorTest.java | 20 | ||||
| -rw-r--r-- | sonar-css-plugin/src/test/java/org/sonar/css/plugin/StylelintCommandProviderTest.java | 9 | 
2 files changed, 25 insertions, 4 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 d176688..f86e24f 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 @@ -28,11 +28,13 @@ import java.nio.file.Path;  import java.nio.file.Paths;  import org.junit.Rule;  import org.junit.Test; +import org.junit.rules.ExpectedException;  import org.junit.rules.TemporaryFolder;  import org.sonar.api.batch.fs.InputFile.Type;  import org.sonar.api.batch.fs.internal.DefaultInputFile;  import org.sonar.api.batch.fs.internal.TestInputFileBuilder;  import org.sonar.api.batch.rule.CheckFactory; +import org.sonar.api.batch.sensor.SensorContext;  import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor;  import org.sonar.api.batch.sensor.internal.SensorContextTester;  import org.sonar.css.plugin.bundle.BundleHandler; @@ -42,6 +44,9 @@ import static org.assertj.core.api.Assertions.assertThat;  public class CssRuleSensorTest { +  @Rule +  public ExpectedException thrown= ExpectedException.none(); +    private static CheckFactory checkFactory = new CheckFactory(new TestActiveRules("S4647"));    private File BASE_DIR = new File("src/test/resources").getAbsoluteFile(); @@ -73,6 +78,19 @@ public class CssRuleSensorTest {      assertThat(Files.readAllLines(configPath)).containsOnly("{\"rules\":{\"color-no-invalid-hex\":true}}");    } +  @Test +  public void test_error() throws IOException { +    thrown.expect(IllegalStateException.class); +    thrown.expectMessage("Failed to parse json result of external process execution"); + +    SensorContextTester context = SensorContextTester.create(BASE_DIR); +    context.fileSystem().setWorkDir(tmpDir.getRoot().toPath()); +    DefaultInputFile inputFile = createInputFile(context, "some css content\n on 2 lines", "dir/file.css"); +    TestLinterCommandProvider rulesExecution = TestLinterCommandProvider.nodeScript("/executables/mockError.js", inputFile.absolutePath()); +    CssRuleSensor sensor = new CssRuleSensor(new TestBundleHandler(), checkFactory, rulesExecution); +    sensor.execute(context); +  } +    private static DefaultInputFile createInputFile(SensorContextTester sensorContext, String content, String relativePath) {      DefaultInputFile inputFile = new TestInputFileBuilder("moduleKey", relativePath)        .setModuleBaseDir(sensorContext.fileSystem().baseDirPath()) @@ -117,7 +135,7 @@ public class CssRuleSensorTest {      }      @Override -    public String[] commandParts(File deployDestination, File projectBaseDir) { +    public String[] commandParts(File deployDestination, SensorContext context) {        return elements;      } diff --git a/sonar-css-plugin/src/test/java/org/sonar/css/plugin/StylelintCommandProviderTest.java b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/StylelintCommandProviderTest.java index d201258..7244cce 100644 --- a/sonar-css-plugin/src/test/java/org/sonar/css/plugin/StylelintCommandProviderTest.java +++ b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/StylelintCommandProviderTest.java @@ -21,6 +21,7 @@ package org.sonar.css.plugin;  import java.io.File;  import org.junit.Test; +import org.sonar.api.batch.sensor.internal.SensorContextTester;  import static org.assertj.core.api.Assertions.assertThat; @@ -30,11 +31,13 @@ public class StylelintCommandProviderTest {    public void test() throws Exception {      StylelintCommandProvider stylelintCommandProvider = new StylelintCommandProvider();      File deployDestination = new File("deploy_destination"); -    File baseDir = new File("base_dir"); -    assertThat(stylelintCommandProvider.commandParts(deployDestination, baseDir)).containsExactly( +    File baseDir = new File("src/test/resources").getAbsoluteFile(); +    SensorContextTester context = SensorContextTester.create(baseDir); +    context.settings().setProperty(CssPlugin.FILE_SUFFIXES_KEY, ".foo,.bar"); +    assertThat(stylelintCommandProvider.commandParts(deployDestination, context)).containsExactly(        "node",        new File(deployDestination, "css-bundle/node_modules/stylelint/bin/stylelint").getAbsolutePath(), -      baseDir.getAbsolutePath(), +      baseDir.getAbsolutePath() + File.separator + "**" + File.separator + "*{.foo,.bar}",        "--config",        new File(deployDestination, "css-bundle/stylelintconfig.json").getAbsolutePath(),        "-f",  | 
