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,7 @@ pub fn inject(
4042 krate : & mut ast:: Crate ,
4143 span_diagnostic : & errors:: Handler ,
4244 features : & Features ,
45+ panic_strategy : PanicStrategy ,
4346) {
4447 // Check for #![reexport_test_harness_main = "some_name"] which gives the
4548 // main test function the name `some_name` without hygiene. This needs to be
@@ -54,7 +57,7 @@ pub fn inject(
5457
5558 if should_test {
5659 generate_test_harness ( sess, resolver, reexport_test_harness_main,
57- krate, features, test_runner)
60+ krate, features, panic_strategy , test_runner)
5861 }
5962}
6063
@@ -183,6 +186,7 @@ fn generate_test_harness(sess: &ParseSess,
183186 reexport_test_harness_main : Option < Symbol > ,
184187 krate : & mut ast:: Crate ,
185188 features : & Features ,
189+ panic_strategy : PanicStrategy ,
186190 test_runner : Option < ast:: Path > ) {
187191 let mut econfig = ExpansionConfig :: default ( "test" . to_string ( ) ) ;
188192 econfig. features = Some ( features) ;
@@ -203,6 +207,7 @@ fn generate_test_harness(sess: &ParseSess,
203207
204208 let cx = TestCtxt {
205209 ext_cx,
210+ panic_strategy,
206211 def_site,
207212 test_cases : Vec :: new ( ) ,
208213 reexport_test_harness_main,
@@ -248,9 +253,14 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
248253 let ecx = & cx. ext_cx ;
249254 let test_id = Ident :: new ( sym:: test, sp) ;
250255
256+ let runner_name = match cx. panic_strategy {
257+ PanicStrategy :: Unwind => "test_main_static" ,
258+ PanicStrategy :: Abort => "test_main_static_abort" ,
259+ } ;
260+
251261 // test::test_main_static(...)
252262 let mut test_runner = cx. test_runner . clone ( ) . unwrap_or (
253- ecx. path ( sp, vec ! [ test_id, ecx. ident_of( "test_main_static" , sp) ] ) ) ;
263+ ecx. path ( sp, vec ! [ test_id, ecx. ident_of( runner_name , sp) ] ) ) ;
254264
255265 test_runner. span = sp;
256266
0 commit comments