9
9
// except according to those terms.
10
10
11
11
use common:: CompareMode ;
12
- use common:: { expected_output_path, UI_FIXED , UI_STDERR , UI_STDOUT } ;
12
+ use common:: { expected_output_path, UI_EXTENSIONS , UI_FIXED , UI_STDERR , UI_STDOUT } ;
13
13
use common:: { output_base_dir, output_base_name, output_testname_unique} ;
14
14
use common:: { Codegen , CodegenUnits , DebugInfoGdb , DebugInfoLldb , Rustdoc } ;
15
15
use common:: { CompileFail , ParseFail , Pretty , RunFail , RunPass , RunPassValgrind } ;
@@ -2609,6 +2609,9 @@ impl<'test> TestCx<'test> {
2609
2609
errors += self . compare_output ( "stdout" , & normalized_stdout, & expected_stdout) ;
2610
2610
errors += self . compare_output ( "stderr" , & normalized_stderr, & expected_stderr) ;
2611
2611
2612
+ let modes_to_prune = vec ! [ CompareMode :: Nll ] ;
2613
+ self . prune_duplicate_outputs ( & modes_to_prune) ;
2614
+
2612
2615
if self . config . compare_mode . is_some ( ) {
2613
2616
// don't test rustfix with nll right now
2614
2617
} else if self . props . run_rustfix {
@@ -2971,6 +2974,16 @@ impl<'test> TestCx<'test> {
2971
2974
}
2972
2975
}
2973
2976
2977
+ fn delete_file ( & self , file : & PathBuf ) {
2978
+ if let Err ( e) = :: std:: fs:: remove_file ( file) {
2979
+ self . fatal ( & format ! (
2980
+ "failed to delete `{}`: {}" ,
2981
+ file. display( ) ,
2982
+ e,
2983
+ ) ) ;
2984
+ }
2985
+ }
2986
+
2974
2987
fn compare_output ( & self , kind : & str , actual : & str , expected : & str ) -> usize {
2975
2988
if actual == expected {
2976
2989
return 0 ;
@@ -3023,13 +3036,7 @@ impl<'test> TestCx<'test> {
3023
3036
3024
3037
for output_file in & files {
3025
3038
if actual. is_empty ( ) {
3026
- if let Err ( e) = :: std:: fs:: remove_file ( output_file) {
3027
- self . fatal ( & format ! (
3028
- "failed to delete `{}`: {}" ,
3029
- output_file. display( ) ,
3030
- e,
3031
- ) ) ;
3032
- }
3039
+ self . delete_file ( output_file) ;
3033
3040
} else {
3034
3041
match File :: create ( & output_file) . and_then ( |mut f| f. write_all ( actual. as_bytes ( ) ) ) {
3035
3042
Ok ( ( ) ) => { }
@@ -3054,6 +3061,42 @@ impl<'test> TestCx<'test> {
3054
3061
}
3055
3062
}
3056
3063
3064
+ fn prune_duplicate_output ( & self , mode : CompareMode , kind : & str , canon_content : & str ) {
3065
+ let examined_path = expected_output_path (
3066
+ & self . testpaths ,
3067
+ self . revision ,
3068
+ & Some ( mode) ,
3069
+ kind,
3070
+ ) ;
3071
+
3072
+ let examined_content = self
3073
+ . load_expected_output_from_path ( & examined_path)
3074
+ . unwrap_or_else ( |_| String :: new ( ) ) ;
3075
+
3076
+ if examined_path. exists ( ) && canon_content == & examined_content {
3077
+ self . delete_file ( & examined_path) ;
3078
+ }
3079
+ }
3080
+
3081
+ fn prune_duplicate_outputs ( & self , modes : & [ CompareMode ] ) {
3082
+ if self . config . bless {
3083
+ for kind in UI_EXTENSIONS {
3084
+ let canon_comparison_path = expected_output_path (
3085
+ & self . testpaths ,
3086
+ self . revision ,
3087
+ & None ,
3088
+ kind,
3089
+ ) ;
3090
+
3091
+ if let Ok ( canon) = self . load_expected_output_from_path ( & canon_comparison_path) {
3092
+ for mode in modes {
3093
+ self . prune_duplicate_output ( mode. clone ( ) , kind, & canon) ;
3094
+ }
3095
+ }
3096
+ }
3097
+ }
3098
+ }
3099
+
3057
3100
fn create_stamp ( & self ) {
3058
3101
let mut f = File :: create ( :: stamp ( & self . config , self . testpaths , self . revision ) ) . unwrap ( ) ;
3059
3102
f. write_all ( compute_stamp_hash ( & self . config ) . as_bytes ( ) )
0 commit comments