Skip to content

Commit d1d44d4

Browse files
committed
Consolidate all ProcRes unwinds into one code path
1 parent 2ddf0ca commit d1d44d4

File tree

3 files changed

+29
-27
lines changed

3 files changed

+29
-27
lines changed

src/tools/compiletest/src/runtest.rs

Lines changed: 26 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -354,13 +354,10 @@ impl<'test> TestCx<'test> {
354354
}
355355
} else {
356356
if proc_res.status.success() {
357-
{
358-
self.error(&format!("{} test did not emit an error", self.config.mode));
359-
if self.config.mode == crate::common::TestMode::Ui {
360-
println!("note: by default, ui tests are expected not to compile");
361-
}
362-
proc_res.fatal(None, || ());
363-
};
357+
let err = &format!("{} test did not emit an error", self.config.mode);
358+
let extra_note = (self.config.mode == crate::common::TestMode::Ui)
359+
.then_some("note: by default, ui tests are expected not to compile");
360+
self.fatal_proc_rec_general(err, extra_note, proc_res, || ());
364361
}
365362

366363
if !self.props.dont_check_failure_status {
@@ -2010,18 +2007,34 @@ impl<'test> TestCx<'test> {
20102007
}
20112008

20122009
fn fatal_proc_rec(&self, err: &str, proc_res: &ProcRes) -> ! {
2013-
self.error(err);
2014-
proc_res.fatal(None, || ());
2010+
self.fatal_proc_rec_general(err, None, proc_res, || ());
20152011
}
20162012

2017-
fn fatal_proc_rec_with_ctx(
2013+
/// Underlying implementation of [`Self::fatal_proc_rec`], providing some
2014+
/// extra capabilities not needed by most callers.
2015+
fn fatal_proc_rec_general(
20182016
&self,
20192017
err: &str,
2018+
extra_note: Option<&str>,
20202019
proc_res: &ProcRes,
2021-
on_failure: impl FnOnce(Self),
2020+
callback_before_unwind: impl FnOnce(),
20222021
) -> ! {
20232022
self.error(err);
2024-
proc_res.fatal(None, || on_failure(*self));
2023+
2024+
// Some callers want to print additional notes after the main error message.
2025+
if let Some(note) = extra_note {
2026+
println!("{note}");
2027+
}
2028+
2029+
// Print the details and output of the subprocess that caused this test to fail.
2030+
println!("{}", proc_res.format_info());
2031+
2032+
// Some callers want print more context or show a custom diff before the unwind occurs.
2033+
callback_before_unwind();
2034+
2035+
// Use resume_unwind instead of panic!() to prevent a panic message + backtrace from
2036+
// compiletest, which is unnecessary noise.
2037+
std::panic::resume_unwind(Box::new(()));
20252038
}
20262039

20272040
// codegen tests (using FileCheck)
@@ -2080,7 +2093,7 @@ impl<'test> TestCx<'test> {
20802093
if cfg!(target_os = "freebsd") { "ISO-8859-1" } else { "UTF-8" }
20812094
}
20822095

2083-
fn compare_to_default_rustdoc(&mut self, out_dir: &Utf8Path) {
2096+
fn compare_to_default_rustdoc(&self, out_dir: &Utf8Path) {
20842097
if !self.config.has_html_tidy {
20852098
return;
20862099
}
@@ -2982,17 +2995,6 @@ impl ProcRes {
29822995
render("stderr", &self.stderr),
29832996
)
29842997
}
2985-
2986-
pub fn fatal(&self, err: Option<&str>, on_failure: impl FnOnce()) -> ! {
2987-
if let Some(e) = err {
2988-
println!("\nerror: {}", e);
2989-
}
2990-
println!("{}", self.format_info());
2991-
on_failure();
2992-
// Use resume_unwind instead of panic!() to prevent a panic message + backtrace from
2993-
// compiletest, which is unnecessary noise.
2994-
std::panic::resume_unwind(Box::new(()));
2995-
}
29962998
}
29972999

29983000
#[derive(Debug)]

src/tools/compiletest/src/runtest/rustdoc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ impl TestCx<'_> {
2828
}
2929
let res = self.run_command_to_procres(&mut cmd);
3030
if !res.status.success() {
31-
self.fatal_proc_rec_with_ctx("htmldocck failed!", &res, |mut this| {
32-
this.compare_to_default_rustdoc(&out_dir)
31+
self.fatal_proc_rec_general("htmldocck failed!", None, &res, || {
32+
self.compare_to_default_rustdoc(&out_dir);
3333
});
3434
}
3535
}

src/tools/compiletest/src/runtest/rustdoc_json.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ impl TestCx<'_> {
2929
);
3030

3131
if !res.status.success() {
32-
self.fatal_proc_rec_with_ctx("jsondocck failed!", &res, |_| {
32+
self.fatal_proc_rec_general("jsondocck failed!", None, &res, || {
3333
println!("Rustdoc Output:");
3434
println!("{}", proc_res.format_info());
3535
})

0 commit comments

Comments
 (0)