Skip to content

Commit 63ee1cd

Browse files
Improve output a bit in case of error
1 parent 9ee6981 commit 63ee1cd

File tree

2 files changed

+24
-8
lines changed

2 files changed

+24
-8
lines changed

src/librustdoc/lib.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -330,11 +330,13 @@ 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-
let differences = theme::test_theme_against(theme_file, &pathes);
334-
if !differences.is_empty() {
333+
let (success, differences) = theme::test_theme_against(theme_file, &pathes);
334+
if !differences.is_empty() || !success {
335335
eprintln!(" FAILED");
336336
errors += 1;
337-
eprintln!("{}", differences.join("\n"));
337+
if !differences.is_empty() {
338+
eprintln!("{}", differences.join("\n"));
339+
}
338340
} else {
339341
println!(" OK");
340342
}
@@ -408,7 +410,8 @@ pub fn main_args(args: &[String]) -> isize {
408410
eprintln!("rustdoc: option --themes arguments must all be files");
409411
return 1;
410412
}
411-
if !theme::test_theme_against(&theme_file, &pathes).is_empty() {
413+
let (success, ret) = theme::test_theme_against(&theme_file, &pathes);
414+
if !success || !ret.is_empty() {
412415
eprintln!("rustdoc: invalid theme: \"{}\"", theme_s);
413416
eprintln!(" Check what's wrong with the \"theme-checker\" option");
414417
return 1;

src/librustdoc/theme.rs

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -259,15 +259,15 @@ pub fn get_differences(against: &CssPath, other: &CssPath, v: &mut Vec<String>)
259259
}
260260
}
261261

262-
pub fn test_theme_against<P: AsRef<Path>>(f: &P, against: &CssPath) -> Vec<String> {
263-
let mut file = try_something!(File::open(f), Vec::new());
262+
pub fn test_theme_against<P: AsRef<Path>>(f: &P, against: &CssPath) -> (bool, Vec<String>) {
263+
let mut file = try_something!(File::open(f), (false, Vec::new()));
264264
let mut data = Vec::with_capacity(1000);
265265

266-
try_something!(file.read_to_end(&mut data), Vec::new());
266+
try_something!(file.read_to_end(&mut data), (false, Vec::new()));
267267
let pathes = load_css_pathes(&data);
268268
let mut ret = Vec::new();
269269
get_differences(against, &pathes, &mut ret);
270-
ret
270+
(true, ret)
271271
}
272272

273273
#[cfg(test)]
@@ -321,6 +321,19 @@ rule j end {}
321321
&load_css_pathes(text.as_bytes())).is_empty());
322322
}
323323

324+
#[test]
325+
fn test_text() {
326+
let text = r#"
327+
a
328+
/* sdfs
329+
*/ b
330+
c // sdf
331+
d {}
332+
"#;
333+
let pathes = load_css_pathes(text.as_bytes());
334+
assert!(pathes.children.get("a b c d").is_some());
335+
}
336+
324337
#[test]
325338
fn test_comparison() {
326339
let x = r#"

0 commit comments

Comments
 (0)