@@ -1403,6 +1403,11 @@ actual:\n\
14031403 rustc. args ( & [ "--error-format" , "json" ] ) ;
14041404 }
14051405 }
1406+ Ui => {
1407+ if !self . props . compile_flags . iter ( ) . any ( |s| s. starts_with ( "--error-format" ) ) {
1408+ rustc. args ( & [ "--error-format" , "json" ] ) ;
1409+ }
1410+ }
14061411 MirOpt => {
14071412 rustc. args ( & [
14081413 "-Zdump-mir=all" ,
@@ -1427,7 +1432,6 @@ actual:\n\
14271432 Codegen |
14281433 Rustdoc |
14291434 RunMake |
1430- Ui |
14311435 CodegenUnits => {
14321436 // do not use JSON output
14331437 }
@@ -2211,7 +2215,12 @@ actual:\n\
22112215 }
22122216
22132217 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 ( ) ;
22152224
22162225 let expected_stderr_path = self . expected_output_path ( "stderr" ) ;
22172226 let expected_stderr = self . load_expected_output ( & expected_stderr_path) ;
@@ -2220,14 +2229,24 @@ actual:\n\
22202229 let expected_stdout = self . load_expected_output ( & expected_stdout_path) ;
22212230
22222231 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+
22242240 let normalized_stderr =
2225- self . normalize_output ( & proc_res . stderr , & self . props . normalize_stderr ) ;
2241+ self . normalize_output ( & stderr, & self . props . normalize_stderr , explicit ) ;
22262242
22272243 let mut errors = 0 ;
22282244 errors += self . compare_output ( "stdout" , & normalized_stdout, & expected_stdout) ;
22292245 errors += self . compare_output ( "stderr" , & normalized_stderr, & expected_stderr) ;
22302246
2247+ // rewrite the output to the human readable one (shown in case of errors)
2248+ proc_res. stderr = normalized_stderr;
2249+
22312250 if errors > 0 {
22322251 println ! ( "To update references, run this command from build directory:" ) ;
22332252 let relative_path_to_file =
@@ -2421,11 +2440,13 @@ actual:\n\
24212440 mir_dump_dir
24222441 }
24232442
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 {
24252449 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" ) ;
24292450 let parent_dir_str = if json {
24302451 parent_dir. display ( ) . to_string ( ) . replace ( "\\ " , "\\ \\ " )
24312452 } else {
0 commit comments