Skip to content

Commit 97b6878

Browse files
authored
Merge pull request #738 from youbamj/fix/cargo-test-compile-diagnostics
fix(cargo): preserve test compile diagnostics
2 parents ec92c43 + 15d5beb commit 97b6878

2 files changed

Lines changed: 39 additions & 0 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2020
* **ruby:** add `ruby_exec()` shared utility for auto-detecting `bundle exec` when Gemfile exists
2121
* **ruby:** add discover/rewrite rules for rake, rails, rspec, rubocop, and bundle commands
2222

23+
### Bug Fixes
24+
25+
* **cargo:** preserve compile diagnostics when `cargo test` fails before any test suites run
26+
2327
## [0.30.1](https://github.com/rtk-ai/rtk/compare/v0.30.0...v0.30.1) (2026-03-18)
2428

2529

src/cargo_cmd.rs

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -850,6 +850,18 @@ fn filter_cargo_test(output: &str) -> String {
850850
}
851851

852852
if result.trim().is_empty() {
853+
let has_compile_errors = output.lines().any(|line| {
854+
let trimmed = line.trim_start();
855+
trimmed.starts_with("error[") || trimmed.starts_with("error:")
856+
});
857+
858+
if has_compile_errors {
859+
let build_filtered = filter_cargo_build(output);
860+
if build_filtered.starts_with("cargo build:") {
861+
return build_filtered.replacen("cargo build:", "cargo test:", 1);
862+
}
863+
}
864+
853865
// Fallback: show last meaningful lines
854866
let meaningful: Vec<&str> = output
855867
.lines()
@@ -1314,6 +1326,29 @@ test result: MALFORMED LINE WITHOUT PROPER FORMAT
13141326
);
13151327
}
13161328

1329+
#[test]
1330+
fn test_filter_cargo_test_compile_error_preserves_error_header() {
1331+
let output = r#" Compiling rtk v0.31.0 (/workspace/projects/rtk)
1332+
error[E0425]: cannot find value `missing_symbol` in this scope
1333+
--> tests/repro_compile_fail.rs:3:13
1334+
|
1335+
3 | let _ = missing_symbol;
1336+
| ^^^^^^^^^^^^^^ not found in this scope
1337+
1338+
For more information about this error, try `rustc --explain E0425`.
1339+
error: could not compile `rtk` (test "repro_compile_fail") due to 1 previous error
1340+
"#;
1341+
let result = filter_cargo_test(output);
1342+
assert!(result.contains("cargo test: 1 errors, 0 warnings (1 crates)"));
1343+
assert!(result.contains("error[E0425]"), "got: {}", result);
1344+
assert!(
1345+
result.contains("--> tests/repro_compile_fail.rs:3:13"),
1346+
"got: {}",
1347+
result
1348+
);
1349+
assert!(!result.starts_with('|'), "got: {}", result);
1350+
}
1351+
13171352
#[test]
13181353
fn test_filter_cargo_clippy_clean() {
13191354
let output = r#" Checking rtk v0.5.0

0 commit comments

Comments
 (0)