From 12d5574d0b38a871646757fb28c6c9cf31767b33 Mon Sep 17 00:00:00 2001 From: Harnoor Lal Date: Sat, 7 Mar 2026 16:20:32 -0800 Subject: [PATCH] test(cli): assert --max-weight error prints exactly once Strengthen the trace_max_weight_exceeded test to verify the threshold error message appears exactly once in stderr, preventing regression of the duplicate-print bug. Closes #148 --- tests/cli.rs | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/cli.rs b/tests/cli.rs index aff8c93..f301e83 100644 --- a/tests/cli.rs +++ b/tests/cli.rs @@ -194,12 +194,19 @@ fn trace_diff_from_json() { fn trace_max_weight_exceeded() { let p = common::TestProject::new(); // Threshold of 1 byte -- guaranteed to exceed - chainsaw() + let output = chainsaw() .args(["trace", "--max-weight", "1", "--no-cache"]) .arg(&p.entry) - .assert() - .failure() - .stderr(predicate::str::contains("exceeds --max-weight")); + .output() + .unwrap(); + assert!(!output.status.success()); + let stderr = String::from_utf8_lossy(&output.stderr); + // The error must appear exactly once (not duplicated by both eprintln and main handler). + let count = stderr.matches("exceeds --max-weight").count(); + assert_eq!( + count, 1, + "expected error to appear exactly once, got {count}; stderr:\n{stderr}" + ); } #[test]