Rollup merge of #85997 - jyn514:rustdoc-diff, r=Mark-Simulacrum

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
```
This commit is contained in:
Yuki Okushi 2021-06-10 11:02:12 +09:00 committed by GitHub
commit 232e7a5e7a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -2488,6 +2488,7 @@ impl<'test> TestCx<'test> {
{
let mut diff_output = File::create(&diff_filename).unwrap();
let mut wrote_data = false;
for entry in walkdir::WalkDir::new(out_dir) {
let entry = entry.expect("failed to read file");
let extension = entry.path().extension().and_then(|p| p.to_str());
@ -2500,17 +2501,28 @@ impl<'test> TestCx<'test> {
if let Ok(s) = std::fs::read(&expected_path) { s } else { continue };
let actual_path = entry.path();
let actual = std::fs::read(&actual_path).unwrap();
diff_output
.write_all(&unified_diff::diff(
&expected,
&expected_path.to_string_lossy(),
&actual,
&actual_path.to_string_lossy(),
3,
))
.unwrap();
let diff = unified_diff::diff(
&expected,
&expected_path.to_string_lossy(),
&actual,
&actual_path.to_string_lossy(),
3,
);
wrote_data |= !diff.is_empty();
diff_output.write_all(&diff).unwrap();
}
}
if !wrote_data {
println!("note: diff is identical to nightly rustdoc");
assert!(diff_output.metadata().unwrap().len() == 0);
return;
} else if self.config.verbose {
eprintln!("printing diff:");
let mut buf = Vec::new();
diff_output.read_to_end(&mut buf).unwrap();
std::io::stderr().lock().write_all(&mut buf).unwrap();
}
}
match self.config.color {