Log unfiltered snapshots on failure (#8349)

Cherry-picked from https://github.com/astral-sh/uv/pull/8347

Seems generally really helpful to see the unfiltered snapshot when a
test fails. Especially when debugging filters on Windows.
This commit is contained in:
Zanie Blue 2024-10-20 13:37:29 -05:00 committed by GitHub
parent 93f3316c88
commit be26e47d2f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 10 additions and 1 deletions

View File

@ -1112,6 +1112,7 @@ pub fn run_and_format<T: AsRef<str>>(
/// Execute the command and format its output status, stdout and stderr into a snapshot string.
///
/// This function is derived from `insta_cmd`s `spawn_with_info`.
#[allow(clippy::print_stderr)]
pub fn run_and_format_with_status<T: AsRef<str>>(
mut command: impl BorrowMut<Command>,
filters: impl AsRef<[(T, T)]>,
@ -1141,13 +1142,21 @@ pub fn run_and_format_with_status<T: AsRef<str>>(
.output()
.unwrap_or_else(|err| panic!("Failed to spawn {program}: {err}"));
eprintln!("\n━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ Unfiltered output ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
eprintln!(
"----- stdout -----\n{}\n----- stderr -----\n{}",
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr),
);
eprintln!("────────────────────────────────────────────────────────────────────────────────\n");
let mut snapshot = apply_filters(
format!(
"success: {:?}\nexit_code: {}\n----- stdout -----\n{}\n----- stderr -----\n{}",
output.status.success(),
output.status.code().unwrap_or(!0),
String::from_utf8_lossy(&output.stdout),
String::from_utf8_lossy(&output.stderr)
String::from_utf8_lossy(&output.stderr),
),
filters,
);