From 63ee1cd846b92eb3a124ec345d4889bdb5bca8e3 Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Fri, 26 Jan 2018 00:43:57 +0100 Subject: [PATCH] Improve output a bit in case of error --- src/librustdoc/lib.rs | 11 +++++++---- src/librustdoc/theme.rs | 21 +++++++++++++++++---- 2 files changed, 24 insertions(+), 8 deletions(-) diff --git a/src/librustdoc/lib.rs b/src/librustdoc/lib.rs index 1bdcebcee98..c08cff98892 100644 --- a/src/librustdoc/lib.rs +++ b/src/librustdoc/lib.rs @@ -330,11 +330,13 @@ pub fn main_args(args: &[String]) -> isize { println!("rustdoc: [theme-checker] Starting tests!"); for theme_file in to_check.iter() { print!(" - Checking \"{}\"...", theme_file); - let differences = theme::test_theme_against(theme_file, &pathes); - if !differences.is_empty() { + let (success, differences) = theme::test_theme_against(theme_file, &pathes); + if !differences.is_empty() || !success { eprintln!(" FAILED"); errors += 1; - eprintln!("{}", differences.join("\n")); + if !differences.is_empty() { + eprintln!("{}", differences.join("\n")); + } } else { println!(" OK"); } @@ -408,7 +410,8 @@ pub fn main_args(args: &[String]) -> isize { eprintln!("rustdoc: option --themes arguments must all be files"); return 1; } - if !theme::test_theme_against(&theme_file, &pathes).is_empty() { + let (success, ret) = theme::test_theme_against(&theme_file, &pathes); + if !success || !ret.is_empty() { eprintln!("rustdoc: invalid theme: \"{}\"", theme_s); eprintln!(" Check what's wrong with the \"theme-checker\" option"); return 1; diff --git a/src/librustdoc/theme.rs b/src/librustdoc/theme.rs index b64d61184e0..fe753878041 100644 --- a/src/librustdoc/theme.rs +++ b/src/librustdoc/theme.rs @@ -259,15 +259,15 @@ pub fn get_differences(against: &CssPath, other: &CssPath, v: &mut Vec) } } -pub fn test_theme_against>(f: &P, against: &CssPath) -> Vec { - let mut file = try_something!(File::open(f), Vec::new()); +pub fn test_theme_against>(f: &P, against: &CssPath) -> (bool, Vec) { + let mut file = try_something!(File::open(f), (false, Vec::new())); let mut data = Vec::with_capacity(1000); - try_something!(file.read_to_end(&mut data), Vec::new()); + try_something!(file.read_to_end(&mut data), (false, Vec::new())); let pathes = load_css_pathes(&data); let mut ret = Vec::new(); get_differences(against, &pathes, &mut ret); - ret + (true, ret) } #[cfg(test)] @@ -321,6 +321,19 @@ rule j end {} &load_css_pathes(text.as_bytes())).is_empty()); } + #[test] + fn test_text() { + let text = r#" +a +/* sdfs +*/ b +c // sdf +d {} +"#; + let pathes = load_css_pathes(text.as_bytes()); + assert!(pathes.children.get("a b c d").is_some()); + } + #[test] fn test_comparison() { let x = r#"