@@ -2449,7 +2449,7 @@ impl<'test> TestCx<'test> {
24492449 }
24502450 }
24512451
2452- fn compare_output ( & self , kind : & str , actual : & str , expected : & str ) -> usize {
2452+ fn compare_output ( & self , stream : & str , actual : & str , expected : & str ) -> usize {
24532453 let are_different = match ( self . force_color_svg ( ) , expected. find ( '\n' ) , actual. find ( '\n' ) ) {
24542454 // FIXME: We ignore the first line of SVG files
24552455 // because the width parameter is non-deterministic.
@@ -2489,56 +2489,66 @@ impl<'test> TestCx<'test> {
24892489 ( expected, actual)
24902490 } ;
24912491
2492+ // Write the actual output to a file in build/
2493+ let test_name = self . config . compare_mode . as_ref ( ) . map_or ( "" , |m| m. to_str ( ) ) ;
2494+ let actual_path = self
2495+ . output_base_name ( )
2496+ . with_extra_extension ( self . revision . unwrap_or ( "" ) )
2497+ . with_extra_extension ( test_name)
2498+ . with_extra_extension ( stream) ;
2499+
2500+ if let Err ( err) = fs:: write ( & actual_path, & actual) {
2501+ self . fatal ( & format ! ( "failed to write {stream} to `{actual_path:?}`: {err}" , ) ) ;
2502+ }
2503+ println ! ( "Saved the actual {stream} to {actual_path:?}" ) ;
2504+
2505+ let expected_path =
2506+ expected_output_path ( self . testpaths , self . revision , & self . config . compare_mode , stream) ;
2507+
24922508 if !self . config . bless {
24932509 if expected. is_empty ( ) {
2494- println ! ( "normalized {}:\n {}\n " , kind , actual) ;
2510+ println ! ( "normalized {}:\n {}\n " , stream , actual) ;
24952511 } else {
2496- println ! ( "diff of {}:\n " , kind) ;
2497- print ! ( "{}" , write_diff( expected, actual, 3 ) ) ;
2512+ println ! ( "diff of {stream}:\n " ) ;
2513+ if let Some ( diff_command) = self . config . diff_command . as_deref ( ) {
2514+ let mut args = diff_command. split_whitespace ( ) ;
2515+ let name = args. next ( ) . unwrap ( ) ;
2516+ match Command :: new ( name)
2517+ . args ( args)
2518+ . args ( [ & expected_path, & actual_path] )
2519+ . output ( )
2520+ {
2521+ Err ( err) => {
2522+ self . fatal ( & format ! (
2523+ "failed to call custom diff command `{diff_command}`: {err}"
2524+ ) ) ;
2525+ }
2526+ Ok ( output) => {
2527+ let output = String :: from_utf8_lossy ( & output. stdout ) ;
2528+ print ! ( "{output}" ) ;
2529+ }
2530+ }
2531+ } else {
2532+ print ! ( "{}" , write_diff( expected, actual, 3 ) ) ;
2533+ }
24982534 }
2499- }
2500-
2501- let mode = self . config . compare_mode . as_ref ( ) . map_or ( "" , |m| m. to_str ( ) ) ;
2502- let output_file = self
2503- . output_base_name ( )
2504- . with_extra_extension ( self . revision . unwrap_or ( "" ) )
2505- . with_extra_extension ( mode)
2506- . with_extra_extension ( kind) ;
2507-
2508- let mut files = vec ! [ output_file] ;
2509- if self . config . bless {
2535+ } else {
25102536 // Delete non-revision .stderr/.stdout file if revisions are used.
25112537 // Without this, we'd just generate the new files and leave the old files around.
25122538 if self . revision . is_some ( ) {
25132539 let old =
2514- expected_output_path ( self . testpaths , None , & self . config . compare_mode , kind ) ;
2540+ expected_output_path ( self . testpaths , None , & self . config . compare_mode , stream ) ;
25152541 self . delete_file ( & old) ;
25162542 }
2517- files. push ( expected_output_path (
2518- self . testpaths ,
2519- self . revision ,
2520- & self . config . compare_mode ,
2521- kind,
2522- ) ) ;
2523- }
25242543
2525- for output_file in & files {
2526- if actual. is_empty ( ) {
2527- self . delete_file ( output_file) ;
2528- } else if let Err ( err) = fs:: write ( & output_file, & actual) {
2529- self . fatal ( & format ! (
2530- "failed to write {} to `{}`: {}" ,
2531- kind,
2532- output_file. display( ) ,
2533- err,
2534- ) ) ;
2544+ if let Err ( err) = fs:: write ( & expected_path, & actual) {
2545+ self . fatal ( & format ! ( "failed to write {stream} to `{expected_path:?}`: {err}" ) ) ;
25352546 }
2547+ println ! ( "Blessing the {stream} of {test_name} in {expected_path:?}" ) ;
25362548 }
25372549
2538- println ! ( "\n The actual {0} differed from the expected {0}." , kind) ;
2539- for output_file in files {
2540- println ! ( "Actual {} saved to {}" , kind, output_file. display( ) ) ;
2541- }
2550+ println ! ( "\n The actual {0} differed from the expected {0}." , stream) ;
2551+
25422552 if self . config . bless { 0 } else { 1 }
25432553 }
25442554
0 commit comments