Consolidate all ProcRes unwinds into one code path

This commit is contained in:
Zalathar 2025-08-02 12:57:30 +10:00
parent 2ddf0ca9f5
commit d1d44d44f1
3 changed files with 29 additions and 27 deletions

View file

@ -354,13 +354,10 @@ impl<'test> TestCx<'test> {
}
} else {
if proc_res.status.success() {
{
self.error(&format!("{} test did not emit an error", self.config.mode));
if self.config.mode == crate::common::TestMode::Ui {
println!("note: by default, ui tests are expected not to compile");
}
proc_res.fatal(None, || ());
};
let err = &format!("{} test did not emit an error", self.config.mode);
let extra_note = (self.config.mode == crate::common::TestMode::Ui)
.then_some("note: by default, ui tests are expected not to compile");
self.fatal_proc_rec_general(err, extra_note, proc_res, || ());
}
if !self.props.dont_check_failure_status {
@ -2010,18 +2007,34 @@ impl<'test> TestCx<'test> {
}
fn fatal_proc_rec(&self, err: &str, proc_res: &ProcRes) -> ! {
self.error(err);
proc_res.fatal(None, || ());
self.fatal_proc_rec_general(err, None, proc_res, || ());
}
fn fatal_proc_rec_with_ctx(
/// Underlying implementation of [`Self::fatal_proc_rec`], providing some
/// extra capabilities not needed by most callers.
fn fatal_proc_rec_general(
&self,
err: &str,
extra_note: Option<&str>,
proc_res: &ProcRes,
on_failure: impl FnOnce(Self),
callback_before_unwind: impl FnOnce(),
) -> ! {
self.error(err);
proc_res.fatal(None, || on_failure(*self));
// Some callers want to print additional notes after the main error message.
if let Some(note) = extra_note {
println!("{note}");
}
// Print the details and output of the subprocess that caused this test to fail.
println!("{}", proc_res.format_info());
// Some callers want print more context or show a custom diff before the unwind occurs.
callback_before_unwind();
// Use resume_unwind instead of panic!() to prevent a panic message + backtrace from
// compiletest, which is unnecessary noise.
std::panic::resume_unwind(Box::new(()));
}
// codegen tests (using FileCheck)
@ -2080,7 +2093,7 @@ impl<'test> TestCx<'test> {
if cfg!(target_os = "freebsd") { "ISO-8859-1" } else { "UTF-8" }
}
fn compare_to_default_rustdoc(&mut self, out_dir: &Utf8Path) {
fn compare_to_default_rustdoc(&self, out_dir: &Utf8Path) {
if !self.config.has_html_tidy {
return;
}
@ -2982,17 +2995,6 @@ impl ProcRes {
render("stderr", &self.stderr),
)
}
pub fn fatal(&self, err: Option<&str>, on_failure: impl FnOnce()) -> ! {
if let Some(e) = err {
println!("\nerror: {}", e);
}
println!("{}", self.format_info());
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(()));
}
}
#[derive(Debug)]

View file

@ -28,8 +28,8 @@ impl TestCx<'_> {
}
let res = self.run_command_to_procres(&mut cmd);
if !res.status.success() {
self.fatal_proc_rec_with_ctx("htmldocck failed!", &res, |mut this| {
this.compare_to_default_rustdoc(&out_dir)
self.fatal_proc_rec_general("htmldocck failed!", None, &res, || {
self.compare_to_default_rustdoc(&out_dir);
});
}
}

View file

@ -29,7 +29,7 @@ impl TestCx<'_> {
);
if !res.status.success() {
self.fatal_proc_rec_with_ctx("jsondocck failed!", &res, |_| {
self.fatal_proc_rec_general("jsondocck failed!", None, &res, || {
println!("Rustdoc Output:");
println!("{}", proc_res.format_info());
})