@@ -18,6 +18,7 @@ use header::TestProps;
18
18
use header;
19
19
use procsrv;
20
20
use test:: TestPaths ;
21
+ use uidiff;
21
22
use util:: logv;
22
23
23
24
use std:: env;
@@ -2115,8 +2116,8 @@ actual:\n\
2115
2116
let normalized_stderr = self . normalize_output ( & proc_res. stderr ) ;
2116
2117
2117
2118
let mut errors = 0 ;
2118
- errors += self . compare_output ( "stdout" , normalized_stdout. as_bytes ( ) , & expected_stdout) ;
2119
- errors += self . compare_output ( "stderr" , normalized_stderr. as_bytes ( ) , & expected_stderr) ;
2119
+ errors += self . compare_output ( "stdout" , & normalized_stdout, & expected_stdout) ;
2120
+ errors += self . compare_output ( "stderr" , & normalized_stderr, & expected_stderr) ;
2120
2121
2121
2122
if errors > 0 {
2122
2123
println ! ( "To update references, run this command from build directory:" ) ;
@@ -2127,15 +2128,18 @@ actual:\n\
2127
2128
self . config. src_base. display( ) ,
2128
2129
self . config. build_base. display( ) ,
2129
2130
relative_path_to_file. display( ) ) ;
2130
- self . fatal ( & format ! ( "{} errors occurred comparing output." , errors) ) ;
2131
+ self . fatal_proc_rec ( & format ! ( "{} errors occurred comparing output." , errors) ,
2132
+ & proc_res) ;
2131
2133
}
2132
2134
}
2133
2135
2134
2136
fn normalize_output ( & self , output : & str ) -> String {
2135
2137
let parent_dir = self . testpaths . file . parent ( ) . unwrap ( ) ;
2136
2138
let parent_dir_str = parent_dir. display ( ) . to_string ( ) ;
2137
2139
output. replace ( & parent_dir_str, "$DIR" )
2138
- . replace ( "\\ " , "/" ) // windows, you know.
2140
+ . replace ( "\\ " , "/" ) // normalize for paths on windows
2141
+ . replace ( "\r \n " , "\n " ) // normalize for linebreaks on windows
2142
+ . replace ( "\t " , "\\ t" ) // makes tabs visible
2139
2143
}
2140
2144
2141
2145
fn expected_output_path ( & self , kind : & str ) -> PathBuf {
@@ -2146,31 +2150,34 @@ actual:\n\
2146
2150
self . testpaths . file . with_extension ( extension)
2147
2151
}
2148
2152
2149
- fn load_expected_output ( & self , path : & Path ) -> Vec < u8 > {
2153
+ fn load_expected_output ( & self , path : & Path ) -> String {
2150
2154
if !path. exists ( ) {
2151
- return vec ! [ ] ;
2155
+ return String :: new ( ) ;
2152
2156
}
2153
2157
2154
- let mut result = Vec :: new ( ) ;
2155
- match File :: open ( path) . and_then ( |mut f| f. read_to_end ( & mut result) ) {
2158
+ let mut result = String :: new ( ) ;
2159
+ match File :: open ( path) . and_then ( |mut f| f. read_to_string ( & mut result) ) {
2156
2160
Ok ( _) => result,
2157
2161
Err ( e) => {
2158
2162
self . fatal ( & format ! ( "failed to load expected output from `{}`: {}" , path. display( ) , e) )
2159
2163
}
2160
2164
}
2161
2165
}
2162
2166
2163
- fn compare_output ( & self , kind : & str , actual : & [ u8 ] , expected : & [ u8 ] ) -> usize {
2164
- if self . config . verbose {
2165
- println ! ( "normalized {}:\n {}\n " , kind, str :: from_utf8( actual) . unwrap_or( "not utf8" ) ) ;
2166
- println ! ( "expected {}:\n {}\n " , kind, str :: from_utf8( expected) . unwrap_or( "not utf8" ) ) ;
2167
- }
2167
+ fn compare_output ( & self , kind : & str , actual : & str , expected : & str ) -> usize {
2168
2168
if actual == expected {
2169
2169
return 0 ;
2170
2170
}
2171
2171
2172
+ println ! ( "normalized {}:\n {}\n " , kind, actual) ;
2173
+ println ! ( "expected {}:\n {}\n " , kind, expected) ;
2174
+ println ! ( "diff of {}:\n " , kind) ;
2175
+ for line in uidiff:: diff_lines ( actual, expected) {
2176
+ println ! ( "{}" , line) ;
2177
+ }
2178
+
2172
2179
let output_file = self . output_base_name ( ) . with_extension ( kind) ;
2173
- match File :: create ( & output_file) . and_then ( |mut f| f. write_all ( actual) ) {
2180
+ match File :: create ( & output_file) . and_then ( |mut f| f. write_all ( actual. as_bytes ( ) ) ) {
2174
2181
Ok ( ( ) ) => { }
2175
2182
Err ( e) => {
2176
2183
self . fatal ( & format ! ( "failed to write {} to `{}`: {}" ,
0 commit comments