diff --git a/src/cmds/rust/cargo_cmd.rs b/src/cmds/rust/cargo_cmd.rs index 061b1bfbde..d16a0481b8 100644 --- a/src/cmds/rust/cargo_cmd.rs +++ b/src/cmds/rust/cargo_cmd.rs @@ -93,7 +93,11 @@ impl BlockHandler for CargoBuildHandler { !(line.trim().is_empty() && block.len() > 3) } - fn format_summary(&self, _exit_code: i32, _raw: &str) -> Option { + fn format_summary(&self, _exit_code: i32, raw: &str) -> Option { + if raw.trim().is_empty() { + return None; + } + if self.error_count == 0 && self.warnings == 0 { let mut s = format!("cargo build ({} crates compiled)", self.compiled); if let Some(ref finished) = self.finished_line { @@ -758,6 +762,10 @@ fn filter_cargo_nextest(output: &str) -> String { } fn filter_cargo_build(output: &str) -> String { + if output.trim().is_empty() { + return String::new(); + } + let mut handler = CargoBuildHandler::new(); let mut blocks: Vec> = Vec::new(); let mut current_block: Vec = Vec::new(); @@ -1353,6 +1361,11 @@ mod tests { assert!(result.contains("3 crates compiled")); } + #[test] + fn test_filter_cargo_build_quiet_success_preserves_empty_output() { + assert_eq!(filter_cargo_build(""), ""); + } + #[test] fn test_filter_cargo_build_errors() { let output = r#" Compiling rtk v0.5.0 @@ -2110,6 +2123,13 @@ error: test run failed assert!(!result.contains("Compiling"), "got: {}", result); } + #[test] + fn test_cargo_build_stream_quiet_success_preserves_empty_output() { + let mut f = BlockStreamFilter::new(CargoBuildHandler::new()); + let result = run_block_filter(&mut f, "", 0); + assert_eq!(result, ""); + } + #[test] fn test_cargo_build_stream_errors() { let input = r#" Compiling rtk v0.5.0