@@ -2480,7 +2480,7 @@ impl<'test> TestCx<'test> {
2480
2480
}
2481
2481
}
2482
2482
2483
- fn compare_output ( & self , kind : & str , actual : & str , expected : & str ) -> usize {
2483
+ fn compare_output ( & self , stream : & str , actual : & str , expected : & str ) -> usize {
2484
2484
let are_different = match ( self . force_color_svg ( ) , expected. find ( '\n' ) , actual. find ( '\n' ) ) {
2485
2485
// FIXME: We ignore the first line of SVG files
2486
2486
// because the width parameter is non-deterministic.
@@ -2520,56 +2520,66 @@ impl<'test> TestCx<'test> {
2520
2520
( expected, actual)
2521
2521
} ;
2522
2522
2523
+ // Write the actual output to a file in build/
2524
+ let test_name = self . config . compare_mode . as_ref ( ) . map_or ( "" , |m| m. to_str ( ) ) ;
2525
+ let actual_path = self
2526
+ . output_base_name ( )
2527
+ . with_extra_extension ( self . revision . unwrap_or ( "" ) )
2528
+ . with_extra_extension ( test_name)
2529
+ . with_extra_extension ( stream) ;
2530
+
2531
+ if let Err ( err) = fs:: write ( & actual_path, & actual) {
2532
+ self . fatal ( & format ! ( "failed to write {stream} to `{actual_path:?}`: {err}" , ) ) ;
2533
+ }
2534
+ println ! ( "Saved the actual {stream} to {actual_path:?}" ) ;
2535
+
2536
+ let expected_path =
2537
+ expected_output_path ( self . testpaths , self . revision , & self . config . compare_mode , stream) ;
2538
+
2523
2539
if !self . config . bless {
2524
2540
if expected. is_empty ( ) {
2525
- println ! ( "normalized {}:\n {}\n " , kind , actual) ;
2541
+ println ! ( "normalized {}:\n {}\n " , stream , actual) ;
2526
2542
} else {
2527
- println ! ( "diff of {}:\n " , kind) ;
2528
- print ! ( "{}" , write_diff( expected, actual, 3 ) ) ;
2543
+ println ! ( "diff of {stream}:\n " ) ;
2544
+ if let Some ( diff_command) = self . config . diff_command . as_deref ( ) {
2545
+ let mut args = diff_command. split_whitespace ( ) ;
2546
+ let name = args. next ( ) . unwrap ( ) ;
2547
+ match Command :: new ( name)
2548
+ . args ( args)
2549
+ . args ( [ & expected_path, & actual_path] )
2550
+ . output ( )
2551
+ {
2552
+ Err ( err) => {
2553
+ self . fatal ( & format ! (
2554
+ "failed to call custom diff command `{diff_command}`: {err}"
2555
+ ) ) ;
2556
+ }
2557
+ Ok ( output) => {
2558
+ let output = String :: from_utf8_lossy_owned ( output. stdout ) . unwrap ( ) ;
2559
+ print ! ( "{output}" ) ;
2560
+ }
2561
+ }
2562
+ } else {
2563
+ print ! ( "{}" , write_diff( expected, actual, 3 ) ) ;
2564
+ }
2529
2565
}
2530
- }
2531
-
2532
- let mode = self . config . compare_mode . as_ref ( ) . map_or ( "" , |m| m. to_str ( ) ) ;
2533
- let output_file = self
2534
- . output_base_name ( )
2535
- . with_extra_extension ( self . revision . unwrap_or ( "" ) )
2536
- . with_extra_extension ( mode)
2537
- . with_extra_extension ( kind) ;
2538
-
2539
- let mut files = vec ! [ output_file] ;
2540
- if self . config . bless {
2566
+ } else {
2541
2567
// Delete non-revision .stderr/.stdout file if revisions are used.
2542
2568
// Without this, we'd just generate the new files and leave the old files around.
2543
2569
if self . revision . is_some ( ) {
2544
2570
let old =
2545
- expected_output_path ( self . testpaths , None , & self . config . compare_mode , kind ) ;
2571
+ expected_output_path ( self . testpaths , None , & self . config . compare_mode , stream ) ;
2546
2572
self . delete_file ( & old) ;
2547
2573
}
2548
- files. push ( expected_output_path (
2549
- self . testpaths ,
2550
- self . revision ,
2551
- & self . config . compare_mode ,
2552
- kind,
2553
- ) ) ;
2554
- }
2555
2574
2556
- for output_file in & files {
2557
- if actual. is_empty ( ) {
2558
- self . delete_file ( output_file) ;
2559
- } else if let Err ( err) = fs:: write ( & output_file, & actual) {
2560
- self . fatal ( & format ! (
2561
- "failed to write {} to `{}`: {}" ,
2562
- kind,
2563
- output_file. display( ) ,
2564
- err,
2565
- ) ) ;
2575
+ if let Err ( err) = fs:: write ( & expected_path, & actual) {
2576
+ self . fatal ( & format ! ( "failed to write {stream} to `{expected_path:?}`: {err}" ) ) ;
2566
2577
}
2578
+ println ! ( "Blessing the {stream} of {test_name} in {expected_path:?}" ) ;
2567
2579
}
2568
2580
2569
- println ! ( "\n The actual {0} differed from the expected {0}." , kind) ;
2570
- for output_file in files {
2571
- println ! ( "Actual {} saved to {}" , kind, output_file. display( ) ) ;
2572
- }
2581
+ println ! ( "\n The actual {0} differed from the expected {0}." , stream) ;
2582
+
2573
2583
if self . config . bless { 0 } else { 1 }
2574
2584
}
2575
2585
0 commit comments