Skip to content

Commit 4c5c4aa

Browse files
committed
Auto merge of #79370 - jyn514:tidy-error, r=GuillaumeGomez
Don't abort rustdoc tests if `tidy` isn't installed Follow-up to #78752. Before: ``` Check compiletest suite=rustdoc mode=rustdoc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu) running 396 tests ..................................................2020-11-23T12:12:37.735649Z ERROR compiletest::runtest: fatal error, panic: "failed to run tidy - is it installed? - No such file or directory (os error 2)" F................................................. 100/396 .................................................................................................... 200/396 .................................................................................................... 300/396 ...............................i...............2020-11-23T12:15:00.271271Z ERROR compiletest::runtest: fatal error, panic: "failed to run tidy - is it installed? - No such file or directory (os error 2)" F................................................ ``` After: ``` Check compiletest suite=rustdoc mode=rustdoc (x86_64-unknown-linux-gnu -> x86_64-unknown-linux-gnu) running 4 tests .FFF failures: ---- [rustdoc] rustdoc/fn-pointer-arg-name.rs stdout ---- error: htmldocck failed! status: exit code: 1 command: "/usr/bin/python" "/home/joshua/rustc/src/etc/htmldocck.py" "/home/joshua/rustc/build/x86_64-unknown-linux-gnu/test/rustdoc/fn-pointer-arg-name" "/home/joshua/rustc/src/test/rustdoc/fn-pointer-arg-name.rs" stdout: ------------------------------------------ ------------------------------------------ stderr: ------------------------------------------ 4: `@has` check failed `XPATH PATTERN` did not match // `@has` - '//*[`@class="rust` fn"]' 'pub fn f(callback: fn(len: usize, foo: u32))' Encountered 1 errors ------------------------------------------ info: generating a diff against nightly rustdoc failed to run tidy - is it installed? - Permission denied (os error 13) failed to run tidy - is it installed? - Permission denied (os error 13) # a diff without running `tidy` ``` r? `@GuillaumeGomez`
2 parents 3f2088a + f9b97a8 commit 4c5c4aa

File tree

3 files changed

+26
-17
lines changed

3 files changed

+26
-17
lines changed

src/tools/compiletest/src/common.rs

+3
Original file line numberDiff line numberDiff line change
@@ -327,6 +327,9 @@ pub struct Config {
327327
/// created in `/<build_base>/rustfix_missing_coverage.txt`
328328
pub rustfix_coverage: bool,
329329

330+
/// whether to run `tidy` when a rustdoc test fails
331+
pub has_tidy: bool,
332+
330333
// Configuration for various run-make tests frobbing things like C compilers
331334
// or querying about various LLVM component information.
332335
pub cc: String,

src/tools/compiletest/src/main.rs

+11-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::ffi::OsString;
1414
use std::fs;
1515
use std::io::{self, ErrorKind};
1616
use std::path::{Path, PathBuf};
17-
use std::process::Command;
17+
use std::process::{Command, Stdio};
1818
use std::time::SystemTime;
1919
use test::ColorConfig;
2020
use tracing::*;
@@ -43,6 +43,10 @@ fn main() {
4343
panic!("Can't find Valgrind to run Valgrind tests");
4444
}
4545

46+
if !config.has_tidy && config.mode == Mode::Rustdoc {
47+
eprintln!("warning: `tidy` is not installed; generated diffs will be harder to read");
48+
}
49+
4650
log_config(&config);
4751
run_tests(config);
4852
}
@@ -189,6 +193,11 @@ pub fn parse_config(args: Vec<String>) -> Config {
189193

190194
let src_base = opt_path(matches, "src-base");
191195
let run_ignored = matches.opt_present("ignored");
196+
let has_tidy = Command::new("tidy")
197+
.arg("--version")
198+
.stdout(Stdio::null())
199+
.status()
200+
.map_or(false, |status| status.success());
192201
Config {
193202
bless: matches.opt_present("bless"),
194203
compile_lib_path: make_absolute(opt_path(matches, "compile-lib-path")),
@@ -244,6 +253,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
244253
remote_test_client: matches.opt_str("remote-test-client").map(PathBuf::from),
245254
compare_mode: matches.opt_str("compare-mode").map(CompareMode::parse),
246255
rustfix_coverage: matches.opt_present("rustfix-coverage"),
256+
has_tidy,
247257

248258
cc: matches.opt_str("cc").unwrap(),
249259
cxx: matches.opt_str("cxx").unwrap(),

src/tools/compiletest/src/runtest.rs

+12-16
Original file line numberDiff line numberDiff line change
@@ -2394,7 +2394,8 @@ impl<'test> TestCx<'test> {
23942394

23952395
let proc_res = new_rustdoc.document(&compare_dir);
23962396
if !proc_res.status.success() {
2397-
proc_res.fatal(Some("failed to run nightly rustdoc"), || ());
2397+
eprintln!("failed to run nightly rustdoc");
2398+
return;
23982399
}
23992400

24002401
#[rustfmt::skip]
@@ -2408,28 +2409,22 @@ impl<'test> TestCx<'test> {
24082409
"-modify",
24092410
];
24102411
let tidy_dir = |dir| {
2411-
let tidy = |file: &_| {
2412-
Command::new("tidy")
2413-
.args(&tidy_args)
2414-
.arg(file)
2415-
.spawn()
2416-
.unwrap_or_else(|err| {
2417-
self.fatal(&format!("failed to run tidy - is it installed? - {}", err))
2418-
})
2419-
.wait()
2420-
.unwrap()
2421-
};
24222412
for entry in walkdir::WalkDir::new(dir) {
24232413
let entry = entry.expect("failed to read file");
24242414
if entry.file_type().is_file()
24252415
&& entry.path().extension().and_then(|p| p.to_str()) == Some("html".into())
24262416
{
2427-
tidy(entry.path());
2417+
let status =
2418+
Command::new("tidy").args(&tidy_args).arg(entry.path()).status().unwrap();
2419+
// `tidy` returns 1 if it modified the file.
2420+
assert!(status.success() || status.code() == Some(1));
24282421
}
24292422
}
24302423
};
2431-
tidy_dir(out_dir);
2432-
tidy_dir(&compare_dir);
2424+
if self.config.has_tidy {
2425+
tidy_dir(out_dir);
2426+
tidy_dir(&compare_dir);
2427+
}
24332428

24342429
let pager = {
24352430
let output = Command::new("git").args(&["config", "--get", "core.pager"]).output().ok();
@@ -2442,7 +2437,8 @@ impl<'test> TestCx<'test> {
24422437
})
24432438
};
24442439
let mut diff = Command::new("diff");
2445-
diff.args(&["-u", "-r"]).args(&[&compare_dir, out_dir]);
2440+
// diff recursively, showing context, and excluding .css files
2441+
diff.args(&["-u", "-r", "-x", "*.css"]).args(&[&compare_dir, out_dir]);
24462442

24472443
let output = if let Some(pager) = pager {
24482444
let diff_pid = diff.stdout(Stdio::piped()).spawn().expect("failed to run `diff`");

0 commit comments

Comments
 (0)