@@ -17,7 +17,6 @@ export tr_ok;
17
17
export tr_failed;
18
18
export tr_ignored;
19
19
export run_tests_console;
20
- export configure_test_task;
21
20
22
21
#[ abi = "cdecl" ]
23
22
native mod rustrt {
@@ -192,6 +191,8 @@ enum testevent {
192
191
te_result ( test_desc, test_result) ;
193
192
}
194
193
194
+ type monitor_msg = ( test_desc , test_result ) ;
195
+
195
196
fn run_tests ( opts : test_opts , tests : [ test_desc ] ,
196
197
callback : fn @( testevent ) ) {
197
198
@@ -202,23 +203,27 @@ fn run_tests(opts: test_opts, tests: [test_desc],
202
203
// many tests that run in other processes we would be making a big mess.
203
204
let concurrency = get_concurrency ( ) ;
204
205
#debug ( "using %u test tasks" , concurrency) ;
206
+
205
207
let total = vec:: len ( filtered_tests) ;
206
208
let run_idx = 0 u;
207
209
let wait_idx = 0 u;
208
- let futures = [ ] ;
210
+ let done_idx = 0 u ;
209
211
210
- while wait_idx < total {
211
- while vec:: len ( futures) < concurrency && run_idx < total {
212
- futures += [ run_test ( filtered_tests[ run_idx] ) ] ;
212
+ let p = comm:: port ( ) ;
213
+ let ch = comm:: chan ( p) ;
214
+
215
+ while done_idx < total {
216
+ while wait_idx < concurrency && run_idx < total {
217
+ run_test ( vec:: shift ( filtered_tests) , ch) ;
218
+ wait_idx += 1 u;
213
219
run_idx += 1 u;
214
220
}
215
221
216
- let future = futures[ 0 ] ;
217
- callback ( te_wait ( future. test ) ) ;
218
- let result = future. wait ( ) ;
219
- callback ( te_result ( future. test , result) ) ;
220
- futures = vec:: slice ( futures, 1 u, vec:: len ( futures) ) ;
221
- wait_idx += 1 u;
222
+ let ( test, result) = comm:: recv ( p) ;
223
+ callback ( te_wait ( test) ) ;
224
+ callback ( te_result ( test, result) ) ;
225
+ wait_idx -= 1 u;
226
+ done_idx += 1 u;
222
227
}
223
228
}
224
229
@@ -280,35 +285,34 @@ fn filter_tests(opts: test_opts,
280
285
281
286
type test_future = { test : test_desc , wait : fn @( ) -> test_result } ;
282
287
283
- fn run_test ( test : test_desc ) -> test_future {
288
+ fn run_test ( + test : test_desc , monitor_ch : comm :: chan < monitor_msg > ) {
284
289
if test. ignore {
285
- ret { test : test, wait : fn @( ) -> test_result { tr_ignored } } ;
290
+ comm:: send ( monitor_ch, ( test, tr_ignored) ) ;
291
+ ret;
286
292
}
287
293
288
- let test_task = test_to_task ( test. fn ) ;
289
- ret { test : test,
290
- wait : fn @( ) -> test_result {
291
- alt task:: join ( test_task) {
292
- task:: tr_success {
293
- if test. should_fail { tr_failed }
294
- else { tr_ok }
295
- }
296
- task:: tr_failure {
297
- if test. should_fail { tr_ok }
298
- else { tr_failed }
299
- }
300
- }
301
- }
294
+ task:: spawn { ||
295
+
296
+ let testfn = test. fn ;
297
+ let test_task = task:: spawn_joinable { ||
298
+ configure_test_task ( ) ;
299
+ testfn ( ) ;
302
300
} ;
301
+
302
+ let task_result = task:: join ( test_task) ;
303
+ let test_result = calc_result ( test, task_result == task:: tr_success) ;
304
+ comm:: send ( monitor_ch, ( test, test_result) ) ;
305
+ } ;
303
306
}
304
307
305
- // We need to run our tests in another task in order to trap test failures.
306
- // This function only works with functions that don't contain closures.
307
- fn test_to_task( & & f: test_fn) -> task:: joinable_task {
308
- ret task:: spawn_joinable ( fn~[ copy f] ( ) {
309
- configure_test_task ( ) ;
310
- f ( ) ;
311
- } ) ;
308
+ fn calc_result( test: test_desc, task_succeeded: bool ) -> test_result {
309
+ if task_succeeded {
310
+ if test. should_fail { tr_failed }
311
+ else { tr_ok }
312
+ } else {
313
+ if test. should_fail { tr_ok }
314
+ else { tr_failed }
315
+ }
312
316
}
313
317
314
318
// Call from within a test task to make sure it's set up correctly
@@ -330,9 +334,11 @@ mod tests {
330
334
ignore: true ,
331
335
should_fail: false
332
336
} ;
333
- let future = run_test ( desc) ;
334
- let result = future. wait ( ) ;
335
- assert result != tr_ok;
337
+ let p = comm:: port ( ) ;
338
+ let ch = comm:: chan ( p) ;
339
+ run_test ( desc, ch) ;
340
+ let ( _, res) = comm:: recv ( p) ;
341
+ assert res != tr_ok;
336
342
}
337
343
338
344
#[ test]
@@ -344,8 +350,11 @@ mod tests {
344
350
ignore: true ,
345
351
should_fail: false
346
352
} ;
347
- let res = run_test ( desc) . wait ( ) ;
348
- assert ( res == tr_ignored) ;
353
+ let p = comm:: port ( ) ;
354
+ let ch = comm:: chan ( p) ;
355
+ run_test ( desc, ch) ;
356
+ let ( _, res) = comm:: recv ( p) ;
357
+ assert res == tr_ignored;
349
358
}
350
359
351
360
#[ test]
@@ -358,7 +367,10 @@ mod tests {
358
367
ignore: false ,
359
368
should_fail: true
360
369
} ;
361
- let res = run_test ( desc) . wait ( ) ;
370
+ let p = comm:: port ( ) ;
371
+ let ch = comm:: chan ( p) ;
372
+ run_test ( desc, ch) ;
373
+ let ( _, res) = comm:: recv ( p) ;
362
374
assert res == tr_ok;
363
375
}
364
376
@@ -371,7 +383,10 @@ mod tests {
371
383
ignore: false ,
372
384
should_fail: true
373
385
} ;
374
- let res = run_test ( desc) . wait ( ) ;
386
+ let p = comm:: port ( ) ;
387
+ let ch = comm:: chan ( p) ;
388
+ run_test ( desc, ch) ;
389
+ let ( _, res) = comm:: recv ( p) ;
375
390
assert res == tr_failed;
376
391
}
377
392
0 commit comments