@@ -261,37 +261,31 @@ impl Metric {
261
261
#[ derive( Copy , Clone , Debug ) ]
262
262
pub struct Options {
263
263
display_output : bool ,
264
+ panic_abort : bool ,
264
265
}
265
266
266
267
impl Options {
267
268
pub fn new ( ) -> Options {
268
269
Options {
269
270
display_output : false ,
271
+ panic_abort : false ,
270
272
}
271
273
}
272
274
273
275
pub fn display_output ( mut self , display_output : bool ) -> Options {
274
276
self . display_output = display_output;
275
277
self
276
278
}
279
+
280
+ pub fn panic_abort ( mut self , panic_abort : bool ) -> Options {
281
+ self . panic_abort = panic_abort;
282
+ self
283
+ }
277
284
}
278
285
279
286
// The default console test runner. It accepts the command line
280
287
// arguments and a vector of test_descs.
281
288
pub fn test_main ( args : & [ String ] , tests : Vec < TestDescAndFn > , options : Option < Options > ) {
282
- // If we're being run in SpawnedSecondary mode, run the test here. run_test
283
- // will then exit the process.
284
- if let Ok ( name) = env:: var ( SECONDARY_TEST_INVOKER_VAR ) {
285
- let test = tests
286
- . into_iter ( )
287
- . filter ( |test| test. desc . name . as_slice ( ) == name)
288
- . next ( )
289
- . expect ( "couldn't find a test with the provided name" ) ;
290
- let opts = parse_opts ( & [ ] ) . unwrap ( ) . unwrap ( ) ;
291
- run_test ( & opts, false , test, RunStrategy :: SpawnedSecondary , Concurrent :: No ) ;
292
- unreachable ! ( ) ;
293
- }
294
-
295
289
let mut opts = match parse_opts ( args) {
296
290
Some ( Ok ( o) ) => o,
297
291
Some ( Err ( msg) ) => {
@@ -320,32 +314,63 @@ pub fn test_main(args: &[String], tests: Vec<TestDescAndFn>, options: Option<Opt
320
314
}
321
315
}
322
316
323
- // A variant optimized for invocation with a static test vector.
324
- // This will panic (intentionally) when fed any dynamic tests, because
325
- // it is copying the static values out into a dynamic vector and cannot
326
- // copy dynamic values. It is doing this because from this point on
327
- // a Vec<TestDescAndFn> is used in order to effect ownership-transfer
328
- // semantics into parallel test runners, which in turn requires a Vec<>
329
- // rather than a &[].
317
+ /// A variant optimized for invocation with a static test vector.
318
+ /// This will panic (intentionally) when fed any dynamic tests.
319
+ ///
320
+ /// This is the entry point for the main function generated by `rustc --test`
321
+ /// when panic=unwind.
330
322
pub fn test_main_static ( tests : & [ & TestDescAndFn ] ) {
331
323
let args = env:: args ( ) . collect :: < Vec < _ > > ( ) ;
332
- let owned_tests = tests
333
- . iter ( )
334
- . map ( |t| match t. testfn {
335
- StaticTestFn ( f) => TestDescAndFn {
336
- testfn : StaticTestFn ( f) ,
337
- desc : t. desc . clone ( ) ,
338
- } ,
339
- StaticBenchFn ( f) => TestDescAndFn {
340
- testfn : StaticBenchFn ( f) ,
341
- desc : t. desc . clone ( ) ,
342
- } ,
343
- _ => panic ! ( "non-static tests passed to test::test_main_static" ) ,
344
- } )
345
- . collect ( ) ;
324
+ let owned_tests: Vec < _ > = tests. iter ( ) . map ( make_owned_test) . collect ( ) ;
346
325
test_main ( & args, owned_tests, None )
347
326
}
348
327
328
+ /// A variant optimized for invocation with a static test vector.
329
+ /// This will panic (intentionally) when fed any dynamic tests.
330
+ ///
331
+ /// Runs tests in panic=abort mode, which involves spawning subprocesses for
332
+ /// tests.
333
+ ///
334
+ /// This is the entry point for the main function generated by `rustc --test`
335
+ /// when panic=abort.
336
+ pub fn test_main_static_abort ( tests : & [ & TestDescAndFn ] ) {
337
+ // If we're being run in SpawnedSecondary mode, run the test here. run_test
338
+ // will then exit the process.
339
+ if let Ok ( name) = env:: var ( SECONDARY_TEST_INVOKER_VAR ) {
340
+ let test = tests
341
+ . iter ( )
342
+ . filter ( |test| test. desc . name . as_slice ( ) == name)
343
+ . map ( make_owned_test)
344
+ . next ( )
345
+ . expect ( "couldn't find a test with the provided name" ) ;
346
+ let opts = parse_opts ( & [ ] ) . unwrap ( ) . unwrap ( ) ;
347
+ run_test ( & opts, false , test, RunStrategy :: SpawnedSecondary , Concurrent :: No ) ;
348
+ unreachable ! ( ) ;
349
+ }
350
+
351
+ let args = env:: args ( ) . collect :: < Vec < _ > > ( ) ;
352
+ let owned_tests: Vec < _ > = tests. iter ( ) . map ( make_owned_test) . collect ( ) ;
353
+ test_main ( & args, owned_tests, Some ( Options :: new ( ) . panic_abort ( true ) ) )
354
+ }
355
+
356
+ /// Clones static values for putting into a dynamic vector, which test_main()
357
+ /// needs to hand out ownership of tests to parallel test runners.
358
+ ///
359
+ /// This will panic when fed any dynamic tests, because they cannot be cloned.
360
+ fn make_owned_test ( test : & & TestDescAndFn ) -> TestDescAndFn {
361
+ match test. testfn {
362
+ StaticTestFn ( f) => TestDescAndFn {
363
+ testfn : StaticTestFn ( f) ,
364
+ desc : test. desc . clone ( ) ,
365
+ } ,
366
+ StaticBenchFn ( f) => TestDescAndFn {
367
+ testfn : StaticBenchFn ( f) ,
368
+ desc : test. desc . clone ( ) ,
369
+ } ,
370
+ _ => panic ! ( "non-static tests passed to test::test_main_static" ) ,
371
+ }
372
+ }
373
+
349
374
/// Invoked when unit tests terminate. Should panic if the unit
350
375
/// Tests is considered a failure. By default, invokes `report()`
351
376
/// and checks for a `0` result.
@@ -1147,8 +1172,7 @@ where
1147
1172
let mut pending = 0 ;
1148
1173
1149
1174
let ( tx, rx) = channel :: < MonitorMsg > ( ) ;
1150
- // TODO
1151
- let run_strategy = if true {
1175
+ let run_strategy = if opts. options . panic_abort {
1152
1176
RunStrategy :: SpawnPrimary ( tx)
1153
1177
} else {
1154
1178
RunStrategy :: InProcess ( tx)
0 commit comments