From 2430ede36e1fba9044b82de9d09e6a71584f1db8 Mon Sep 17 00:00:00 2001 From: Joshua Nelson Date: Fri, 4 Jun 2021 13:28:57 -0400 Subject: [PATCH] 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 ``` --- src/tools/compiletest/src/runtest.rs | 30 +++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/tools/compiletest/src/runtest.rs b/src/tools/compiletest/src/runtest.rs index 54b079a3e86..79520705cb1 100644 --- a/src/tools/compiletest/src/runtest.rs +++ b/src/tools/compiletest/src/runtest.rs @@ -2487,6 +2487,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()); @@ -2499,17 +2500,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 {