@@ -3112,7 +3112,7 @@ impl<'test> TestCx<'test> {
31123112 let expected_fixed = self . load_expected_output ( UI_FIXED ) ;
31133113
31143114 let modes_to_prune = vec ! [ CompareMode :: Nll ] ;
3115- self . prune_duplicate_outputs ( & modes_to_prune) ;
3115+ self . check_and_prune_duplicate_outputs ( & proc_res , & [ ] , & modes_to_prune) ;
31163116
31173117 let mut errors = self . load_compare_outputs ( & proc_res, TestOutput :: Compile , explicit) ;
31183118 let rustfix_input = json:: rustfix_diagnostics_only ( & proc_res. stderr ) ;
@@ -3730,28 +3730,54 @@ impl<'test> TestCx<'test> {
37303730 if self . config . bless { 0 } else { 1 }
37313731 }
37323732
3733- fn prune_duplicate_output ( & self , mode : CompareMode , kind : & str , canon_content : & str ) {
3734- let examined_path = expected_output_path ( & self . testpaths , self . revision , & Some ( mode) , kind) ;
3735-
3736- let examined_content =
3737- self . load_expected_output_from_path ( & examined_path) . unwrap_or_else ( |_| String :: new ( ) ) ;
3733+ fn check_and_prune_duplicate_outputs (
3734+ & self ,
3735+ proc_res : & ProcRes ,
3736+ modes : & [ CompareMode ] ,
3737+ require_same_modes : & [ CompareMode ] ,
3738+ ) {
3739+ for kind in UI_EXTENSIONS {
3740+ let canon_comparison_path =
3741+ expected_output_path ( & self . testpaths , self . revision , & None , kind) ;
37383742
3739- if canon_content == examined_content {
3740- self . delete_file ( & examined_path) ;
3741- }
3742- }
3743+ let canon = match self . load_expected_output_from_path ( & canon_comparison_path) {
3744+ Ok ( canon) => canon,
3745+ _ => continue ,
3746+ } ;
3747+ let bless = self . config . bless ;
3748+ let check_and_prune_duplicate_outputs = |mode : & CompareMode , require_same : bool | {
3749+ let examined_path =
3750+ expected_output_path ( & self . testpaths , self . revision , & Some ( mode. clone ( ) ) , kind) ;
3751+
3752+ // If there is no output, there is nothing to do
3753+ let examined_content = match self . load_expected_output_from_path ( & examined_path) {
3754+ Ok ( content) => content,
3755+ _ => return ,
3756+ } ;
37433757
3744- fn prune_duplicate_outputs ( & self , modes : & [ CompareMode ] ) {
3745- if self . config . bless {
3746- for kind in UI_EXTENSIONS {
3747- let canon_comparison_path =
3748- expected_output_path ( & self . testpaths , self . revision , & None , kind) ;
3758+ let is_duplicate = canon == examined_content;
37493759
3750- if let Ok ( canon) = self . load_expected_output_from_path ( & canon_comparison_path) {
3751- for mode in modes {
3752- self . prune_duplicate_output ( mode. clone ( ) , kind, & canon) ;
3760+ match ( bless, require_same, is_duplicate) {
3761+ // If we're blessing and the output is the same, then delete the file.
3762+ ( true , _, true ) => {
3763+ self . delete_file ( & examined_path) ;
37533764 }
3765+ // If we want them to be the same, but they are different, then error.
3766+ // We do this wether we bless or not
3767+ ( _, true , false ) => {
3768+ self . fatal_proc_rec (
3769+ & format ! ( "`{}` should not have different output from base test!" , kind) ,
3770+ proc_res,
3771+ ) ;
3772+ }
3773+ _ => { }
37543774 }
3775+ } ;
3776+ for mode in modes {
3777+ check_and_prune_duplicate_outputs ( mode, false ) ;
3778+ }
3779+ for mode in require_same_modes {
3780+ check_and_prune_duplicate_outputs ( mode, true ) ;
37553781 }
37563782 }
37573783 }
0 commit comments