@@ -8,8 +8,6 @@ use std::fs;
8
8
use std:: path:: { Path , PathBuf } ;
9
9
use std:: process:: Command ;
10
10
11
- type Result < T > = std:: result:: Result < T , Box < dyn std:: error:: Error > > ;
12
-
13
11
struct TestCase {
14
12
config : & ' static str ,
15
13
func : & ' static dyn Fn ( & TestRunner ) ,
@@ -183,18 +181,16 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
183
181
runner. run_cargo ( [ "clean" ] ) ;
184
182
185
183
// newer aho_corasick versions throw a deprecation warning
186
- let mut lint_rust_flags = runner. rust_flags . clone ( ) ;
187
- lint_rust_flags. push ( "--cap-lints" . to_string ( ) ) ;
188
- lint_rust_flags. push ( "warn" . to_string ( ) ) ;
184
+ let lint_rust_flags = format ! ( "{} --cap-lints warn" , runner. rust_flags) ;
189
185
190
186
let mut build_cmd = runner. cargo_command ( [ "build" , "--example" , "shootout-regex-dna" , "--target" , & runner. target_triple ] ) ;
191
- build_cmd. env ( "RUSTFLAGS" , lint_rust_flags. join ( " " ) ) ;
187
+ build_cmd. env ( "RUSTFLAGS" , lint_rust_flags. clone ( ) ) ;
192
188
193
189
spawn_and_wait ( build_cmd) ;
194
190
195
191
if runner. host_triple == runner. target_triple {
196
192
let mut run_cmd = runner. cargo_command ( [ "run" , "--example" , "shootout-regex-dna" , "--target" , & runner. target_triple ] ) ;
197
- run_cmd. env ( "RUSTFLAGS" , lint_rust_flags. join ( " " ) ) ;
193
+ run_cmd. env ( "RUSTFLAGS" , lint_rust_flags) ;
198
194
199
195
200
196
let input = fs:: read_to_string ( PathBuf :: from ( "examples/regexdna-input.txt" ) ) . unwrap ( ) ;
@@ -205,7 +201,6 @@ const EXTENDED_SYSROOT_SUITE: &[TestCase] = &[
205
201
// Make sure `[codegen mono items] start` doesn't poison the diff
206
202
let output = output. lines ( )
207
203
. filter ( |line| !line. contains ( "codegen mono items" ) )
208
- . filter ( |line| !line. contains ( "Spawned thread" ) )
209
204
. chain ( Some ( "" ) ) // This just adds the trailing newline
210
205
. collect :: < Vec < & str > > ( )
211
206
. join ( "\r \n " ) ;
@@ -267,7 +262,7 @@ pub(crate) fn run_tests(
267
262
cg_clif_build_dir : & Path ,
268
263
host_triple : & str ,
269
264
target_triple : & str ,
270
- ) -> Result < ( ) > {
265
+ ) {
271
266
let runner = TestRunner :: new ( host_triple. to_string ( ) , target_triple. to_string ( ) ) ;
272
267
273
268
if config:: get_bool ( "testsuite.no_sysroot" ) {
@@ -280,7 +275,7 @@ pub(crate) fn run_tests(
280
275
& target_triple,
281
276
) ;
282
277
283
- let _ = remove_out_dir ( ) ;
278
+ let _ = fs :: remove_dir_all ( Path :: new ( "target" ) . join ( "out" ) ) ;
284
279
runner. run_testsuite ( NO_SYSROOT_SUITE ) ;
285
280
} else {
286
281
eprintln ! ( "[SKIP] no_sysroot tests" ) ;
@@ -311,22 +306,16 @@ pub(crate) fn run_tests(
311
306
} else {
312
307
eprintln ! ( "[SKIP] extended_sysroot tests" ) ;
313
308
}
314
-
315
- Ok ( ( ) )
316
309
}
317
310
318
311
319
- fn remove_out_dir ( ) -> Result < ( ) > {
320
- let out_dir = Path :: new ( "target" ) . join ( "out" ) ;
321
- Ok ( fs:: remove_dir_all ( out_dir) ?)
322
- }
323
312
324
313
struct TestRunner {
325
314
root_dir : PathBuf ,
326
315
out_dir : PathBuf ,
327
316
jit_supported : bool ,
328
- rust_flags : Vec < String > ,
329
- run_wrapper : Vec < String > ,
317
+ rust_flags : String ,
318
+ run_wrapper : String ,
330
319
host_triple : String ,
331
320
target_triple : String ,
332
321
}
@@ -342,22 +331,19 @@ impl TestRunner {
342
331
let is_native = host_triple == target_triple;
343
332
let jit_supported = target_triple. contains ( "x86_64" ) && is_native;
344
333
345
- let env_rust_flags = env:: var ( "RUSTFLAGS" ) . ok ( ) ;
346
- let env_run_wrapper = env:: var ( "RUN_WRAPPER" ) . ok ( ) ;
347
-
348
- let mut rust_flags: Vec < & str > = env_rust_flags. iter ( ) . map ( |s| s. as_str ( ) ) . collect ( ) ;
349
- let mut run_wrapper: Vec < & str > = env_run_wrapper. iter ( ) . map ( |s| s. as_str ( ) ) . collect ( ) ;
334
+ let mut rust_flags = env:: var ( "RUSTFLAGS" ) . ok ( ) . unwrap_or ( "" . to_string ( ) ) ;
335
+ let mut run_wrapper = String :: new ( ) ;
350
336
351
337
if !is_native {
352
338
match target_triple. as_str ( ) {
353
339
"aarch64-unknown-linux-gnu" => {
354
340
// We are cross-compiling for aarch64. Use the correct linker and run tests in qemu.
355
- rust_flags. insert ( 0 , "-Clinker=aarch64-linux-gnu-gcc" ) ;
356
- run_wrapper. extend ( [ "qemu-aarch64" , "-L" , " /usr/aarch64-linux-gnu"] ) ;
341
+ rust_flags = format ! ( "-Clinker=aarch64-linux-gnu-gcc {}" , rust_flags ) ;
342
+ run_wrapper = "qemu-aarch64 -L /usr/aarch64-linux-gnu" . to_string ( ) ;
357
343
} ,
358
344
"x86_64-pc-windows-gnu" => {
359
345
// We are cross-compiling for Windows. Run tests in wine.
360
- run_wrapper. push ( "wine" . into ( ) ) ;
346
+ run_wrapper = "wine" . to_string ( ) ;
361
347
}
362
348
_ => {
363
349
println ! ( "Unknown non-native platform" ) ;
@@ -367,26 +353,25 @@ impl TestRunner {
367
353
368
354
// FIXME fix `#[linkage = "extern_weak"]` without this
369
355
if host_triple. contains ( "darwin" ) {
370
- rust_flags. push ( "-Clink-arg=-undefined" ) ;
371
- rust_flags. push ( "-Clink-arg=dynamic_lookup" ) ;
356
+ rust_flags = format ! ( "{} -Clink-arg=-undefined -Clink-arg=dynamic_lookup" , rust_flags) ;
372
357
}
373
358
374
359
Self {
375
360
root_dir,
376
361
out_dir,
377
362
jit_supported,
378
- rust_flags : rust_flags . iter ( ) . map ( |s| s . to_string ( ) ) . collect ( ) ,
379
- run_wrapper : run_wrapper . iter ( ) . map ( |s| s . to_string ( ) ) . collect ( ) ,
363
+ rust_flags,
364
+ run_wrapper,
380
365
host_triple,
381
366
target_triple,
382
367
}
383
368
}
384
369
385
370
pub fn run_testsuite ( & self , tests : & [ TestCase ] ) {
386
371
for & TestCase { config, func } in tests {
387
- let is_jit_test = config. contains ( "jit" ) ;
388
372
let ( tag, testname) = config. split_once ( '.' ) . unwrap ( ) ;
389
373
let tag = tag. to_uppercase ( ) ;
374
+ let is_jit_test = tag == "JIT" ;
390
375
391
376
if !config:: get_bool ( config) || ( is_jit_test && !self . jit_supported ) {
392
377
eprintln ! ( "[{tag}] {testname} (skipped)" ) ;
@@ -428,14 +413,16 @@ impl TestRunner {
428
413
}
429
414
430
415
let mut cmd = Command :: new ( rustc_clif) ;
431
- cmd. args ( self . rust_flags . iter ( ) ) ;
416
+ if !self . rust_flags . is_empty ( ) {
417
+ cmd. arg ( & self . rust_flags ) ;
418
+ }
432
419
cmd. arg ( "-L" ) ;
433
420
cmd. arg ( format ! ( "crate={}" , self . out_dir. display( ) ) ) ;
434
421
cmd. arg ( "--out-dir" ) ;
435
422
cmd. arg ( format ! ( "{}" , self . out_dir. display( ) ) ) ;
436
423
cmd. arg ( "-Cdebuginfo=2" ) ;
437
424
cmd. args ( args) ;
438
- cmd. env ( "RUSTFLAGS" , self . rust_flags . join ( " " ) ) ;
425
+ cmd. env ( "RUSTFLAGS" , & self . rust_flags ) ;
439
426
cmd
440
427
}
441
428
@@ -454,8 +441,8 @@ impl TestRunner {
454
441
let mut full_cmd = vec ! [ ] ;
455
442
456
443
// Prepend the RUN_WRAPPER's
457
- for rw in self . run_wrapper . iter ( ) {
458
- full_cmd. push ( rw . to_string ( ) ) ;
444
+ if ! self . run_wrapper . is_empty ( ) {
445
+ full_cmd. push ( self . run_wrapper . clone ( ) ) ;
459
446
}
460
447
461
448
full_cmd. push ( {
@@ -491,7 +478,7 @@ impl TestRunner {
491
478
492
479
let mut cmd = Command :: new ( cargo_clif) ;
493
480
cmd. args ( args) ;
494
- cmd. env ( "RUSTFLAGS" , self . rust_flags . join ( " " ) ) ;
481
+ cmd. env ( "RUSTFLAGS" , & self . rust_flags ) ;
495
482
cmd
496
483
}
497
484
0 commit comments