33//! Tests for message caching can be found in `cache_messages`.
44
55use cargo_test_support:: { process, project, Project } ;
6+ use cargo_util:: ProcessError ;
67
78/// Captures the actual diagnostics displayed by rustc. This is done to avoid
89/// relying on the exact message formatting in rustc.
@@ -14,20 +15,24 @@ pub fn raw_rustc_output(project: &Project, path: &str, extra: &[&str]) -> String
1415 } else {
1516 proc. arg ( path) ;
1617 }
17- let rustc_output = proc
18+ let rustc_output = match proc
1819 . arg ( "--crate-type=lib" )
1920 . args ( extra)
2021 . cwd ( project. root ( ) )
2122 . exec_with_output ( )
22- . expect ( "rustc to run" ) ;
23- assert ! ( rustc_output. stdout. is_empty( ) ) ;
24- assert ! ( rustc_output. status. success( ) ) ;
23+ {
24+ Ok ( output) => output. stderr ,
25+ Err ( e) => e. downcast :: < ProcessError > ( ) . unwrap ( ) . stderr . unwrap ( ) ,
26+ } ;
2527 // Do a little dance to remove rustc's "warnings emitted" message and the subsequent newline.
26- let stderr = std:: str:: from_utf8 ( & rustc_output. stderr ) . expect ( "utf8" ) ;
28+ let stderr = std:: str:: from_utf8 ( & rustc_output) . expect ( "utf8" ) ;
2729 let mut lines = stderr. lines ( ) ;
2830 let mut result = String :: new ( ) ;
2931 while let Some ( line) = lines. next ( ) {
30- if line. contains ( "warning emitted" ) || line. contains ( "warnings emitted" ) {
32+ if line. contains ( "warning emitted" )
33+ || line. contains ( "warnings emitted" )
34+ || line. contains ( "aborting due to" )
35+ {
3136 // Eat blank line.
3237 match lines. next ( ) {
3338 None | Some ( "" ) => continue ,
@@ -112,3 +117,26 @@ warning: `foo` (lib test) generated 2 warnings (1 duplicate)
112117 . with_stderr ( expected_output)
113118 . run ( ) ;
114119}
120+
121+ #[ cargo_test]
122+ fn deduplicate_errors ( ) {
123+ let p = project ( )
124+ . file (
125+ "src/lib.rs" ,
126+ r#"
127+ this should not compile
128+ "# ,
129+ )
130+ . build ( ) ;
131+ let rustc_message = raw_rustc_output ( & p, "src/lib.rs" , & [ ] ) ;
132+ p. cargo ( "test -j1" )
133+ . with_status ( 101 )
134+ . with_stderr ( & format ! (
135+ "\
136+ [COMPILING] foo v0.0.1 [..]
137+ {}error: could not compile `foo` due to previous error
138+ " ,
139+ rustc_message
140+ ) )
141+ . run ( ) ;
142+ }
0 commit comments