Skip to content

Commit 804b72a

Browse files
committed
If tidy isn't installed, only give one error, not many
1 parent 409382d commit 804b72a

File tree

3 files changed

+22
-19
lines changed

3 files changed

+22
-19
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

+8-18
Original file line numberDiff line numberDiff line change
@@ -2409,32 +2409,22 @@ impl<'test> TestCx<'test> {
24092409
"-modify",
24102410
];
24112411
let tidy_dir = |dir| {
2412-
let tidy = |file: &_| {
2413-
let tidy_proc = Command::new("tidy").args(&tidy_args).arg(file).spawn();
2414-
match tidy_proc {
2415-
Ok(mut proc) => {
2416-
proc.wait().unwrap();
2417-
true
2418-
}
2419-
Err(err) => {
2420-
eprintln!("failed to run tidy - is it installed? - {}", err);
2421-
false
2422-
}
2423-
}
2424-
};
24252412
for entry in walkdir::WalkDir::new(dir) {
24262413
let entry = entry.expect("failed to read file");
24272414
if entry.file_type().is_file()
24282415
&& entry.path().extension().and_then(|p| p.to_str()) == Some("html".into())
24292416
{
2430-
if !tidy(entry.path()) {
2431-
return;
2432-
}
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));
24332421
}
24342422
}
24352423
};
2436-
tidy_dir(out_dir);
2437-
tidy_dir(&compare_dir);
2424+
if self.config.has_tidy {
2425+
tidy_dir(out_dir);
2426+
tidy_dir(&compare_dir);
2427+
}
24382428

24392429
let pager = {
24402430
let output = Command::new("git").args(&["config", "--get", "core.pager"]).output().ok();

0 commit comments

Comments
 (0)