@@ -1403,6 +1403,11 @@ actual:\n\
1403
1403
rustc. args ( & [ "--error-format" , "json" ] ) ;
1404
1404
}
1405
1405
}
1406
+ Ui => {
1407
+ if !self . props . compile_flags . iter ( ) . any ( |s| s. starts_with ( "--error-format" ) ) {
1408
+ rustc. args ( & [ "--error-format" , "json" ] ) ;
1409
+ }
1410
+ }
1406
1411
MirOpt => {
1407
1412
rustc. args ( & [
1408
1413
"-Zdump-mir=all" ,
@@ -1427,7 +1432,6 @@ actual:\n\
1427
1432
Codegen |
1428
1433
Rustdoc |
1429
1434
RunMake |
1430
- Ui |
1431
1435
CodegenUnits => {
1432
1436
// do not use JSON output
1433
1437
}
@@ -2211,7 +2215,12 @@ actual:\n\
2211
2215
}
2212
2216
2213
2217
fn run_ui_test ( & self ) {
2214
- let proc_res = self . compile_test ( ) ;
2218
+ // if the user specified a format in the ui test
2219
+ // print the output to the stderr file, otherwise extract
2220
+ // the rendered error messages from json and print them
2221
+ let explicit = self . props . compile_flags . iter ( ) . any ( |s| s. starts_with ( "--error-format" ) ) ;
2222
+
2223
+ let mut proc_res = self . compile_test ( ) ;
2215
2224
2216
2225
let expected_stderr_path = self . expected_output_path ( "stderr" ) ;
2217
2226
let expected_stderr = self . load_expected_output ( & expected_stderr_path) ;
@@ -2220,14 +2229,24 @@ actual:\n\
2220
2229
let expected_stdout = self . load_expected_output ( & expected_stdout_path) ;
2221
2230
2222
2231
let normalized_stdout =
2223
- self . normalize_output ( & proc_res. stdout , & self . props . normalize_stdout ) ;
2232
+ self . normalize_output ( & proc_res. stdout , & self . props . normalize_stdout , explicit) ;
2233
+
2234
+ let stderr = if explicit {
2235
+ proc_res. stderr . clone ( )
2236
+ } else {
2237
+ json:: extract_rendered ( & proc_res. stderr , & proc_res)
2238
+ } ;
2239
+
2224
2240
let normalized_stderr =
2225
- self . normalize_output ( & proc_res . stderr , & self . props . normalize_stderr ) ;
2241
+ self . normalize_output ( & stderr, & self . props . normalize_stderr , explicit ) ;
2226
2242
2227
2243
let mut errors = 0 ;
2228
2244
errors += self . compare_output ( "stdout" , & normalized_stdout, & expected_stdout) ;
2229
2245
errors += self . compare_output ( "stderr" , & normalized_stderr, & expected_stderr) ;
2230
2246
2247
+ // rewrite the output to the human readable one (shown in case of errors)
2248
+ proc_res. stderr = normalized_stderr;
2249
+
2231
2250
if errors > 0 {
2232
2251
println ! ( "To update references, run this command from build directory:" ) ;
2233
2252
let relative_path_to_file =
@@ -2421,11 +2440,13 @@ actual:\n\
2421
2440
mir_dump_dir
2422
2441
}
2423
2442
2424
- fn normalize_output ( & self , output : & str , custom_rules : & [ ( String , String ) ] ) -> String {
2443
+ fn normalize_output (
2444
+ & self ,
2445
+ output : & str ,
2446
+ custom_rules : & [ ( String , String ) ] ,
2447
+ json : bool ,
2448
+ ) -> String {
2425
2449
let parent_dir = self . testpaths . file . parent ( ) . unwrap ( ) ;
2426
- let cflags = self . props . compile_flags . join ( " " ) ;
2427
- let json = cflags. contains ( "--error-format json" ) ||
2428
- cflags. contains ( "--error-format pretty-json" ) ;
2429
2450
let parent_dir_str = if json {
2430
2451
parent_dir. display ( ) . to_string ( ) . replace ( "\\ " , "\\ \\ " )
2431
2452
} else {
0 commit comments