@@ -71,6 +71,14 @@ pub fn run_metrics(config: Config, testfile: String, mm: &mut MetricMap) {
71
71
}
72
72
}
73
73
74
+ fn get_output ( props : & TestProps , proc_res : & ProcRes ) -> String {
75
+ if props. check_stdout {
76
+ format ! ( "{}{}" , proc_res. stdout, proc_res. stderr)
77
+ } else {
78
+ proc_res. stderr . clone ( )
79
+ }
80
+ }
81
+
74
82
fn run_cfail_test ( config : & Config , props : & TestProps , testfile : & Path ) {
75
83
let proc_res = compile_test ( config, props, testfile) ;
76
84
@@ -81,16 +89,22 @@ fn run_cfail_test(config: &Config, props: &TestProps, testfile: &Path) {
81
89
82
90
check_correct_failure_status ( & proc_res) ;
83
91
92
+ if proc_res. status . success ( ) {
93
+ fatal ( "process did not return an error status" ) ;
94
+ }
95
+
96
+ let output_to_check = get_output ( props, & proc_res) ;
84
97
let expected_errors = errors:: load_errors ( & config. cfail_regex , testfile) ;
85
98
if !expected_errors. is_empty ( ) {
86
99
if !props. error_patterns . is_empty ( ) {
87
100
fatal ( "both error pattern and expected errors specified" ) ;
88
101
}
89
102
check_expected_errors ( expected_errors, testfile, & proc_res) ;
90
103
} else {
91
- check_error_patterns ( props, testfile, & proc_res) ;
104
+ check_error_patterns ( props, testfile, output_to_check . as_slice ( ) , & proc_res) ;
92
105
}
93
106
check_no_compiler_crash ( & proc_res) ;
107
+ check_forbid_output ( props, output_to_check. as_slice ( ) , & proc_res) ;
94
108
}
95
109
96
110
fn run_rfail_test ( config : & Config , props : & TestProps , testfile : & Path ) {
@@ -112,8 +126,9 @@ fn run_rfail_test(config: &Config, props: &TestProps, testfile: &Path) {
112
126
fatal_proc_rec ( "run-fail test isn't valgrind-clean!" , & proc_res) ;
113
127
}
114
128
129
+ let output_to_check = get_output ( props, & proc_res) ;
115
130
check_correct_failure_status ( & proc_res) ;
116
- check_error_patterns ( props, testfile, & proc_res) ;
131
+ check_error_patterns ( props, testfile, output_to_check . as_slice ( ) , & proc_res) ;
117
132
}
118
133
119
134
fn check_correct_failure_status ( proc_res : & ProcRes ) {
@@ -258,8 +273,8 @@ fn run_pretty_test(config: &Config, props: &TestProps, testfile: &Path) {
258
273
format!( "--target={}" , config. target) ,
259
274
"-L" . to_string( ) ,
260
275
aux_dir. as_str( ) . unwrap( ) . to_string( ) ) ;
261
- args. push_all_move ( split_maybe_args ( & config. target_rustcflags ) ) ;
262
- args. push_all_move ( split_maybe_args ( & props. compile_flags ) ) ;
276
+ args. extend ( split_maybe_args ( & config. target_rustcflags ) . into_iter ( ) ) ;
277
+ args. extend ( split_maybe_args ( & props. compile_flags ) . into_iter ( ) ) ;
263
278
return ProcArgs {
264
279
prog : config. rustc_path . as_str ( ) . unwrap ( ) . to_string ( ) ,
265
280
args : args,
@@ -306,8 +321,8 @@ actual:\n\
306
321
config. build_base. as_str( ) . unwrap( ) . to_string( ) ,
307
322
"-L" . to_string( ) ,
308
323
aux_dir. as_str( ) . unwrap( ) . to_string( ) ) ;
309
- args. push_all_move ( split_maybe_args ( & config. target_rustcflags ) ) ;
310
- args. push_all_move ( split_maybe_args ( & props. compile_flags ) ) ;
324
+ args. extend ( split_maybe_args ( & config. target_rustcflags ) . into_iter ( ) ) ;
325
+ args. extend ( split_maybe_args ( & props. compile_flags ) . into_iter ( ) ) ;
311
326
// FIXME (#9639): This needs to handle non-utf8 paths
312
327
return ProcArgs {
313
328
prog : config. rustc_path . as_str ( ) . unwrap ( ) . to_string ( ) ,
@@ -834,24 +849,15 @@ fn check_debugger_output(debugger_run_result: &ProcRes, check_lines: &[String])
834
849
835
850
fn check_error_patterns ( props : & TestProps ,
836
851
testfile : & Path ,
852
+ output_to_check : & str ,
837
853
proc_res : & ProcRes ) {
838
854
if props. error_patterns . is_empty ( ) {
839
855
fatal ( format ! ( "no error pattern specified in {}" ,
840
856
testfile. display( ) ) . as_slice ( ) ) ;
841
857
}
842
-
843
- if proc_res. status . success ( ) {
844
- fatal ( "process did not return an error status" ) ;
845
- }
846
-
847
858
let mut next_err_idx = 0 u;
848
859
let mut next_err_pat = & props. error_patterns [ next_err_idx] ;
849
860
let mut done = false ;
850
- let output_to_check = if props. check_stdout {
851
- format ! ( "{}{}" , proc_res. stdout, proc_res. stderr)
852
- } else {
853
- proc_res. stderr . clone ( )
854
- } ;
855
861
for line in output_to_check. as_slice ( ) . lines ( ) {
856
862
if line. contains ( next_err_pat. as_slice ( ) ) {
857
863
debug ! ( "found error pattern {}" , next_err_pat) ;
@@ -890,6 +896,16 @@ fn check_no_compiler_crash(proc_res: &ProcRes) {
890
896
}
891
897
}
892
898
899
+ fn check_forbid_output ( props : & TestProps ,
900
+ output_to_check : & str ,
901
+ proc_res : & ProcRes ) {
902
+ for pat in props. forbid_output . iter ( ) {
903
+ if output_to_check. contains ( pat. as_slice ( ) ) {
904
+ fatal_proc_rec ( "forbidden pattern found in compiler output" , proc_res) ;
905
+ }
906
+ }
907
+ }
908
+
893
909
fn check_expected_errors ( expected_errors : Vec < errors:: ExpectedError > ,
894
910
testfile : & Path ,
895
911
proc_res : & ProcRes ) {
@@ -1079,11 +1095,12 @@ fn compile_test_(config: &Config, props: &TestProps,
1079
1095
testfile : & Path , extra_args : & [ String ] ) -> ProcRes {
1080
1096
let aux_dir = aux_output_dir_name ( config, testfile) ;
1081
1097
// FIXME (#9639): This needs to handle non-utf8 paths
1082
- let link_args = vec ! ( "-L" . to_string( ) ,
1083
- aux_dir. as_str( ) . unwrap( ) . to_string( ) ) ;
1098
+ let mut link_args = vec ! ( "-L" . to_string( ) ,
1099
+ aux_dir. as_str( ) . unwrap( ) . to_string( ) ) ;
1100
+ link_args. extend ( extra_args. iter ( ) . map ( |s| s. clone ( ) ) ) ;
1084
1101
let args = make_compile_args ( config,
1085
1102
props,
1086
- link_args. append ( extra_args ) ,
1103
+ link_args,
1087
1104
|a, b| ThisFile ( make_exe_name ( a, b) ) , testfile) ;
1088
1105
compose_and_run_compiler ( config, props, testfile, args, None )
1089
1106
}
@@ -1130,16 +1147,16 @@ fn compose_and_run_compiler(
1130
1147
for rel_ab in props. aux_builds . iter ( ) {
1131
1148
let abs_ab = config. aux_base . join ( rel_ab. as_slice ( ) ) ;
1132
1149
let aux_props = header:: load_props ( & abs_ab) ;
1133
- let crate_type = if aux_props. no_prefer_dynamic {
1150
+ let mut crate_type = if aux_props. no_prefer_dynamic {
1134
1151
Vec :: new ( )
1135
1152
} else {
1136
1153
vec ! ( "--crate-type=dylib" . to_string( ) )
1137
1154
} ;
1155
+ crate_type. extend ( extra_link_args. clone ( ) . into_iter ( ) ) ;
1138
1156
let aux_args =
1139
1157
make_compile_args ( config,
1140
1158
& aux_props,
1141
- crate_type. append (
1142
- extra_link_args. as_slice ( ) ) ,
1159
+ crate_type,
1143
1160
|a, b| {
1144
1161
let f = make_lib_name ( a, b, testfile) ;
1145
1162
ThisDirectory ( f. dir_path ( ) )
@@ -1230,11 +1247,11 @@ fn make_compile_args(config: &Config,
1230
1247
} ;
1231
1248
args. push ( path. as_str ( ) . unwrap ( ) . to_string ( ) ) ;
1232
1249
if props. force_host {
1233
- args. push_all_move ( split_maybe_args ( & config. host_rustcflags ) ) ;
1250
+ args. extend ( split_maybe_args ( & config. host_rustcflags ) . into_iter ( ) ) ;
1234
1251
} else {
1235
- args. push_all_move ( split_maybe_args ( & config. target_rustcflags ) ) ;
1252
+ args. extend ( split_maybe_args ( & config. target_rustcflags ) . into_iter ( ) ) ;
1236
1253
}
1237
- args. push_all_move ( split_maybe_args ( & props. compile_flags ) ) ;
1254
+ args. extend ( split_maybe_args ( & props. compile_flags ) . into_iter ( ) ) ;
1238
1255
return ProcArgs {
1239
1256
prog : config. rustc_path . as_str ( ) . unwrap ( ) . to_string ( ) ,
1240
1257
args : args,
@@ -1251,10 +1268,9 @@ fn make_lib_name(config: &Config, auxfile: &Path, testfile: &Path) -> Path {
1251
1268
fn make_exe_name ( config : & Config , testfile : & Path ) -> Path {
1252
1269
let mut f = output_base_name ( config, testfile) ;
1253
1270
if !os:: consts:: EXE_SUFFIX . is_empty ( ) {
1254
- match f. filename ( ) . map ( |s| Vec :: from_slice ( s) . append ( os:: consts:: EXE_SUFFIX . as_bytes ( ) ) ) {
1255
- Some ( v) => f. set_filename ( v) ,
1256
- None => ( )
1257
- }
1271
+ let mut fname = f. filename ( ) . unwrap ( ) . to_vec ( ) ;
1272
+ fname. extend ( os:: consts:: EXE_SUFFIX . bytes ( ) ) ;
1273
+ f. set_filename ( fname) ;
1258
1274
}
1259
1275
f
1260
1276
}
@@ -1270,7 +1286,7 @@ fn make_run_args(config: &Config, props: &TestProps, testfile: &Path) ->
1270
1286
args. push ( exe_file. as_str ( ) . unwrap ( ) . to_string ( ) ) ;
1271
1287
1272
1288
// Add the arguments in the run_flags directive
1273
- args. push_all_move ( split_maybe_args ( & props. run_flags ) ) ;
1289
+ args. extend ( split_maybe_args ( & props. run_flags ) . into_iter ( ) ) ;
1274
1290
1275
1291
let prog = args. remove ( 0 ) . unwrap ( ) ;
1276
1292
return ProcArgs {
@@ -1365,12 +1381,10 @@ fn make_out_name(config: &Config, testfile: &Path, extension: &str) -> Path {
1365
1381
}
1366
1382
1367
1383
fn aux_output_dir_name ( config : & Config , testfile : & Path ) -> Path {
1368
- let mut f = output_base_name ( config, testfile) ;
1369
- match f. filename ( ) . map ( |s| Vec :: from_slice ( s) . append ( b".libaux" ) ) {
1370
- Some ( v) => f. set_filename ( v) ,
1371
- None => ( )
1372
- }
1373
- f
1384
+ let f = output_base_name ( config, testfile) ;
1385
+ let mut fname = f. filename ( ) . unwrap ( ) . to_vec ( ) ;
1386
+ fname. extend ( "libaux" . bytes ( ) ) ;
1387
+ f. with_filename ( fname)
1374
1388
}
1375
1389
1376
1390
fn output_testname ( testfile : & Path ) -> Path {
@@ -1582,22 +1596,25 @@ fn append_suffix_to_stem(p: &Path, suffix: &str) -> Path {
1582
1596
if suffix. len ( ) == 0 {
1583
1597
( * p) . clone ( )
1584
1598
} else {
1585
- let stem = p. filestem ( ) . unwrap ( ) ;
1586
- p. with_filename ( Vec :: from_slice ( stem) . append ( b"-" ) . append ( suffix. as_bytes ( ) ) )
1599
+ let mut stem = p. filestem ( ) . unwrap ( ) . to_vec ( ) ;
1600
+ stem. extend ( "-" . bytes ( ) ) ;
1601
+ stem. extend ( suffix. bytes ( ) ) ;
1602
+ p. with_filename ( stem)
1587
1603
}
1588
1604
}
1589
1605
1590
1606
fn compile_test_and_save_bitcode ( config : & Config , props : & TestProps ,
1591
1607
testfile : & Path ) -> ProcRes {
1592
1608
let aux_dir = aux_output_dir_name ( config, testfile) ;
1593
1609
// FIXME (#9639): This needs to handle non-utf8 paths
1594
- let link_args = vec ! ( "-L" . to_string( ) ,
1595
- aux_dir. as_str( ) . unwrap( ) . to_string( ) ) ;
1610
+ let mut link_args = vec ! ( "-L" . to_string( ) ,
1611
+ aux_dir. as_str( ) . unwrap( ) . to_string( ) ) ;
1596
1612
let llvm_args = vec ! ( "--emit=bc,obj" . to_string( ) ,
1597
1613
"--crate-type=lib" . to_string( ) ) ;
1614
+ link_args. extend ( llvm_args. into_iter ( ) ) ;
1598
1615
let args = make_compile_args ( config,
1599
1616
props,
1600
- link_args. append ( llvm_args . as_slice ( ) ) ,
1617
+ link_args,
1601
1618
|a, b| ThisDirectory ( output_base_name ( a, b) . dir_path ( ) ) ,
1602
1619
testfile) ;
1603
1620
compose_and_run_compiler ( config, props, testfile, args, None )
0 commit comments