Change ProcRes::print_info to format_info

This method now returns a string instead of printing directly to
(possibly-captured) stdout.
This commit is contained in:
Zalathar 2025-08-02 12:44:51 +10:00
parent 5b9564a189
commit 2ddf0ca9f5
2 changed files with 6 additions and 5 deletions

View file

@ -2957,7 +2957,8 @@ pub struct ProcRes {
}
impl ProcRes {
pub fn print_info(&self) {
#[must_use]
pub fn format_info(&self) -> String {
fn render(name: &str, contents: &str) -> String {
let contents = json::extract_rendered(contents);
let contents = contents.trim_end();
@ -2973,20 +2974,20 @@ impl ProcRes {
}
}
println!(
format!(
"status: {}\ncommand: {}\n{}\n{}\n",
self.status,
self.cmdline,
render("stdout", &self.stdout),
render("stderr", &self.stderr),
);
)
}
pub fn fatal(&self, err: Option<&str>, on_failure: impl FnOnce()) -> ! {
if let Some(e) = err {
println!("\nerror: {}", e);
}
self.print_info();
println!("{}", self.format_info());
on_failure();
// Use resume_unwind instead of panic!() to prevent a panic message + backtrace from
// compiletest, which is unnecessary noise.

View file

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