Skip to content

Commit b44b033

Browse files
get differences
1 parent 94ad4e1 commit b44b033

File tree

2 files changed

+43
-10
lines changed

2 files changed

+43
-10
lines changed

src/librustdoc/lib.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,9 +330,11 @@ pub fn main_args(args: &[String]) -> isize {
330330
println!("rustdoc: [theme-checker] Starting tests!");
331331
for theme_file in to_check.iter() {
332332
print!(" - Checking \"{}\"...", theme_file);
333-
if !theme::test_theme_against(theme_file, &pathes) {
333+
let differences = theme::test_theme_against(theme_file, &pathes);
334+
if !differences.is_empty() {
334335
eprintln!(" FAILED");
335336
errors += 1;
337+
eprintln!("{}", differences.join("\n"));
336338
} else {
337339
println!(" OK");
338340
}

src/librustdoc/theme.rs

Lines changed: 40 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ use std::hash::{Hash, Hasher};
1414
use std::io::Read;
1515
use std::path::Path;
1616

17-
macro_rules! try_false {
18-
($e:expr) => ({
17+
macro_rules! try_something {
18+
($e:expr, $out:expr) => ({
1919
match $e {
2020
Ok(c) => c,
2121
Err(e) => {
2222
eprintln!("rustdoc: got an error: {}", e);
23-
return false;
23+
return $out;
2424
}
2525
}
2626
})
@@ -215,18 +215,49 @@ pub fn load_css_pathes(v: &[u8]) -> CssPath {
215215
parent
216216
}
217217

218-
pub fn test_theme_against<P: AsRef<Path>>(f: &P, against: &CssPath) -> bool {
219-
let mut file = try_false!(File::open(f));
218+
fn get_differences(against: &CssPath, other: &CssPath, v: &mut Vec<String>) {
219+
if against.name != other.name {
220+
return
221+
} else {
222+
for child in &against.children {
223+
let mut found = false;
224+
let mut found_working = false;
225+
let mut tmp = Vec::new();
226+
227+
for other_child in &other.children {
228+
if child.name == other_child.name {
229+
if child != other_child {
230+
get_differences(child, other_child, &mut tmp);
231+
} else {
232+
found_working = true;
233+
}
234+
found = true;
235+
break
236+
}
237+
}
238+
if found == false {
239+
v.push(format!(" Missing \"{}\" rule", child.name));
240+
} else if found_working == false {
241+
v.extend(tmp.iter().cloned());
242+
}
243+
}
244+
}
245+
}
246+
247+
pub fn test_theme_against<P: AsRef<Path>>(f: &P, against: &CssPath) -> Vec<String> {
248+
let mut file = try_something!(File::open(f), Vec::new());
220249
let mut data = Vec::with_capacity(1000);
221250

222-
try_false!(file.read_to_end(&mut data));
251+
try_something!(file.read_to_end(&mut data), Vec::new());
223252
let pathes = load_css_pathes(&data);
224253
println!("========= {:?}", pathes);
225254
println!("========= {:?}", against);
226-
pathes == *against
255+
let mut ret = Vec::new();
256+
get_differences(against, &pathes, &mut ret);
257+
ret
227258
}
228259

229-
#[test]
260+
/*#[test]
230261
fn test_comments_in_rules() {
231262
let text = r#"
232263
rule a {}
@@ -255,4 +286,4 @@ you like things like "{}" in there? :)
255286
*/
256287
end {}
257288
"#;
258-
}
289+
}*/

0 commit comments

Comments
 (0)