@@ -1182,26 +1182,63 @@ pub fn run_test(opts: &TestOpts,
1182
1182
}
1183
1183
}
1184
1184
1185
- thread:: spawn ( move || {
1186
- let data = Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ;
1187
- let data2 = data. clone ( ) ;
1188
- let cfg = thread:: Builder :: new ( ) . name ( match desc. name {
1189
- DynTestName ( ref name) => name. clone ( ) ,
1190
- StaticTestName ( name) => name. to_owned ( ) ,
1185
+ // If the platform is single-threaded we're just going to run
1186
+ // the test synchronously, regardless of the concurrency
1187
+ // level.
1188
+ let supports_threads = !cfg ! ( target_os = "emscripten" ) ;
1189
+
1190
+ // Buffer for capturing standard I/O
1191
+ let data = Arc :: new ( Mutex :: new ( Vec :: new ( ) ) ) ;
1192
+ let data2 = data. clone ( ) ;
1193
+
1194
+ if supports_threads {
1195
+ thread:: spawn ( move || {
1196
+ let cfg = thread:: Builder :: new ( ) . name ( match desc. name {
1197
+ DynTestName ( ref name) => name. clone ( ) ,
1198
+ StaticTestName ( name) => name. to_owned ( ) ,
1199
+ } ) ;
1200
+
1201
+ let result_guard = cfg. spawn ( move || {
1202
+ if !nocapture {
1203
+ io:: set_print ( box Sink ( data2. clone ( ) ) ) ;
1204
+ io:: set_panic ( box Sink ( data2) ) ;
1205
+ }
1206
+ testfn ( )
1207
+ } )
1208
+ . unwrap ( ) ;
1209
+ let test_result = calc_result ( & desc, result_guard. join ( ) ) ;
1210
+ let stdout = data. lock ( ) . unwrap ( ) . to_vec ( ) ;
1211
+ monitor_ch. send ( ( desc. clone ( ) , test_result, stdout) ) . unwrap ( ) ;
1191
1212
} ) ;
1213
+ } else {
1214
+ let oldio = if !nocapture {
1215
+ Some ( (
1216
+ io:: set_print ( box Sink ( data2. clone ( ) ) ) ,
1217
+ io:: set_panic ( box Sink ( data2) )
1218
+ ) )
1219
+ } else {
1220
+ None
1221
+ } ;
1222
+
1223
+ use std:: panic:: { catch_unwind, AssertUnwindSafe } ;
1192
1224
1193
- let result_guard = cfg. spawn ( move || {
1194
- if !nocapture {
1195
- io:: set_print ( box Sink ( data2. clone ( ) ) ) ;
1196
- io:: set_panic ( box Sink ( data2) ) ;
1197
- }
1198
- testfn ( )
1199
- } )
1200
- . unwrap ( ) ;
1201
- let test_result = calc_result ( & desc, result_guard. join ( ) ) ;
1225
+ let result = catch_unwind ( AssertUnwindSafe ( || {
1226
+ testfn ( )
1227
+ } ) ) ;
1228
+
1229
+ if let Some ( ( printio, panicio) ) = oldio {
1230
+ if let Some ( printio) = printio {
1231
+ io:: set_print ( printio) ;
1232
+ }
1233
+ if let Some ( panicio) = panicio {
1234
+ io:: set_panic ( panicio) ;
1235
+ }
1236
+ } ;
1237
+
1238
+ let test_result = calc_result ( & desc, result) ;
1202
1239
let stdout = data. lock ( ) . unwrap ( ) . to_vec ( ) ;
1203
1240
monitor_ch. send ( ( desc. clone ( ) , test_result, stdout) ) . unwrap ( ) ;
1204
- } ) ;
1241
+ }
1205
1242
}
1206
1243
1207
1244
match testfn {
0 commit comments