diff options
| author | Elena Vilchik | 2018-06-26 15:11:24 +0200 | 
|---|---|---|
| committer | GitHub | 2018-06-26 15:11:24 +0200 | 
| commit | 4fc865cac084522cd37000a5abbf95acf00f7977 (patch) | |
| tree | b62a11ff188169a0b4fd06e1b486dd4f82692452 /sonar-css-plugin/src/test | |
| parent | a7cbea9bfccfaaeca25498d4cde75dff7ddb7b76 (diff) | |
| download | sonar-css-4fc865cac084522cd37000a5abbf95acf00f7977.tar.bz2 | |
Not fail analysis when syntax error (#80)
Diffstat (limited to 'sonar-css-plugin/src/test')
3 files changed, 62 insertions, 0 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 0b4acd2..dfe7ff2 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 @@ -145,6 +145,30 @@ public class CssRuleSensorTest {      assertThat(logTester.logs(LoggerLevel.WARN)).contains("No rules are activated in CSS Quality Profile");    } +  @Test +  public void test_syntax_error() throws IOException { +    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 = new TestLinterCommandProvider().nodeScript("/executables/mockSyntaxError.js", inputFile.absolutePath()); +    CssRuleSensor sensor = new CssRuleSensor(new TestBundleHandler(), checkFactory, rulesExecution); +    sensor.execute(context); + +    assertThat(logTester.logs(LoggerLevel.ERROR)).contains("Failed to parse " + inputFile.uri()); +  } + +  @Test +  public void test_unknown_rule() throws IOException { +    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 = new TestLinterCommandProvider().nodeScript("/executables/mockUnknownRule.js", inputFile.absolutePath()); +    CssRuleSensor sensor = new CssRuleSensor(new TestBundleHandler(), checkFactory, rulesExecution); +    sensor.execute(context); + +    assertThat(logTester.logs(LoggerLevel.ERROR)).contains("Unknown stylelint rule or rule not enabled: 'unknown-rule-key'"); +  } +    private static DefaultInputFile createInputFile(SensorContextTester sensorContext, String content, String relativePath) {      DefaultInputFile inputFile = new TestInputFileBuilder("moduleKey", relativePath)        .setModuleBaseDir(sensorContext.fileSystem().baseDirPath()) diff --git a/sonar-css-plugin/src/test/resources/executables/mockSyntaxError.js b/sonar-css-plugin/src/test/resources/executables/mockSyntaxError.js new file mode 100644 index 0000000..cd32af2 --- /dev/null +++ b/sonar-css-plugin/src/test/resources/executables/mockSyntaxError.js @@ -0,0 +1,19 @@ +#!/usr/bin/env node +var testFile = process.argv[2]; + +var result = [ +  { +    source: testFile, + +    warnings: [ +      { +        text: "Missed semicolon (CssSyntaxError)", +        line: 2, +        rule: "CssSyntaxError" +      } +    ] +  } +]; + +var json = JSON.stringify(result); +console.log(json); diff --git a/sonar-css-plugin/src/test/resources/executables/mockUnknownRule.js b/sonar-css-plugin/src/test/resources/executables/mockUnknownRule.js new file mode 100644 index 0000000..844b38b --- /dev/null +++ b/sonar-css-plugin/src/test/resources/executables/mockUnknownRule.js @@ -0,0 +1,19 @@ +#!/usr/bin/env node +var testFile = process.argv[2]; + +var result = [ +  { +    source: testFile, + +    warnings: [ +      { +        text: "some message", +        line: 2, +        rule: "unknown-rule-key" +      } +    ] +  } +]; + +var json = JSON.stringify(result); +console.log(json); | 
