@@ -213,7 +213,7 @@ fn remove_and_create_dir_all(path: &Path) {
213213 fs:: create_dir_all ( path) . unwrap ( ) ;
214214}
215215
216- #[ derive( Copy , Clone ) ]
216+ #[ derive( Copy , Clone , Debug ) ]
217217struct TestCx < ' test > {
218218 config : & ' test Config ,
219219 props : & ' test TestProps ,
@@ -2318,32 +2318,44 @@ impl<'test> TestCx<'test> {
23182318 match output_kind {
23192319 TestOutput :: Compile => {
23202320 if !self . props . dont_check_compiler_stdout {
2321- errors += self . compare_output (
2321+ if self
2322+ . compare_output (
2323+ stdout_kind,
2324+ & normalized_stdout,
2325+ & proc_res. stdout ,
2326+ & expected_stdout,
2327+ )
2328+ . should_error ( )
2329+ {
2330+ errors += 1 ;
2331+ }
2332+ }
2333+ if !self . props . dont_check_compiler_stderr {
2334+ if self
2335+ . compare_output ( stderr_kind, & normalized_stderr, & stderr, & expected_stderr)
2336+ . should_error ( )
2337+ {
2338+ errors += 1 ;
2339+ }
2340+ }
2341+ }
2342+ TestOutput :: Run => {
2343+ if self
2344+ . compare_output (
23222345 stdout_kind,
23232346 & normalized_stdout,
23242347 & proc_res. stdout ,
23252348 & expected_stdout,
2326- ) ;
2349+ )
2350+ . should_error ( )
2351+ {
2352+ errors += 1 ;
23272353 }
2328- if !self . props . dont_check_compiler_stderr {
2329- errors += self . compare_output (
2330- stderr_kind,
2331- & normalized_stderr,
2332- & stderr,
2333- & expected_stderr,
2334- ) ;
2354+
2355+ if self . compare_output ( stderr_kind, & normalized_stderr, & stderr, & expected_stderr) {
2356+ errors += 1 ;
23352357 }
23362358 }
2337- TestOutput :: Run => {
2338- errors += self . compare_output (
2339- stdout_kind,
2340- & normalized_stdout,
2341- & proc_res. stdout ,
2342- & expected_stdout,
2343- ) ;
2344- errors +=
2345- self . compare_output ( stderr_kind, & normalized_stderr, & stderr, & expected_stderr) ;
2346- }
23472359 }
23482360 errors
23492361 }
@@ -2570,21 +2582,29 @@ impl<'test> TestCx<'test> {
25702582 }
25712583 }
25722584
2585+ // Returns `true` if output differed and was not blessed
25732586 fn compare_output (
25742587 & self ,
25752588 stream : & str ,
25762589 actual : & str ,
25772590 actual_unnormalized : & str ,
25782591 expected : & str ,
2579- ) -> usize {
2592+ ) -> CompareOutcome {
2593+ let expected_path =
2594+ expected_output_path ( self . testpaths , self . revision , & self . config . compare_mode , stream) ;
2595+
2596+ if self . config . bless && actual. is_empty ( ) && expected_path. exists ( ) {
2597+ self . delete_file ( & expected_path) ;
2598+ }
2599+
25802600 let are_different = match ( self . force_color_svg ( ) , expected. find ( '\n' ) , actual. find ( '\n' ) ) {
25812601 // FIXME: We ignore the first line of SVG files
25822602 // because the width parameter is non-deterministic.
25832603 ( true , Some ( nl_e) , Some ( nl_a) ) => expected[ nl_e..] != actual[ nl_a..] ,
25842604 _ => expected != actual,
25852605 } ;
25862606 if !are_different {
2587- return 0 ;
2607+ return CompareOutcome :: Same ;
25882608 }
25892609
25902610 // Wrapper tools set by `runner` might provide extra output on failure,
@@ -2600,7 +2620,7 @@ impl<'test> TestCx<'test> {
26002620 used. retain ( |line| actual_lines. contains ( line) ) ;
26012621 // check if `expected` contains a subset of the lines of `actual`
26022622 if used. len ( ) == expected_lines. len ( ) && ( expected. is_empty ( ) == actual. is_empty ( ) ) {
2603- return 0 ;
2623+ return CompareOutcome :: Same ;
26042624 }
26052625 if expected_lines. is_empty ( ) {
26062626 // if we have no lines to check, force a full overwite
@@ -2626,9 +2646,6 @@ impl<'test> TestCx<'test> {
26262646 }
26272647 println ! ( "Saved the actual {stream} to {actual_path:?}" ) ;
26282648
2629- let expected_path =
2630- expected_output_path ( self . testpaths , self . revision , & self . config . compare_mode , stream) ;
2631-
26322649 if !self . config . bless {
26332650 if expected. is_empty ( ) {
26342651 println ! ( "normalized {}:\n {}\n " , stream, actual) ;
@@ -2651,15 +2668,17 @@ impl<'test> TestCx<'test> {
26512668 self . delete_file ( & old) ;
26522669 }
26532670
2654- if let Err ( err) = fs:: write ( & expected_path, & actual) {
2655- self . fatal ( & format ! ( "failed to write {stream} to `{expected_path:?}`: {err}" ) ) ;
2671+ if !actual. is_empty ( ) {
2672+ if let Err ( err) = fs:: write ( & expected_path, & actual) {
2673+ self . fatal ( & format ! ( "failed to write {stream} to `{expected_path:?}`: {err}" ) ) ;
2674+ }
2675+ println ! ( "Blessing the {stream} of {test_name} in {expected_path:?}" ) ;
26562676 }
2657- println ! ( "Blessing the {stream} of {test_name} in {expected_path:?}" ) ;
26582677 }
26592678
26602679 println ! ( "\n The actual {0} differed from the expected {0}." , stream) ;
26612680
2662- if self . config . bless { 0 } else { 1 }
2681+ if self . config . bless { CompareOutcome :: Blessed } else { CompareOutcome :: Differed }
26632682 }
26642683
26652684 /// Returns whether to show the full stderr/stdout.
@@ -2885,3 +2904,21 @@ enum AuxType {
28852904 Dylib ,
28862905 ProcMacro ,
28872906}
2907+
2908+ /// Outcome of comparing a stream to a blessed file,
2909+ /// e.g. `.stderr` and `.fixed`.
2910+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
2911+ enum CompareOutcome {
2912+ /// Expected and actual outputs are the same
2913+ Same ,
2914+ /// Outputs differed but were blessed
2915+ Blessed ,
2916+ /// Outputs differed and an error should be emitted
2917+ Differed ,
2918+ }
2919+
2920+ impl CompareOutcome {
2921+ fn should_error ( & self ) -> bool {
2922+ matches ! ( self , CompareOutcome :: Differed )
2923+ }
2924+ }
0 commit comments