@@ -2318,32 +2318,44 @@ impl<'test> TestCx<'test> {
2318
2318
match output_kind {
2319
2319
TestOutput :: Compile => {
2320
2320
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 (
2322
2345
stdout_kind,
2323
2346
& normalized_stdout,
2324
2347
& proc_res. stdout ,
2325
2348
& expected_stdout,
2326
- ) ;
2349
+ )
2350
+ . should_error ( )
2351
+ {
2352
+ errors += 1 ;
2327
2353
}
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 ;
2335
2357
}
2336
2358
}
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
- }
2347
2359
}
2348
2360
errors
2349
2361
}
@@ -2570,21 +2582,22 @@ impl<'test> TestCx<'test> {
2570
2582
}
2571
2583
}
2572
2584
2585
+ // Returns `true` if output differed and was not blessed
2573
2586
fn compare_output (
2574
2587
& self ,
2575
2588
stream : & str ,
2576
2589
actual : & str ,
2577
2590
actual_unnormalized : & str ,
2578
2591
expected : & str ,
2579
- ) -> usize {
2592
+ ) -> bool {
2580
2593
let are_different = match ( self . force_color_svg ( ) , expected. find ( '\n' ) , actual. find ( '\n' ) ) {
2581
2594
// FIXME: We ignore the first line of SVG files
2582
2595
// because the width parameter is non-deterministic.
2583
2596
( true , Some ( nl_e) , Some ( nl_a) ) => expected[ nl_e..] != actual[ nl_a..] ,
2584
2597
_ => expected != actual,
2585
2598
} ;
2586
2599
if !are_different {
2587
- return 0 ;
2600
+ return CompareOutcome :: Same ;
2588
2601
}
2589
2602
2590
2603
// Wrapper tools set by `runner` might provide extra output on failure,
@@ -2600,7 +2613,7 @@ impl<'test> TestCx<'test> {
2600
2613
used. retain ( |line| actual_lines. contains ( line) ) ;
2601
2614
// check if `expected` contains a subset of the lines of `actual`
2602
2615
if used. len ( ) == expected_lines. len ( ) && ( expected. is_empty ( ) == actual. is_empty ( ) ) {
2603
- return 0 ;
2616
+ return CompareOutcome :: Same ;
2604
2617
}
2605
2618
if expected_lines. is_empty ( ) {
2606
2619
// if we have no lines to check, force a full overwite
@@ -2659,7 +2672,7 @@ impl<'test> TestCx<'test> {
2659
2672
2660
2673
println ! ( "\n The actual {0} differed from the expected {0}." , stream) ;
2661
2674
2662
- if self . config . bless { 0 } else { 1 }
2675
+ if self . config . bless { CompareOutcome :: Blessed } else { CompareOutcome :: Differed }
2663
2676
}
2664
2677
2665
2678
/// Returns whether to show the full stderr/stdout.
@@ -2885,3 +2898,21 @@ enum AuxType {
2885
2898
Dylib ,
2886
2899
ProcMacro ,
2887
2900
}
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