From be26e47d2f47125668f22ab598f62155f7a056cd Mon Sep 17 00:00:00 2001 From: Zanie Blue Date: Sun, 20 Oct 2024 13:37:29 -0500 Subject: [PATCH] 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. --- crates/uv/tests/it/common/mod.rs | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/crates/uv/tests/it/common/mod.rs b/crates/uv/tests/it/common/mod.rs index e5e5878cd..229a1e71a 100644 --- a/crates/uv/tests/it/common/mod.rs +++ b/crates/uv/tests/it/common/mod.rs @@ -1112,6 +1112,7 @@ pub fn run_and_format>( /// 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>( mut command: impl BorrowMut, filters: impl AsRef<[(T, T)]>, @@ -1141,13 +1142,21 @@ pub fn run_and_format_with_status>( .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, );