@@ -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,47 @@ 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
2356
+ . compare_output ( stderr_kind, & normalized_stderr, & stderr, & expected_stderr)
2357
+ . should_error ( )
2358
+ {
2359
+ errors += 1 ;
2335
2360
}
2336
2361
}
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
2362
}
2348
2363
errors
2349
2364
}
@@ -2576,15 +2591,22 @@ impl<'test> TestCx<'test> {
2576
2591
actual : & str ,
2577
2592
actual_unnormalized : & str ,
2578
2593
expected : & str ,
2579
- ) -> usize {
2594
+ ) -> CompareOutcome {
2595
+ let expected_path =
2596
+ expected_output_path ( self . testpaths , self . revision , & self . config . compare_mode , stream) ;
2597
+
2598
+ if self . config . bless && actual. is_empty ( ) && expected_path. exists ( ) {
2599
+ self . delete_file ( & expected_path) ;
2600
+ }
2601
+
2580
2602
let are_different = match ( self . force_color_svg ( ) , expected. find ( '\n' ) , actual. find ( '\n' ) ) {
2581
2603
// FIXME: We ignore the first line of SVG files
2582
2604
// because the width parameter is non-deterministic.
2583
2605
( true , Some ( nl_e) , Some ( nl_a) ) => expected[ nl_e..] != actual[ nl_a..] ,
2584
2606
_ => expected != actual,
2585
2607
} ;
2586
2608
if !are_different {
2587
- return 0 ;
2609
+ return CompareOutcome :: Same ;
2588
2610
}
2589
2611
2590
2612
// Wrapper tools set by `runner` might provide extra output on failure,
@@ -2600,7 +2622,7 @@ impl<'test> TestCx<'test> {
2600
2622
used. retain ( |line| actual_lines. contains ( line) ) ;
2601
2623
// check if `expected` contains a subset of the lines of `actual`
2602
2624
if used. len ( ) == expected_lines. len ( ) && ( expected. is_empty ( ) == actual. is_empty ( ) ) {
2603
- return 0 ;
2625
+ return CompareOutcome :: Same ;
2604
2626
}
2605
2627
if expected_lines. is_empty ( ) {
2606
2628
// if we have no lines to check, force a full overwite
@@ -2626,9 +2648,6 @@ impl<'test> TestCx<'test> {
2626
2648
}
2627
2649
println ! ( "Saved the actual {stream} to {actual_path:?}" ) ;
2628
2650
2629
- let expected_path =
2630
- expected_output_path ( self . testpaths , self . revision , & self . config . compare_mode , stream) ;
2631
-
2632
2651
if !self . config . bless {
2633
2652
if expected. is_empty ( ) {
2634
2653
println ! ( "normalized {}:\n {}\n " , stream, actual) ;
@@ -2651,15 +2670,17 @@ impl<'test> TestCx<'test> {
2651
2670
self . delete_file ( & old) ;
2652
2671
}
2653
2672
2654
- if let Err ( err) = fs:: write ( & expected_path, & actual) {
2655
- self . fatal ( & format ! ( "failed to write {stream} to `{expected_path:?}`: {err}" ) ) ;
2673
+ if !actual. is_empty ( ) {
2674
+ if let Err ( err) = fs:: write ( & expected_path, & actual) {
2675
+ self . fatal ( & format ! ( "failed to write {stream} to `{expected_path:?}`: {err}" ) ) ;
2676
+ }
2677
+ println ! ( "Blessing the {stream} of {test_name} in {expected_path:?}" ) ;
2656
2678
}
2657
- println ! ( "Blessing the {stream} of {test_name} in {expected_path:?}" ) ;
2658
2679
}
2659
2680
2660
2681
println ! ( "\n The actual {0} differed from the expected {0}." , stream) ;
2661
2682
2662
- if self . config . bless { 0 } else { 1 }
2683
+ if self . config . bless { CompareOutcome :: Blessed } else { CompareOutcome :: Differed }
2663
2684
}
2664
2685
2665
2686
/// Returns whether to show the full stderr/stdout.
@@ -2885,3 +2906,21 @@ enum AuxType {
2885
2906
Dylib ,
2886
2907
ProcMacro ,
2887
2908
}
2909
+
2910
+ /// Outcome of comparing a stream to a blessed file,
2911
+ /// e.g. `.stderr` and `.fixed`.
2912
+ #[ derive( Copy , Clone , Debug , PartialEq , Eq ) ]
2913
+ enum CompareOutcome {
2914
+ /// Expected and actual outputs are the same
2915
+ Same ,
2916
+ /// Outputs differed but were blessed
2917
+ Blessed ,
2918
+ /// Outputs differed and an error should be emitted
2919
+ Differed ,
2920
+ }
2921
+
2922
+ impl CompareOutcome {
2923
+ fn should_error ( & self ) -> bool {
2924
+ matches ! ( self , CompareOutcome :: Differed )
2925
+ }
2926
+ }
0 commit comments