Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't abort rustdoc tests if tidy isn't installed #79370

Merged
merged 3 commits into from
Dec 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/tools/compiletest/src/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ pub struct Config {
/// created in `/<build_base>/rustfix_missing_coverage.txt`
pub rustfix_coverage: bool,

/// whether to run `tidy` when a rustdoc test fails
pub has_tidy: bool,

// Configuration for various run-make tests frobbing things like C compilers
// or querying about various LLVM component information.
pub cc: String,
Expand Down
12 changes: 11 additions & 1 deletion src/tools/compiletest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::ffi::OsString;
use std::fs;
use std::io::{self, ErrorKind};
use std::path::{Path, PathBuf};
use std::process::Command;
use std::process::{Command, Stdio};
use std::time::SystemTime;
use test::ColorConfig;
use tracing::*;
Expand Down Expand Up @@ -43,6 +43,10 @@ fn main() {
panic!("Can't find Valgrind to run Valgrind tests");
}

if !config.has_tidy && config.mode == Mode::Rustdoc {
eprintln!("warning: `tidy` is not installed; generated diffs will be harder to read");
}

log_config(&config);
run_tests(config);
}
Expand Down Expand Up @@ -189,6 +193,11 @@ pub fn parse_config(args: Vec<String>) -> Config {

let src_base = opt_path(matches, "src-base");
let run_ignored = matches.opt_present("ignored");
let has_tidy = Command::new("tidy")
.arg("--version")
.stdout(Stdio::null())
.status()
.map_or(false, |status| status.success());
Config {
bless: matches.opt_present("bless"),
compile_lib_path: make_absolute(opt_path(matches, "compile-lib-path")),
Expand Down Expand Up @@ -244,6 +253,7 @@ pub fn parse_config(args: Vec<String>) -> Config {
remote_test_client: matches.opt_str("remote-test-client").map(PathBuf::from),
compare_mode: matches.opt_str("compare-mode").map(CompareMode::parse),
rustfix_coverage: matches.opt_present("rustfix-coverage"),
has_tidy,

cc: matches.opt_str("cc").unwrap(),
cxx: matches.opt_str("cxx").unwrap(),
Expand Down
28 changes: 12 additions & 16 deletions src/tools/compiletest/src/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2394,7 +2394,8 @@ impl<'test> TestCx<'test> {

let proc_res = new_rustdoc.document(&compare_dir);
if !proc_res.status.success() {
proc_res.fatal(Some("failed to run nightly rustdoc"), || ());
eprintln!("failed to run nightly rustdoc");
return;
}

#[rustfmt::skip]
Expand All @@ -2408,28 +2409,22 @@ impl<'test> TestCx<'test> {
"-modify",
];
let tidy_dir = |dir| {
let tidy = |file: &_| {
Command::new("tidy")
.args(&tidy_args)
.arg(file)
.spawn()
.unwrap_or_else(|err| {
self.fatal(&format!("failed to run tidy - is it installed? - {}", err))
})
.wait()
.unwrap()
};
for entry in walkdir::WalkDir::new(dir) {
let entry = entry.expect("failed to read file");
if entry.file_type().is_file()
&& entry.path().extension().and_then(|p| p.to_str()) == Some("html".into())
{
tidy(entry.path());
let status =
Command::new("tidy").args(&tidy_args).arg(entry.path()).status().unwrap();
jyn514 marked this conversation as resolved.
Show resolved Hide resolved
// `tidy` returns 1 if it modified the file.
assert!(status.success() || status.code() == Some(1));
}
}
};
tidy_dir(out_dir);
tidy_dir(&compare_dir);
if self.config.has_tidy {
tidy_dir(out_dir);
tidy_dir(&compare_dir);
}

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

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