Skip to content

Commit f954b61

Browse files
kylehgcclaude
andcommitted
fix(cargo): stop the raw-tail fallback restating captured warnings
Review follow-up. When filter_cargo_test parses no test results and no compile errors — `cargo test --no-run` on a crate that warns — the last-5-meaningful-lines fallback appended raw output onto a result that already held the warnings section, printing those lines twice. Same double-report already fixed on the streaming path. Exclude lines the warnings section printed from the tail. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent 6235d4b commit f954b61

1 file changed

Lines changed: 39 additions & 2 deletions

File tree

‎src/cmds/rust/cargo_cmd.rs‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::core::utils::{join_with_overflow, resolved_command, truncate};
88
use anyhow::Result;
99
use serde::Deserialize;
1010
use std::cmp::Ordering;
11-
use std::collections::HashMap;
11+
use std::collections::{HashMap, HashSet};
1212
use std::ffi::OsString;
1313
use std::sync::LazyLock;
1414

@@ -1362,10 +1362,13 @@ pub(crate) fn filter_cargo_test(output: &str) -> String {
13621362
}
13631363
}
13641364

1365-
// Fallback: show last meaningful lines
1365+
// Fallback: show last meaningful lines, minus anything the warnings
1366+
// section above already printed — otherwise those lines report twice.
1367+
let already_shown: HashSet<&str> = warnings_section.lines().collect();
13661368
let meaningful: Vec<&str> = output
13671369
.lines()
13681370
.filter(|l| !l.trim().is_empty() && !l.trim_start().starts_with("Compiling"))
1371+
.filter(|l| !already_shown.contains(*l))
13691372
.collect();
13701373
for line in meaningful.iter().rev().take(5).rev() {
13711374
result.push_str(&format!("{}\n", line));
@@ -1802,6 +1805,40 @@ error: aborting due to 1 previous error
18021805
);
18031806
}
18041807

1808+
#[test]
1809+
fn test_filter_cargo_test_no_run_does_not_repeat_warnings_in_tail() {
1810+
// `cargo test --no-run`: warnings, but no "test result:" line and no
1811+
// errors — the raw-tail fallback must not restate lines the warnings
1812+
// section already printed.
1813+
let output = r#" Compiling failproj v0.1.0
1814+
warning: function `unused_helper` is never used
1815+
--> src/lib.rs:1:4
1816+
|
1817+
1 | fn unused_helper() -> i32 {
1818+
| ^^^^^^^^^^^^^
1819+
|
1820+
= note: `#[warn(dead_code)]` on by default
1821+
1822+
warning: `failproj` (lib) generated 1 warning
1823+
Finished `test` profile [unoptimized + debuginfo] target(s) in 0.42s
1824+
Executable unittests src/lib.rs (target/debug/deps/failproj-abc123)
1825+
"#;
1826+
let result = filter_cargo_test(output);
1827+
assert_eq!(
1828+
result
1829+
.matches("= note: `#[warn(dead_code)]` on by default")
1830+
.count(),
1831+
1,
1832+
"warning line must not appear twice, got: {}",
1833+
result
1834+
);
1835+
assert!(
1836+
result.contains("unused_helper"),
1837+
"warning must still be reported, got: {}",
1838+
result
1839+
);
1840+
}
1841+
18051842
#[test]
18061843
fn test_streamed_cargo_test_handler_does_not_repeat_streamed_warnings() {
18071844
use crate::core::stream::{BlockStreamFilter, StreamFilter};

0 commit comments

Comments
 (0)