Skip to content

Commit 2430ede

Browse files
committed
rustdoc: Print a warning if the diff when comparing to old nightlies is empty
This avoids confusing situations where it's unclear whether there's a bug in the diff tool or not: ``` 26: @Has check failed `XPATH PATTERN` did not match // @Has - '//code/a[@href="{{channel}}/std/primitive.i32.html"]' 'i32' Encountered 6 errors ------------------------------------------ info: generating a diff against nightly rustdoc failures: [rustdoc] rustdoc/primitive-reexport.rs ```
1 parent c4c2ab5 commit 2430ede

File tree

1 file changed

+21
-9
lines changed

1 file changed

+21
-9
lines changed

src/tools/compiletest/src/runtest.rs

+21-9
Original file line numberDiff line numberDiff line change
@@ -2487,6 +2487,7 @@ impl<'test> TestCx<'test> {
24872487

24882488
{
24892489
let mut diff_output = File::create(&diff_filename).unwrap();
2490+
let mut wrote_data = false;
24902491
for entry in walkdir::WalkDir::new(out_dir) {
24912492
let entry = entry.expect("failed to read file");
24922493
let extension = entry.path().extension().and_then(|p| p.to_str());
@@ -2499,17 +2500,28 @@ impl<'test> TestCx<'test> {
24992500
if let Ok(s) = std::fs::read(&expected_path) { s } else { continue };
25002501
let actual_path = entry.path();
25012502
let actual = std::fs::read(&actual_path).unwrap();
2502-
diff_output
2503-
.write_all(&unified_diff::diff(
2504-
&expected,
2505-
&expected_path.to_string_lossy(),
2506-
&actual,
2507-
&actual_path.to_string_lossy(),
2508-
3,
2509-
))
2510-
.unwrap();
2503+
let diff = unified_diff::diff(
2504+
&expected,
2505+
&expected_path.to_string_lossy(),
2506+
&actual,
2507+
&actual_path.to_string_lossy(),
2508+
3,
2509+
);
2510+
wrote_data |= !diff.is_empty();
2511+
diff_output.write_all(&diff).unwrap();
25112512
}
25122513
}
2514+
2515+
if !wrote_data {
2516+
println!("note: diff is identical to nightly rustdoc");
2517+
assert!(diff_output.metadata().unwrap().len() == 0);
2518+
return;
2519+
} else if self.config.verbose {
2520+
eprintln!("printing diff:");
2521+
let mut buf = Vec::new();
2522+
diff_output.read_to_end(&mut buf).unwrap();
2523+
std::io::stderr().lock().write_all(&mut buf).unwrap();
2524+
}
25132525
}
25142526

25152527
match self.config.color {

0 commit comments

Comments
 (0)