2
2
3
3
use crate :: common:: { CompareMode , PassMode } ;
4
4
use crate :: common:: { expected_output_path, UI_EXTENSIONS , UI_FIXED , UI_STDERR , UI_STDOUT } ;
5
+ use crate :: common:: { UI_RUN_STDERR , UI_RUN_STDOUT } ;
5
6
use crate :: common:: { output_base_dir, output_base_name, output_testname_unique} ;
6
7
use crate :: common:: { Codegen , CodegenUnits , Rustdoc } ;
7
8
use crate :: common:: { DebugInfoCdb , DebugInfoGdbLldb , DebugInfoGdb , DebugInfoLldb } ;
@@ -288,6 +289,11 @@ enum ReadFrom {
288
289
Stdin ( String ) ,
289
290
}
290
291
292
+ enum TestOutput {
293
+ Compile ,
294
+ Run ,
295
+ }
296
+
291
297
impl < ' test > TestCx < ' test > {
292
298
/// Code executed for each revision in turn (or, if there are no
293
299
/// revisions, exactly once, with revision == None).
@@ -2930,6 +2936,61 @@ impl<'test> TestCx<'test> {
2930
2936
}
2931
2937
}
2932
2938
2939
+ fn load_compare_outputs ( & self , proc_res : & ProcRes ,
2940
+ output_kind : TestOutput , explicit_format : bool ) -> usize {
2941
+
2942
+ let ( stderr_kind, stdout_kind) = match output_kind {
2943
+ TestOutput :: Compile => ( UI_STDERR , UI_STDOUT ) ,
2944
+ TestOutput :: Run => ( UI_RUN_STDERR , UI_RUN_STDOUT )
2945
+ } ;
2946
+
2947
+ let expected_stderr = self . load_expected_output ( stderr_kind) ;
2948
+ let expected_stdout = self . load_expected_output ( stdout_kind) ;
2949
+
2950
+ let normalized_stdout = match output_kind {
2951
+ TestOutput :: Run if self . config . remote_test_client . is_some ( ) => {
2952
+ // When tests are run using the remote-test-client, the string
2953
+ // 'uploaded "$TEST_BUILD_DIR/<test_executable>, waiting for result"'
2954
+ // is printed to stdout by the client and then captured in the ProcRes,
2955
+ // so it needs to be removed when comparing the run-pass test execution output
2956
+ lazy_static ! {
2957
+ static ref REMOTE_TEST_RE : Regex = Regex :: new(
2958
+ "^uploaded \" \\ $TEST_BUILD_DIR(/[[:alnum:]_\\ -]+)+\" , waiting for result\n "
2959
+ ) . unwrap( ) ;
2960
+ }
2961
+ REMOTE_TEST_RE . replace (
2962
+ & self . normalize_output ( & proc_res. stdout , & self . props . normalize_stdout ) ,
2963
+ ""
2964
+ ) . to_string ( )
2965
+ }
2966
+ _ => self . normalize_output ( & proc_res. stdout , & self . props . normalize_stdout )
2967
+ } ;
2968
+
2969
+ let stderr = if explicit_format {
2970
+ proc_res. stderr . clone ( )
2971
+ } else {
2972
+ json:: extract_rendered ( & proc_res. stderr )
2973
+ } ;
2974
+
2975
+ let normalized_stderr = self . normalize_output ( & stderr, & self . props . normalize_stderr ) ;
2976
+ let mut errors = 0 ;
2977
+ match output_kind {
2978
+ TestOutput :: Compile => {
2979
+ if !self . props . dont_check_compiler_stdout {
2980
+ errors += self . compare_output ( "stdout" , & normalized_stdout, & expected_stdout) ;
2981
+ }
2982
+ if !self . props . dont_check_compiler_stderr {
2983
+ errors += self . compare_output ( "stderr" , & normalized_stderr, & expected_stderr) ;
2984
+ }
2985
+ }
2986
+ TestOutput :: Run => {
2987
+ errors += self . compare_output ( stdout_kind, & normalized_stdout, & expected_stdout) ;
2988
+ errors += self . compare_output ( stderr_kind, & normalized_stderr, & expected_stderr) ;
2989
+ }
2990
+ }
2991
+ errors
2992
+ }
2993
+
2933
2994
fn run_ui_test ( & self ) {
2934
2995
// if the user specified a format in the ui test
2935
2996
// print the output to the stderr file, otherwise extract
@@ -2942,32 +3003,13 @@ impl<'test> TestCx<'test> {
2942
3003
let proc_res = self . compile_test ( ) ;
2943
3004
self . check_if_test_should_compile ( & proc_res) ;
2944
3005
2945
- let expected_stderr = self . load_expected_output ( UI_STDERR ) ;
2946
- let expected_stdout = self . load_expected_output ( UI_STDOUT ) ;
2947
3006
let expected_fixed = self . load_expected_output ( UI_FIXED ) ;
2948
3007
2949
- let normalized_stdout =
2950
- self . normalize_output ( & proc_res. stdout , & self . props . normalize_stdout ) ;
2951
-
2952
- let stderr = if explicit {
2953
- proc_res. stderr . clone ( )
2954
- } else {
2955
- json:: extract_rendered ( & proc_res. stderr )
2956
- } ;
2957
-
2958
- let normalized_stderr = self . normalize_output ( & stderr, & self . props . normalize_stderr ) ;
2959
-
2960
- let mut errors = 0 ;
2961
- if !self . props . dont_check_compiler_stdout {
2962
- errors += self . compare_output ( "stdout" , & normalized_stdout, & expected_stdout) ;
2963
- }
2964
- if !self . props . dont_check_compiler_stderr {
2965
- errors += self . compare_output ( "stderr" , & normalized_stderr, & expected_stderr) ;
2966
- }
2967
-
2968
3008
let modes_to_prune = vec ! [ CompareMode :: Nll ] ;
2969
3009
self . prune_duplicate_outputs ( & modes_to_prune) ;
2970
3010
3011
+ let mut errors = self . load_compare_outputs ( & proc_res, TestOutput :: Compile , explicit) ;
3012
+
2971
3013
if self . config . compare_mode . is_some ( ) {
2972
3014
// don't test rustfix with nll right now
2973
3015
} else if self . config . rustfix_coverage {
@@ -3045,7 +3087,17 @@ impl<'test> TestCx<'test> {
3045
3087
3046
3088
if self . should_run_successfully ( ) {
3047
3089
let proc_res = self . exec_compiled_test ( ) ;
3048
-
3090
+ let run_output_errors = if self . props . check_run_results {
3091
+ self . load_compare_outputs ( & proc_res, TestOutput :: Run , explicit)
3092
+ } else {
3093
+ 0
3094
+ } ;
3095
+ if run_output_errors > 0 {
3096
+ self . fatal_proc_rec (
3097
+ & format ! ( "{} errors occured comparing run output." , run_output_errors) ,
3098
+ & proc_res,
3099
+ ) ;
3100
+ }
3049
3101
if !proc_res. status . success ( ) {
3050
3102
self . fatal_proc_rec ( "test run failed!" , & proc_res) ;
3051
3103
}
0 commit comments