-
Notifications
You must be signed in to change notification settings - Fork 13.4k
Give a better error when rustdoc tests fail #78752
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
341eb6d
Give a better error when rustdoc tests fail
jyn514 c0eedc0
Address review comments
jyn514 acd6ce2
Fix bugs
jyn514 975471c
Fall back to `diff` if `delta` isn't installed
jyn514 619880e
Fix tests with auxiliary docs
jyn514 e6e4a0a
Capture stdout and stderr of diff so they'll be printed at the end
jyn514 4d44d77
Use default git pager instead of hard-coding `delta`
jyn514 25a3ffe
Move from bash to rust
jyn514 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -287,6 +287,7 @@ pub fn compute_stamp_hash(config: &Config) -> String { | |
format!("{:x}", hash.finish()) | ||
} | ||
|
||
#[derive(Copy, Clone)] | ||
struct TestCx<'test> { | ||
config: &'test Config, | ||
props: &'test TestProps, | ||
|
@@ -1728,7 +1729,7 @@ impl<'test> TestCx<'test> { | |
self.config.target.contains("vxworks") && !self.is_vxworks_pure_static() | ||
} | ||
|
||
fn compose_and_run_compiler(&self, mut rustc: Command, input: Option<String>) -> ProcRes { | ||
fn build_all_auxiliary(&self, rustc: &mut Command) -> PathBuf { | ||
let aux_dir = self.aux_output_dir_name(); | ||
|
||
if !self.props.aux_builds.is_empty() { | ||
|
@@ -1747,6 +1748,11 @@ impl<'test> TestCx<'test> { | |
rustc.arg("--extern").arg(format!("{}={}/{}", aux_name, aux_dir.display(), lib_name)); | ||
} | ||
|
||
aux_dir | ||
} | ||
|
||
fn compose_and_run_compiler(&self, mut rustc: Command, input: Option<String>) -> ProcRes { | ||
let aux_dir = self.build_all_auxiliary(&mut rustc); | ||
self.props.unset_rustc_env.clone().iter().fold(&mut rustc, |rustc, v| rustc.env_remove(v)); | ||
rustc.envs(self.props.rustc_env.clone()); | ||
self.compose_and_run( | ||
|
@@ -2208,7 +2214,17 @@ impl<'test> TestCx<'test> { | |
|
||
fn fatal_proc_rec(&self, err: &str, proc_res: &ProcRes) -> ! { | ||
self.error(err); | ||
proc_res.fatal(None); | ||
proc_res.fatal(None, || ()); | ||
} | ||
|
||
fn fatal_proc_rec_with_ctx( | ||
&self, | ||
err: &str, | ||
proc_res: &ProcRes, | ||
on_failure: impl FnOnce(Self), | ||
) -> ! { | ||
self.error(err); | ||
proc_res.fatal(None, || on_failure(*self)); | ||
} | ||
|
||
// codegen tests (using FileCheck) | ||
|
@@ -2325,15 +2341,131 @@ impl<'test> TestCx<'test> { | |
let res = self.cmd2procres( | ||
Command::new(&self.config.docck_python) | ||
.arg(root.join("src/etc/htmldocck.py")) | ||
.arg(out_dir) | ||
.arg(&out_dir) | ||
.arg(&self.testpaths.file), | ||
); | ||
if !res.status.success() { | ||
self.fatal_proc_rec("htmldocck failed!", &res); | ||
self.fatal_proc_rec_with_ctx("htmldocck failed!", &res, |mut this| { | ||
this.compare_to_default_rustdoc(&out_dir) | ||
}); | ||
} | ||
} | ||
} | ||
|
||
fn compare_to_default_rustdoc(&mut self, out_dir: &Path) { | ||
println!("info: generating a diff against nightly rustdoc"); | ||
|
||
let suffix = | ||
self.safe_revision().map_or("nightly".into(), |path| path.to_owned() + "-nightly"); | ||
let compare_dir = output_base_dir(self.config, self.testpaths, Some(&suffix)); | ||
// Don't give an error if the directory didn't already exist | ||
let _ = fs::remove_dir_all(&compare_dir); | ||
jyn514 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
create_dir_all(&compare_dir).unwrap(); | ||
|
||
// We need to create a new struct for the lifetimes on `config` to work. | ||
let new_rustdoc = TestCx { | ||
config: &Config { | ||
// FIXME: use beta or a user-specified rustdoc instead of | ||
// hardcoding the default toolchain | ||
rustdoc_path: Some("rustdoc".into()), | ||
// Needed for building auxiliary docs below | ||
rustc_path: "rustc".into(), | ||
..self.config.clone() | ||
}, | ||
..*self | ||
}; | ||
|
||
let output_file = TargetLocation::ThisDirectory(new_rustdoc.aux_output_dir_name()); | ||
let mut rustc = new_rustdoc.make_compile_args( | ||
&new_rustdoc.testpaths.file, | ||
output_file, | ||
EmitMetadata::No, | ||
AllowUnused::Yes, | ||
); | ||
rustc.arg("-L").arg(&new_rustdoc.aux_output_dir_name()); | ||
new_rustdoc.build_all_auxiliary(&mut rustc); | ||
|
||
let proc_res = new_rustdoc.document(&compare_dir); | ||
if !proc_res.status.success() { | ||
proc_res.fatal(Some("failed to run nightly rustdoc"), || ()); | ||
} | ||
|
||
#[rustfmt::skip] | ||
let tidy_args = [ | ||
"--indent", "yes", | ||
"--indent-spaces", "2", | ||
"--wrap", "0", | ||
"--show-warnings", "no", | ||
"--markup", "yes", | ||
"--quiet", "yes", | ||
"-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()); | ||
} | ||
} | ||
}; | ||
tidy_dir(out_dir); | ||
tidy_dir(&compare_dir); | ||
|
||
let pager = { | ||
let output = Command::new("git").args(&["config", "--get", "core.pager"]).output().ok(); | ||
output.and_then(|out| { | ||
if out.status.success() { | ||
Some(String::from_utf8(out.stdout).expect("invalid UTF8 in git pager")) | ||
} else { | ||
None | ||
} | ||
}) | ||
}; | ||
let mut diff = Command::new("diff"); | ||
diff.args(&["-u", "-r"]).args(&[out_dir, &compare_dir]); | ||
|
||
let output = if let Some(pager) = pager { | ||
let diff_pid = diff.stdout(Stdio::piped()).spawn().expect("failed to run `diff`"); | ||
let pager = pager.trim(); | ||
if self.config.verbose { | ||
eprintln!("using pager {}", pager); | ||
} | ||
let output = Command::new(pager) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, |
||
// disable paging; we want this to be non-interactive | ||
.env("PAGER", "") | ||
.stdin(diff_pid.stdout.unwrap()) | ||
// Capture output and print it explicitly so it will in turn be | ||
// captured by libtest. | ||
.output() | ||
.unwrap(); | ||
assert!(output.status.success()); | ||
output | ||
} else { | ||
eprintln!("warning: no pager configured, falling back to `diff --color`"); | ||
eprintln!( | ||
"help: try configuring a git pager (e.g. `delta`) with `git config --global core.pager delta`" | ||
); | ||
let output = diff.arg("--color").output().unwrap(); | ||
assert!(output.status.success() || output.status.code() == Some(1)); | ||
output | ||
}; | ||
println!("{}", String::from_utf8_lossy(&output.stdout)); | ||
eprintln!("{}", String::from_utf8_lossy(&output.stderr)); | ||
} | ||
|
||
fn get_lines<P: AsRef<Path>>( | ||
&self, | ||
path: &P, | ||
|
@@ -3590,7 +3722,7 @@ pub struct ProcRes { | |
} | ||
|
||
impl ProcRes { | ||
pub fn fatal(&self, err: Option<&str>) -> ! { | ||
pub fn fatal(&self, err: Option<&str>, on_failure: impl FnOnce()) -> ! { | ||
if let Some(e) = err { | ||
println!("\nerror: {}", e); | ||
} | ||
|
@@ -3612,6 +3744,7 @@ impl ProcRes { | |
json::extract_rendered(&self.stdout), | ||
json::extract_rendered(&self.stderr), | ||
); | ||
on_failure(); | ||
// Use resume_unwind instead of panic!() to prevent a panic message + backtrace from | ||
// compiletest, which is unnecessary noise. | ||
std::panic::resume_unwind(Box::new(())); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.