@@ -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,22 @@ 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+ ) -> bool {
25802593 let are_different = match ( self . force_color_svg ( ) , expected. find ( '\n' ) , actual. find ( '\n' ) ) {
25812594 // FIXME: We ignore the first line of SVG files
25822595 // because the width parameter is non-deterministic.
25832596 ( true , Some ( nl_e) , Some ( nl_a) ) => expected[ nl_e..] != actual[ nl_a..] ,
25842597 _ => expected != actual,
25852598 } ;
25862599 if !are_different {
2587- return 0 ;
2600+ return CompareOutcome :: Same ;
25882601 }
25892602
25902603 // Wrapper tools set by `runner` might provide extra output on failure,
@@ -2600,7 +2613,7 @@ impl<'test> TestCx<'test> {
26002613 used. retain ( |line| actual_lines. contains ( line) ) ;
26012614 // check if `expected` contains a subset of the lines of `actual`
26022615 if used. len ( ) == expected_lines. len ( ) && ( expected. is_empty ( ) == actual. is_empty ( ) ) {
2603- return 0 ;
2616+ return CompareOutcome :: Same ;
26042617 }
26052618 if expected_lines. is_empty ( ) {
26062619 // if we have no lines to check, force a full overwite
@@ -2659,7 +2672,7 @@ impl<'test> TestCx<'test> {
26592672
26602673 println ! ( "\n The actual {0} differed from the expected {0}." , stream) ;
26612674
2662- if self . config . bless { 0 } else { 1 }
2675+ if self . config . bless { CompareOutcome :: Blessed } else { CompareOutcome :: Differed }
26632676 }
26642677
26652678 /// Returns whether to show the full stderr/stdout.
@@ -2885,3 +2898,21 @@ enum AuxType {
28852898 Dylib ,
28862899 ProcMacro ,
28872900}
2901+
2902+ /// Outcome of comparing a stream to a blessed file,
2903+ /// e.g. `.stderr` and `.fixed`.
2904+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
2905+ enum CompareOutcome {
2906+ /// Expected and actual outputs are the same
2907+ Same ,
2908+ /// Outputs differed but were blessed
2909+ Blessed ,
2910+ /// Outputs differed and an error should be emitted
2911+ Differed ,
2912+ }
2913+
2914+ impl CompareOutcome {
2915+ fn should_error ( & self ) -> bool {
2916+ matches ! ( self , CompareOutcome :: Differed )
2917+ }
2918+ }
0 commit comments