]> source.dussan.org Git - vaadin-framework.git/commitdiff
Add sub directory support to sass test scanner (#12790)
authorArtur Signell <artur@vaadin.com>
Tue, 15 Oct 2013 18:49:25 +0000 (21:49 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 16 Oct 2013 09:30:21 +0000 (09:30 +0000)
Exclude partial scss files (starting with _)
Add new lines to normalized css for easier comparison

Change-Id: I2bfb796b293cb0b578c3c5c56aacffe7c1514b02

14 files changed:
theme-compiler/tests/resources/automatic/scss/foo/_bar.scss [new file with mode: 0644]
theme-compiler/tests/resources/automatic/scss/foo/bar.scss [deleted file]
theme-compiler/tests/resources/automatic/scss/import-file-which-contains-comment-in-last-line.scss
theme-compiler/tests/resources/automatic/scss/nested-import.scss
theme-compiler/tests/resources/automatic/scss/to-be-imported/_imported-file-contains-comments-in-last-line.scss [new file with mode: 0644]
theme-compiler/tests/resources/automatic/scss/to-be-imported/imported-file-contains-comments-in-last-line.scss [deleted file]
theme-compiler/tests/resources/automatic/scss/url-path.scss
theme-compiler/tests/resources/automatic/scss/utf8-imported/_to-be-imported-scss-file-contains-utf8.scss [new file with mode: 0644]
theme-compiler/tests/resources/automatic/scss/utf8-imported/to-be-imported-scss-file-contains-utf8.scss [deleted file]
theme-compiler/tests/resources/automatic/scss/utf8.scss
theme-compiler/tests/src/com/vaadin/sass/testcases/scss/AbstractDirectoryScanningSassTests.java
theme-compiler/tests/src/com/vaadin/sass/testcases/scss/AutomaticSassTests.java
theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassLangTests.java
theme-compiler/tests/src/com/vaadin/sass/testcases/scss/SassLangTestsBroken.java

diff --git a/theme-compiler/tests/resources/automatic/scss/foo/_bar.scss b/theme-compiler/tests/resources/automatic/scss/foo/_bar.scss
new file mode 100644 (file)
index 0000000..326d342
--- /dev/null
@@ -0,0 +1,5 @@
+.bar {
+   background: url("lorem.png");
+   background: url('lorem.png');
+   background: url(lorem.png);
+}
\ No newline at end of file
diff --git a/theme-compiler/tests/resources/automatic/scss/foo/bar.scss b/theme-compiler/tests/resources/automatic/scss/foo/bar.scss
deleted file mode 100644 (file)
index 326d342..0000000
+++ /dev/null
@@ -1,5 +0,0 @@
-.bar {
-   background: url("lorem.png");
-   background: url('lorem.png');
-   background: url(lorem.png);
-}
\ No newline at end of file
index 41adc908ed1e61fff8e598677a31d1dc06b33d12..8292d4efe370c9cdc708f6a6943544a7ab42e3c5 100644 (file)
@@ -1,4 +1,4 @@
-@import "to-be-imported/imported-file-contains-comments-in-last-line.scss";
+@import "to-be-imported/_imported-file-contains-comments-in-last-line.scss";
 .foo{
   foo: $foo;
 }
\ No newline at end of file
index 605d64a13aae88595586559442c1ac3f72477305..df720a55840617176269fe89033a89a437c36501 100644 (file)
@@ -1,3 +1,3 @@
 .foo {
-    @import "foo/bar.scss";
+    @import "foo/_bar.scss";
 }
\ No newline at end of file
diff --git a/theme-compiler/tests/resources/automatic/scss/to-be-imported/_imported-file-contains-comments-in-last-line.scss b/theme-compiler/tests/resources/automatic/scss/to-be-imported/_imported-file-contains-comments-in-last-line.scss
new file mode 100644 (file)
index 0000000..16244f2
--- /dev/null
@@ -0,0 +1,2 @@
+$foo: bar;
+// This will cause an error
\ No newline at end of file
diff --git a/theme-compiler/tests/resources/automatic/scss/to-be-imported/imported-file-contains-comments-in-last-line.scss b/theme-compiler/tests/resources/automatic/scss/to-be-imported/imported-file-contains-comments-in-last-line.scss
deleted file mode 100644 (file)
index 16244f2..0000000
+++ /dev/null
@@ -1,2 +0,0 @@
-$foo: bar;
-// This will cause an error
\ No newline at end of file
index 0cc954bfb41589ae7cdfdf7dd5593870600f8059..6903d389b59c08259600a4351f907fb8617c1ead 100644 (file)
@@ -1 +1 @@
-@import "foo/bar.scss";
\ No newline at end of file
+@import "foo/_bar.scss";
\ No newline at end of file
diff --git a/theme-compiler/tests/resources/automatic/scss/utf8-imported/_to-be-imported-scss-file-contains-utf8.scss b/theme-compiler/tests/resources/automatic/scss/utf8-imported/_to-be-imported-scss-file-contains-utf8.scss
new file mode 100644 (file)
index 0000000..f8a08a4
--- /dev/null
@@ -0,0 +1,3 @@
+@charset "abc";
+.imported{content: '\1f4c5';}
+.imported_raw_utf{content: "♥";}
diff --git a/theme-compiler/tests/resources/automatic/scss/utf8-imported/to-be-imported-scss-file-contains-utf8.scss b/theme-compiler/tests/resources/automatic/scss/utf8-imported/to-be-imported-scss-file-contains-utf8.scss
deleted file mode 100644 (file)
index f8a08a4..0000000
+++ /dev/null
@@ -1,3 +0,0 @@
-@charset "abc";
-.imported{content: '\1f4c5';}
-.imported_raw_utf{content: "♥";}
index b56867407378752af3a51a1b59c0f99551bf24ec..251d6e6513b9ae944ebbb16ac86632028fbcdbd6 100644 (file)
@@ -1,4 +1,4 @@
 @charset "UTF-8";
-@import "utf8-imported/to-be-imported-scss-file-contains-utf8";
+@import "utf8-imported/_to-be-imported-scss-file-contains-utf8";
 .bar {content: "\1f4c5";}
 .raw_utf {content: "📈";}
\ No newline at end of file
index 40da6179f69cc646c70291a8ad9c5bbd4bc6009a..21edde0c17b69510b76736f8e4063bf67337bea6 100644 (file)
@@ -19,7 +19,6 @@ package com.vaadin.sass.testcases.scss;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileNotFoundException;
-import java.io.FilenameFilter;
 import java.io.IOException;
 import java.net.URISyntaxException;
 import java.net.URL;
@@ -36,28 +35,43 @@ import com.vaadin.sass.testcases.scss.SassTestRunner.FactoryTest;
 public abstract class AbstractDirectoryScanningSassTests {
 
     public static Collection<String> getScssResourceNames(URL directoryUrl)
-            throws URISyntaxException {
+            throws URISyntaxException, IOException {
         List<String> resources = new ArrayList<String>();
-        for (File scssFile : getScssFiles(directoryUrl)) {
-            resources.add(scssFile.getName());
+        for (String scssFile : getScssFiles(directoryUrl)) {
+            resources.add(scssFile);
         }
         return resources;
     }
 
-    private static File[] getScssFiles(URL directoryUrl)
-            throws URISyntaxException {
+    private static List<String> getScssFiles(URL directoryUrl)
+            throws URISyntaxException, IOException {
         URL sasslangUrl = directoryUrl;
         File sasslangDir = new File(sasslangUrl.toURI());
         File scssDir = new File(sasslangDir, "scss");
         Assert.assertTrue(scssDir.exists());
 
-        return scssDir.listFiles(new FilenameFilter() {
+        List<File> scssFiles = new ArrayList<File>();
+        addScssFilesRecursively(scssDir, scssFiles);
 
-            @Override
-            public boolean accept(File dir, String name) {
-                return name.endsWith(".scss");
+        List<String> scssRelativeNames = new ArrayList<String>();
+        for (File f : scssFiles) {
+            String relativeName = f.getCanonicalPath().substring(
+                    scssDir.getCanonicalPath().length() + 1);
+            scssRelativeNames.add(relativeName);
+        }
+        return scssRelativeNames;
+    }
+
+    private static void addScssFilesRecursively(File scssDir,
+            List<File> scssFiles) {
+        for (File f : scssDir.listFiles()) {
+            if (f.isDirectory()) {
+                addScssFilesRecursively(f, scssFiles);
+            } else if (f.getName().endsWith(".scss")
+                    && !f.getName().startsWith("_")) {
+                scssFiles.add(f);
             }
-        });
+        }
     }
 
     protected abstract URL getResourceURL(String path);
@@ -69,7 +83,7 @@ public abstract class AbstractDirectoryScanningSassTests {
         File cssFile = getCssFile(scssFile);
         referenceCss = IOUtils.toString(new FileInputStream(cssFile));
         ScssStylesheet scssStylesheet = ScssStylesheet.get(scssFile
-                .getAbsolutePath());
+                .getCanonicalPath());
         scssStylesheet.compile();
         String parsedCss = scssStylesheet.toString();
 
@@ -88,6 +102,9 @@ public abstract class AbstractDirectoryScanningSassTests {
         css = css.replaceAll("^[\n\r\t ]*", "");
         // remove trailing whitespace
         css = css.replaceAll("[\n\r\t ]*$", "");
+        css = css.replaceAll(";", ";\n");
+        css = css.replaceAll("\\{", "\\{\n");
+        css = css.replaceAll("}", "}\n");
         return css;
     }
 
@@ -103,7 +120,7 @@ public abstract class AbstractDirectoryScanningSassTests {
         return new File(res.toURI());
     }
 
-    private File getCssFile(File scssFile) {
-        return new File(scssFile.getAbsolutePath().replace("scss", "css"));
+    private File getCssFile(File scssFile) throws IOException {
+        return new File(scssFile.getCanonicalPath().replace("scss", "css"));
     }
 }
index 4134c564f982b2c84abcc081bf008f1cd71b8276..66e0bedac0ecedaf7341a6ebad3074919da7f534 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.vaadin.sass.testcases.scss;
 
+import java.io.IOException;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Collection;
@@ -37,7 +38,7 @@ public class AutomaticSassTests extends AbstractDirectoryScanningSassTests {
 
     @TestFactory
     public static Collection<String> getScssResourceNames()
-            throws URISyntaxException {
+            throws URISyntaxException, IOException {
         return getScssResourceNames(getResourceURLInternal(""));
     }
 
index 4b8aada5244b67da5f796036fe454aa639736fe9..a8c9e80a3aefb8d66deb66a2aa575fa6d7780c5c 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.vaadin.sass.testcases.scss;
 
+import java.io.IOException;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Collection;
@@ -42,7 +43,7 @@ public class SassLangTests extends AbstractDirectoryScanningSassTests {
 
     @TestFactory
     public static Collection<String> getScssResourceNames()
-            throws URISyntaxException {
+            throws URISyntaxException, IOException {
         return getScssResourceNames(getResourceURLInternal(""));
     }
 
index 6b812a6940456070ee11accd8a86c5c5738384f3..0656565c206481a50c81fcb0a7c63e4a557e4d10 100644 (file)
@@ -15,6 +15,7 @@
  */
 package com.vaadin.sass.testcases.scss;
 
+import java.io.IOException;
 import java.net.URISyntaxException;
 import java.net.URL;
 import java.util.Collection;
@@ -45,7 +46,7 @@ public class SassLangTestsBroken extends AbstractDirectoryScanningSassTests {
 
     @TestFactory
     public static Collection<String> getScssResourceNames()
-            throws URISyntaxException {
+            throws URISyntaxException, IOException {
         return getScssResourceNames(getResourceURLInternal(""));
     }