@@ -559,68 +559,6 @@ pub fn run_test(
559
559
return None ;
560
560
}
561
561
562
- struct TestRunOpts {
563
- pub strategy : RunStrategy ,
564
- pub nocapture : bool ,
565
- pub time : Option < time:: TestTimeOptions > ,
566
- }
567
-
568
- fn run_test_inner (
569
- id : TestId ,
570
- desc : TestDesc ,
571
- monitor_ch : Sender < CompletedTest > ,
572
- runnable_test : RunnableTest ,
573
- opts : TestRunOpts ,
574
- ) -> Option < thread:: JoinHandle < ( ) > > {
575
- let name = desc. name . clone ( ) ;
576
-
577
- let runtest = move || match opts. strategy {
578
- RunStrategy :: InProcess => run_test_in_process (
579
- id,
580
- desc,
581
- opts. nocapture ,
582
- opts. time . is_some ( ) ,
583
- runnable_test,
584
- monitor_ch,
585
- opts. time ,
586
- ) ,
587
- RunStrategy :: SpawnPrimary => spawn_test_subprocess (
588
- id,
589
- desc,
590
- opts. nocapture ,
591
- opts. time . is_some ( ) ,
592
- monitor_ch,
593
- opts. time ,
594
- ) ,
595
- } ;
596
-
597
- // If the platform is single-threaded we're just going to run
598
- // the test synchronously, regardless of the concurrency
599
- // level.
600
- let supports_threads = !cfg ! ( target_os = "emscripten" ) && !cfg ! ( target_family = "wasm" ) ;
601
- if supports_threads {
602
- let cfg = thread:: Builder :: new ( ) . name ( name. as_slice ( ) . to_owned ( ) ) ;
603
- let mut runtest = Arc :: new ( Mutex :: new ( Some ( runtest) ) ) ;
604
- let runtest2 = runtest. clone ( ) ;
605
- match cfg. spawn ( move || runtest2. lock ( ) . unwrap ( ) . take ( ) . unwrap ( ) ( ) ) {
606
- Ok ( handle) => Some ( handle) ,
607
- Err ( e) if e. kind ( ) == io:: ErrorKind :: WouldBlock => {
608
- // `ErrorKind::WouldBlock` means hitting the thread limit on some
609
- // platforms, so run the test synchronously here instead.
610
- Arc :: get_mut ( & mut runtest) . unwrap ( ) . get_mut ( ) . unwrap ( ) . take ( ) . unwrap ( ) ( ) ;
611
- None
612
- }
613
- Err ( e) => panic ! ( "failed to spawn thread to run test: {e}" ) ,
614
- }
615
- } else {
616
- runtest ( ) ;
617
- None
618
- }
619
- }
620
-
621
- let test_run_opts =
622
- TestRunOpts { strategy, nocapture : opts. nocapture , time : opts. time_options } ;
623
-
624
562
match testfn. into_runnable ( ) {
625
563
Runnable :: Test ( runnable_test) => {
626
564
if runnable_test. is_dynamic ( ) {
@@ -629,7 +567,53 @@ pub fn run_test(
629
567
_ => panic ! ( "Cannot run dynamic test fn out-of-process" ) ,
630
568
} ;
631
569
}
632
- run_test_inner ( id, desc, monitor_ch, runnable_test, test_run_opts)
570
+
571
+ let name = desc. name . clone ( ) ;
572
+ let nocapture = opts. nocapture ;
573
+ let time_options = opts. time_options ;
574
+
575
+ let runtest = move || match strategy {
576
+ RunStrategy :: InProcess => run_test_in_process (
577
+ id,
578
+ desc,
579
+ nocapture,
580
+ time_options. is_some ( ) ,
581
+ runnable_test,
582
+ monitor_ch,
583
+ time_options,
584
+ ) ,
585
+ RunStrategy :: SpawnPrimary => spawn_test_subprocess (
586
+ id,
587
+ desc,
588
+ nocapture,
589
+ time_options. is_some ( ) ,
590
+ monitor_ch,
591
+ time_options,
592
+ ) ,
593
+ } ;
594
+
595
+ // If the platform is single-threaded we're just going to run
596
+ // the test synchronously, regardless of the concurrency
597
+ // level.
598
+ let supports_threads = !cfg ! ( target_os = "emscripten" ) && !cfg ! ( target_family = "wasm" ) ;
599
+ if supports_threads {
600
+ let cfg = thread:: Builder :: new ( ) . name ( name. as_slice ( ) . to_owned ( ) ) ;
601
+ let mut runtest = Arc :: new ( Mutex :: new ( Some ( runtest) ) ) ;
602
+ let runtest2 = runtest. clone ( ) ;
603
+ match cfg. spawn ( move || runtest2. lock ( ) . unwrap ( ) . take ( ) . unwrap ( ) ( ) ) {
604
+ Ok ( handle) => Some ( handle) ,
605
+ Err ( e) if e. kind ( ) == io:: ErrorKind :: WouldBlock => {
606
+ // `ErrorKind::WouldBlock` means hitting the thread limit on some
607
+ // platforms, so run the test synchronously here instead.
608
+ Arc :: get_mut ( & mut runtest) . unwrap ( ) . get_mut ( ) . unwrap ( ) . take ( ) . unwrap ( ) ( ) ;
609
+ None
610
+ }
611
+ Err ( e) => panic ! ( "failed to spawn thread to run test: {e}" ) ,
612
+ }
613
+ } else {
614
+ runtest ( ) ;
615
+ None
616
+ }
633
617
}
634
618
Runnable :: Bench ( runnable_bench) => {
635
619
// Benchmarks aren't expected to panic, so we run them all in-process.
0 commit comments