From 6472431ad488158bfcf863a7b4a5655e1ecc55e8 Mon Sep 17 00:00:00 2001 From: Elena Vilchik Date: Thu, 21 Jun 2018 11:13:19 +0200 Subject: Generate rules configuration file (#56) --- .../org/sonar/css/plugin/CssRuleSensorTest.java | 14 ++++++- .../css/plugin/StylelintCommandProviderTest.java | 44 ++++++++++++++++++++++ .../sonar/css/plugin/StylelintExecutionTest.java | 44 ---------------------- 3 files changed, 57 insertions(+), 45 deletions(-) create mode 100644 sonar-css-plugin/src/test/java/org/sonar/css/plugin/StylelintCommandProviderTest.java delete mode 100644 sonar-css-plugin/src/test/java/org/sonar/css/plugin/StylelintExecutionTest.java (limited to 'sonar-css-plugin/src/test/java/org') 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 a4d5921..5c9e5ae 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 @@ -23,6 +23,9 @@ import java.io.File; import java.io.IOException; import java.net.URISyntaxException; import java.nio.charset.StandardCharsets; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; import org.junit.Rule; import org.junit.Test; import org.junit.rules.TemporaryFolder; @@ -32,6 +35,7 @@ import org.sonar.api.batch.fs.internal.TestInputFileBuilder; import org.sonar.api.batch.rule.CheckFactory; import org.sonar.api.batch.sensor.internal.DefaultSensorDescriptor; import org.sonar.api.batch.sensor.internal.SensorContextTester; +import org.sonar.css.plugin.bundle.BundleHandler; import org.sonar.css.plugin.bundle.CssBundleHandler; import static org.assertj.core.api.Assertions.assertThat; @@ -46,7 +50,7 @@ public class CssRuleSensorTest { @Test public void test_descriptor() throws Exception { - CssRuleSensor sensor = new CssRuleSensor(new CssBundleHandler(), checkFactory, new StylelintExecution()); + CssRuleSensor sensor = new CssRuleSensor(new CssBundleHandler(), checkFactory, new StylelintCommandProvider()); DefaultSensorDescriptor sensorDescriptor = new DefaultSensorDescriptor(); sensor.describe(sensorDescriptor); assertThat(sensorDescriptor.name()).isEqualTo("SonarCSS Rules"); @@ -64,6 +68,9 @@ public class CssRuleSensorTest { sensor.execute(context); assertThat(context.allIssues()).hasSize(1); + + Path configPath = Paths.get(context.fileSystem().workDir().getAbsolutePath(), "testconfig.json"); + assertThat(Files.readAllLines(configPath)).containsOnly("{\"rules\":{\"color-no-invalid-hex\":true}}"); } private static DefaultInputFile createInputFile(SensorContextTester sensorContext, String content, String relativePath) { @@ -113,6 +120,11 @@ public class CssRuleSensorTest { public String[] commandParts(File deployDestination, File projectBaseDir) { return elements; } + + @Override + public String configPath(File deployDestination) { + return new File(deployDestination, "testconfig.json").getAbsolutePath(); + } } private static class TestBundleHandler implements BundleHandler { 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 new file mode 100644 index 0000000..d201258 --- /dev/null +++ b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/StylelintCommandProviderTest.java @@ -0,0 +1,44 @@ +/* + * SonarCSS + * Copyright (C) 2018-2018 SonarSource SA + * mailto:info AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ +package org.sonar.css.plugin; + +import java.io.File; +import org.junit.Test; + +import static org.assertj.core.api.Assertions.assertThat; + +public class StylelintCommandProviderTest { + + @Test + 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( + "node", + new File(deployDestination, "css-bundle/node_modules/stylelint/bin/stylelint").getAbsolutePath(), + baseDir.getAbsolutePath(), + "--config", + new File(deployDestination, "css-bundle/stylelintconfig.json").getAbsolutePath(), + "-f", + "json" + ); + } +} diff --git a/sonar-css-plugin/src/test/java/org/sonar/css/plugin/StylelintExecutionTest.java b/sonar-css-plugin/src/test/java/org/sonar/css/plugin/StylelintExecutionTest.java deleted file mode 100644 index 4ca78db..0000000 --- a/sonar-css-plugin/src/test/java/org/sonar/css/plugin/StylelintExecutionTest.java +++ /dev/null @@ -1,44 +0,0 @@ -/* - * SonarCSS - * Copyright (C) 2018-2018 SonarSource SA - * mailto:info AT sonarsource DOT com - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ -package org.sonar.css.plugin; - -import java.io.File; -import org.junit.Test; - -import static org.assertj.core.api.Assertions.assertThat; - -public class StylelintExecutionTest { - - @Test - public void test() throws Exception { - StylelintExecution stylelintExecution = new StylelintExecution(); - File deployDestination = new File("deploy_destination"); - File baseDir = new File("base_dir"); - assertThat(stylelintExecution.commandParts(deployDestination, baseDir)).containsExactly( - "node", - new File(deployDestination, "css-bundle/node_modules/stylelint/bin/stylelint").getAbsolutePath(), - baseDir.getAbsolutePath(), - "--config", - new File(deployDestination, "css-bundle/stylelintconfig.json").getAbsolutePath(), - "-f", - "json" - ); - } -} -- cgit v1.2.3