about summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2021-06-10 11:02:12 +0900
committerGitHub <noreply@github.com>2021-06-10 11:02:12 +0900
commit232e7a5e7abac697c9d669cb4bb6380affa69b55 (patch)
tree345c74ef591d7ec893f7c24a26c0b61ab4cd45d0 /src
parent578eb6d65fbfaa30f6d0acd27ed2d506aa4d6117 (diff)
parent2430ede36e1fba9044b82de9d09e6a71584f1db8 (diff)
downloadrust-232e7a5e7abac697c9d669cb4bb6380affa69b55.tar.gz
rust-232e7a5e7abac697c9d669cb4bb6380affa69b55.zip
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
```
Diffstat (limited to 'src')
-rw-r--r--src/tools/compiletest/src/runtest.rs30
1 files changed, 21 insertions, 9 deletions
diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs
index 931c822ffe2..1e7c3930246 100644
--- a/src/tools/compiletest/src/runtest.rs
+++ b/src/tools/compiletest/src/runtest.rs
@@ -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 {