@@ -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