@@ -213,7 +213,7 @@ fn remove_and_create_dir_all(path: &Path) {
213
213
fs:: create_dir_all ( path) . unwrap ( ) ;
214
214
}
215
215
216
- #[ derive( Copy , Clone ) ]
216
+ #[ derive( Copy , Clone , Debug ) ]
217
217
struct TestCx < ' test > {
218
218
config : & ' test Config ,
219
219
props : & ' test TestProps ,
@@ -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,29 @@ 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
+ ) -> 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
+
2580
2600
let are_different = match ( self . force_color_svg ( ) , expected. find ( '\n' ) , actual. find ( '\n' ) ) {
2581
2601
// FIXME: We ignore the first line of SVG files
2582
2602
// because the width parameter is non-deterministic.
2583
2603
( true , Some ( nl_e) , Some ( nl_a) ) => expected[ nl_e..] != actual[ nl_a..] ,
2584
2604
_ => expected != actual,
2585
2605
} ;
2586
2606
if !are_different {
2587
- return 0 ;
2607
+ return CompareOutcome :: Same ;
2588
2608
}
2589
2609
2590
2610
// Wrapper tools set by `runner` might provide extra output on failure,
@@ -2600,7 +2620,7 @@ impl<'test> TestCx<'test> {
2600
2620
used. retain ( |line| actual_lines. contains ( line) ) ;
2601
2621
// check if `expected` contains a subset of the lines of `actual`
2602
2622
if used. len ( ) == expected_lines. len ( ) && ( expected. is_empty ( ) == actual. is_empty ( ) ) {
2603
- return 0 ;
2623
+ return CompareOutcome :: Same ;
2604
2624
}
2605
2625
if expected_lines. is_empty ( ) {
2606
2626
// if we have no lines to check, force a full overwite
@@ -2626,9 +2646,6 @@ impl<'test> TestCx<'test> {
2626
2646
}
2627
2647
println ! ( "Saved the actual {stream} to {actual_path:?}" ) ;
2628
2648
2629
- let expected_path =
2630
- expected_output_path ( self . testpaths , self . revision , & self . config . compare_mode , stream) ;
2631
-
2632
2649
if !self . config . bless {
2633
2650
if expected. is_empty ( ) {
2634
2651
println ! ( "normalized {}:\n {}\n " , stream, actual) ;
@@ -2651,15 +2668,17 @@ impl<'test> TestCx<'test> {
2651
2668
self . delete_file ( & old) ;
2652
2669
}
2653
2670
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:?}" ) ;
2656
2676
}
2657
- println ! ( "Blessing the {stream} of {test_name} in {expected_path:?}" ) ;
2658
2677
}
2659
2678
2660
2679
println ! ( "\n The actual {0} differed from the expected {0}." , stream) ;
2661
2680
2662
- if self . config . bless { 0 } else { 1 }
2681
+ if self . config . bless { CompareOutcome :: Blessed } else { CompareOutcome :: Differed }
2663
2682
}
2664
2683
2665
2684
/// Returns whether to show the full stderr/stdout.
@@ -2885,3 +2904,21 @@ enum AuxType {
2885
2904
Dylib ,
2886
2905
ProcMacro ,
2887
2906
}
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