22
33use log:: debug;
44use smallvec:: { smallvec, SmallVec } ;
5+ use rustc_target:: spec:: PanicStrategy ;
56use syntax:: ast:: { self , Ident } ;
67use syntax:: attr;
78use syntax:: entry:: { self , EntryPointType } ;
@@ -25,6 +26,7 @@ struct Test {
2526
2627struct TestCtxt < ' a > {
2728 ext_cx : ExtCtxt < ' a > ,
29+ panic_strategy : PanicStrategy ,
2830 def_site : Span ,
2931 test_cases : Vec < Test > ,
3032 reexport_test_harness_main : Option < Symbol > ,
@@ -40,6 +42,8 @@ pub fn inject(
4042 krate : & mut ast:: Crate ,
4143 span_diagnostic : & errors:: Handler ,
4244 features : & Features ,
45+ panic_strategy : PanicStrategy ,
46+ enable_panic_abort_tests : bool ,
4347) {
4448 // Check for #![reexport_test_harness_main = "some_name"] which gives the
4549 // main test function the name `some_name` without hygiene. This needs to be
@@ -52,9 +56,13 @@ pub fn inject(
5256 // even in non-test builds
5357 let test_runner = get_test_runner ( span_diagnostic, & krate) ;
5458
59+ let panic_strategy = match ( panic_strategy, enable_panic_abort_tests) {
60+ ( PanicStrategy :: Abort , true ) => PanicStrategy :: Abort ,
61+ _ => PanicStrategy :: Unwind ,
62+ } ;
5563 if should_test {
5664 generate_test_harness ( sess, resolver, reexport_test_harness_main,
57- krate, features, test_runner)
65+ krate, features, panic_strategy , test_runner)
5866 }
5967}
6068
@@ -183,6 +191,7 @@ fn generate_test_harness(sess: &ParseSess,
183191 reexport_test_harness_main : Option < Symbol > ,
184192 krate : & mut ast:: Crate ,
185193 features : & Features ,
194+ panic_strategy : PanicStrategy ,
186195 test_runner : Option < ast:: Path > ) {
187196 let mut econfig = ExpansionConfig :: default ( "test" . to_string ( ) ) ;
188197 econfig. features = Some ( features) ;
@@ -203,6 +212,7 @@ fn generate_test_harness(sess: &ParseSess,
203212
204213 let cx = TestCtxt {
205214 ext_cx,
215+ panic_strategy,
206216 def_site,
207217 test_cases : Vec :: new ( ) ,
208218 reexport_test_harness_main,
@@ -248,9 +258,14 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
248258 let ecx = & cx. ext_cx ;
249259 let test_id = Ident :: new ( sym:: test, sp) ;
250260
261+ let runner_name = match cx. panic_strategy {
262+ PanicStrategy :: Unwind => "test_main_static" ,
263+ PanicStrategy :: Abort => "test_main_static_abort" ,
264+ } ;
265+
251266 // test::test_main_static(...)
252267 let mut test_runner = cx. test_runner . clone ( ) . unwrap_or (
253- ecx. path ( sp, vec ! [ test_id, ecx. ident_of( "test_main_static" , sp) ] ) ) ;
268+ ecx. path ( sp, vec ! [ test_id, ecx. ident_of( runner_name , sp) ] ) ) ;
254269
255270 test_runner. span = sp;
256271
0 commit comments