@@ -99,6 +99,10 @@ mod formatters;
9999
100100use  formatters:: { JsonFormatter ,  OutputFormatter ,  PrettyFormatter ,  TerseFormatter } ; 
101101
102+ /// Whether to execute tests concurrently or not 
103+ #[ derive( Copy ,  Clone ,  Debug ,  PartialEq ,  Eq ) ]  
104+ pub  enum  Concurrent  {  Yes ,  No  } 
105+ 
102106// The name of a test. By convention this follows the rules for rust 
103107// paths; i.e. it should be a series of identifiers separated by double 
104108// colons. This way if some test runner wants to arrange the tests 
@@ -1150,7 +1154,7 @@ where
11501154        while  !remaining. is_empty ( )  { 
11511155            let  test = remaining. pop ( ) . unwrap ( ) ; 
11521156            callback ( TeWait ( test. desc . clone ( ) ) ) ?; 
1153-             run_test ( opts,  !opts. run_tests ,  test,  tx. clone ( ) ,  /*concurrency*/ false ) ; 
1157+             run_test ( opts,  !opts. run_tests ,  test,  tx. clone ( ) ,  Concurrent :: No ) ; 
11541158            let  ( test,  result,  stdout)  = rx. recv ( ) . unwrap ( ) ; 
11551159            callback ( TeResult ( test,  result,  stdout) ) ?; 
11561160        } 
@@ -1161,7 +1165,7 @@ where
11611165                let  timeout = Instant :: now ( )  + Duration :: from_secs ( TEST_WARN_TIMEOUT_S ) ; 
11621166                running_tests. insert ( test. desc . clone ( ) ,  timeout) ; 
11631167                callback ( TeWait ( test. desc . clone ( ) ) ) ?;  //here no pad 
1164-                 run_test ( opts,  !opts. run_tests ,  test,  tx. clone ( ) ,  /*concurrency*/ true ) ; 
1168+                 run_test ( opts,  !opts. run_tests ,  test,  tx. clone ( ) ,  Concurrent :: Yes ) ; 
11651169                pending += 1 ; 
11661170            } 
11671171
@@ -1193,7 +1197,7 @@ where
11931197        // All benchmarks run at the end, in serial. 
11941198        for  b in  filtered_benchs { 
11951199            callback ( TeWait ( b. desc . clone ( ) ) ) ?; 
1196-             run_test ( opts,  false ,  b,  tx. clone ( ) ,  /*concurrency*/ true ) ; 
1200+             run_test ( opts,  false ,  b,  tx. clone ( ) ,  Concurrent :: No ) ; 
11971201            let  ( test,  result,  stdout)  = rx. recv ( ) . unwrap ( ) ; 
11981202            callback ( TeResult ( test,  result,  stdout) ) ?; 
11991203        } 
@@ -1395,7 +1399,7 @@ pub fn run_test(
13951399    force_ignore :  bool , 
13961400    test :  TestDescAndFn , 
13971401    monitor_ch :  Sender < MonitorMsg > , 
1398-     concurrency :  bool , 
1402+     concurrency :  Concurrent , 
13991403)  { 
14001404    let  TestDescAndFn  {  desc,  testfn }  = test; 
14011405
@@ -1412,7 +1416,7 @@ pub fn run_test(
14121416        monitor_ch :  Sender < MonitorMsg > , 
14131417        nocapture :  bool , 
14141418        testfn :  Box < dyn  FnBox ( )  + Send > , 
1415-         concurrency :  bool , 
1419+         concurrency :  Concurrent , 
14161420    )  { 
14171421        // Buffer for capturing standard I/O 
14181422        let  data = Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ; 
@@ -1447,7 +1451,7 @@ pub fn run_test(
14471451        // the test synchronously, regardless of the concurrency 
14481452        // level. 
14491453        let  supports_threads = !cfg ! ( target_os = "emscripten" )  && !cfg ! ( target_arch = "wasm32" ) ; 
1450-         if  concurrency && supports_threads { 
1454+         if  concurrency ==  Concurrent :: Yes   && supports_threads { 
14511455            let  cfg = thread:: Builder :: new ( ) . name ( name. as_slice ( ) . to_owned ( ) ) ; 
14521456            cfg. spawn ( runtest) . unwrap ( ) ; 
14531457        }  else  { 
@@ -1758,6 +1762,7 @@ mod tests {
17581762    use  std:: sync:: mpsc:: channel; 
17591763    use  bench; 
17601764    use  Bencher ; 
1765+     use  Concurrent ; 
17611766
17621767
17631768    fn  one_ignored_one_unignored_test ( )  -> Vec < TestDescAndFn >  { 
@@ -1798,7 +1803,7 @@ mod tests {
17981803            testfn :  DynTestFn ( Box :: new ( f) ) , 
17991804        } ; 
18001805        let  ( tx,  rx)  = channel ( ) ; 
1801-         run_test ( & TestOpts :: new ( ) ,  false ,  desc,  tx,  /*concurrency*/ false ) ; 
1806+         run_test ( & TestOpts :: new ( ) ,  false ,  desc,  tx,  Concurrent :: No ) ; 
18021807        let  ( _,  res,  _)  = rx. recv ( ) . unwrap ( ) ; 
18031808        assert ! ( res != TrOk ) ; 
18041809    } 
@@ -1816,7 +1821,7 @@ mod tests {
18161821            testfn :  DynTestFn ( Box :: new ( f) ) , 
18171822        } ; 
18181823        let  ( tx,  rx)  = channel ( ) ; 
1819-         run_test ( & TestOpts :: new ( ) ,  false ,  desc,  tx,  /*concurrency*/ false ) ; 
1824+         run_test ( & TestOpts :: new ( ) ,  false ,  desc,  tx,  Concurrent :: No ) ; 
18201825        let  ( _,  res,  _)  = rx. recv ( ) . unwrap ( ) ; 
18211826        assert ! ( res == TrIgnored ) ; 
18221827    } 
@@ -1836,7 +1841,7 @@ mod tests {
18361841            testfn :  DynTestFn ( Box :: new ( f) ) , 
18371842        } ; 
18381843        let  ( tx,  rx)  = channel ( ) ; 
1839-         run_test ( & TestOpts :: new ( ) ,  false ,  desc,  tx,  /*concurrency*/ false ) ; 
1844+         run_test ( & TestOpts :: new ( ) ,  false ,  desc,  tx,  Concurrent :: No ) ; 
18401845        let  ( _,  res,  _)  = rx. recv ( ) . unwrap ( ) ; 
18411846        assert ! ( res == TrOk ) ; 
18421847    } 
@@ -1856,7 +1861,7 @@ mod tests {
18561861            testfn :  DynTestFn ( Box :: new ( f) ) , 
18571862        } ; 
18581863        let  ( tx,  rx)  = channel ( ) ; 
1859-         run_test ( & TestOpts :: new ( ) ,  false ,  desc,  tx,  /*concurrency*/ false ) ; 
1864+         run_test ( & TestOpts :: new ( ) ,  false ,  desc,  tx,  Concurrent :: No ) ; 
18601865        let  ( _,  res,  _)  = rx. recv ( ) . unwrap ( ) ; 
18611866        assert ! ( res == TrOk ) ; 
18621867    } 
@@ -1878,7 +1883,7 @@ mod tests {
18781883            testfn :  DynTestFn ( Box :: new ( f) ) , 
18791884        } ; 
18801885        let  ( tx,  rx)  = channel ( ) ; 
1881-         run_test ( & TestOpts :: new ( ) ,  false ,  desc,  tx,  /*concurrency*/ false ) ; 
1886+         run_test ( & TestOpts :: new ( ) ,  false ,  desc,  tx,  Concurrent :: No ) ; 
18821887        let  ( _,  res,  _)  = rx. recv ( ) . unwrap ( ) ; 
18831888        assert ! ( res == TrFailedMsg ( format!( "{} '{}'" ,  failed_msg,  expected) ) ) ; 
18841889    } 
@@ -1896,7 +1901,7 @@ mod tests {
18961901            testfn :  DynTestFn ( Box :: new ( f) ) , 
18971902        } ; 
18981903        let  ( tx,  rx)  = channel ( ) ; 
1899-         run_test ( & TestOpts :: new ( ) ,  false ,  desc,  tx,  /*concurrency*/ false ) ; 
1904+         run_test ( & TestOpts :: new ( ) ,  false ,  desc,  tx,  Concurrent :: No ) ; 
19001905        let  ( _,  res,  _)  = rx. recv ( ) . unwrap ( ) ; 
19011906        assert ! ( res == TrFailed ) ; 
19021907    } 
0 commit comments