about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorGuillaume Gomez <guillaume1.gomez@gmail.com>2018-01-25 21:58:10 +0100
committerGuillaume Gomez <guillaume1.gomez@gmail.com>2018-02-08 10:53:09 +0100
commitb44b033bf1a8f74f190854048616ca90db21319e (patch)
tree948372274c7051a4cbb11b2322aaba71d52db588 /src
parent94ad4e1d38d4f3ac0f3e532b5cd07f0e15025c87 (diff)
downloadrust-b44b033bf1a8f74f190854048616ca90db21319e.tar.gz
rust-b44b033bf1a8f74f190854048616ca90db21319e.zip
get differences
Diffstat (limited to 'src')
-rw-r--r--src/librustdoc/lib.rs4
-rw-r--r--src/librustdoc/theme.rs49
2 files changed, 43 insertions, 10 deletions
diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs
index efdfcafb40a..613ac67f03b 100644
--- a/src/librustdoc/lib.rs
+++ b/src/librustdoc/lib.rs
@@ -330,9 +330,11 @@ pub fn main_args(args: &[String]) -> isize {
         println!("rustdoc: [theme-checker] Starting tests!");
         for theme_file in to_check.iter() {
             print!(" - Checking \"{}\"...", theme_file);
-            if !theme::test_theme_against(theme_file, &pathes) {
+            let differences = theme::test_theme_against(theme_file, &pathes);
+            if !differences.is_empty() {
                 eprintln!(" FAILED");
                 errors += 1;
+                eprintln!("{}", differences.join("\n"));
             } else {
                 println!(" OK");
             }
diff --git a/src/librustdoc/theme.rs b/src/librustdoc/theme.rs
index ff1adc3e4c4..933749cfcf9 100644
--- a/src/librustdoc/theme.rs
+++ b/src/librustdoc/theme.rs
@@ -14,13 +14,13 @@ use std::hash::{Hash, Hasher};
 use std::io::Read;
 use std::path::Path;
 
-macro_rules! try_false {
-    ($e:expr) => ({
+macro_rules! try_something {
+    ($e:expr, $out:expr) => ({
         match $e {
             Ok(c) => c,
             Err(e) => {
                 eprintln!("rustdoc: got an error: {}", e);
-                return false;
+                return $out;
             }
         }
     })
@@ -215,18 +215,49 @@ pub fn load_css_pathes(v: &[u8]) -> CssPath {
     parent
 }
 
-pub fn test_theme_against<P: AsRef<Path>>(f: &P, against: &CssPath) -> bool {
-    let mut file = try_false!(File::open(f));
+fn get_differences(against: &CssPath, other: &CssPath, v: &mut Vec<String>) {
+    if against.name != other.name {
+        return
+    } else {
+        for child in &against.children {
+            let mut found = false;
+            let mut found_working = false;
+            let mut tmp = Vec::new();
+
+            for other_child in &other.children {
+                if child.name == other_child.name {
+                    if child != other_child {
+                        get_differences(child, other_child, &mut tmp);
+                    } else {
+                        found_working = true;
+                    }
+                    found = true;
+                    break
+                }
+            }
+            if found == false {
+                v.push(format!("  Missing \"{}\" rule", child.name));
+            } else if found_working == false {
+                v.extend(tmp.iter().cloned());
+            }
+        }
+    }
+}
+
+pub fn test_theme_against<P: AsRef<Path>>(f: &P, against: &CssPath) -> Vec<String> {
+    let mut file = try_something!(File::open(f), Vec::new());
     let mut data = Vec::with_capacity(1000);
 
-    try_false!(file.read_to_end(&mut data));
+    try_something!(file.read_to_end(&mut data), Vec::new());
     let pathes = load_css_pathes(&data);
     println!("========= {:?}", pathes);
     println!("========= {:?}", against);
-    pathes == *against
+    let mut ret = Vec::new();
+    get_differences(against, &pathes, &mut ret);
+    ret
 }
 
-#[test]
+/*#[test]
 fn test_comments_in_rules() {
     let text = r#"
 rule a {}
@@ -255,4 +286,4 @@ you like things like "{}" in there? :)
 */
 end {}
 "#;
-}
\ No newline at end of file
+}*/