2
2
3
3
use log:: debug;
4
4
use smallvec:: { smallvec, SmallVec } ;
5
+ use rustc_target:: spec:: PanicStrategy ;
5
6
use syntax:: ast:: { self , Ident } ;
6
7
use syntax:: attr;
7
8
use syntax:: entry:: { self , EntryPointType } ;
@@ -25,6 +26,7 @@ struct Test {
25
26
26
27
struct TestCtxt < ' a > {
27
28
ext_cx : ExtCtxt < ' a > ,
29
+ panic_strategy : PanicStrategy ,
28
30
def_site : Span ,
29
31
test_cases : Vec < Test > ,
30
32
reexport_test_harness_main : Option < Symbol > ,
@@ -40,6 +42,7 @@ pub fn inject(
40
42
krate : & mut ast:: Crate ,
41
43
span_diagnostic : & errors:: Handler ,
42
44
features : & Features ,
45
+ panic_strategy : PanicStrategy ,
43
46
) {
44
47
// Check for #![reexport_test_harness_main = "some_name"] which gives the
45
48
// main test function the name `some_name` without hygiene. This needs to be
@@ -54,7 +57,7 @@ pub fn inject(
54
57
55
58
if should_test {
56
59
generate_test_harness ( sess, resolver, reexport_test_harness_main,
57
- krate, features, test_runner)
60
+ krate, features, panic_strategy , test_runner)
58
61
}
59
62
}
60
63
@@ -183,6 +186,7 @@ fn generate_test_harness(sess: &ParseSess,
183
186
reexport_test_harness_main : Option < Symbol > ,
184
187
krate : & mut ast:: Crate ,
185
188
features : & Features ,
189
+ panic_strategy : PanicStrategy ,
186
190
test_runner : Option < ast:: Path > ) {
187
191
let mut econfig = ExpansionConfig :: default ( "test" . to_string ( ) ) ;
188
192
econfig. features = Some ( features) ;
@@ -203,6 +207,7 @@ fn generate_test_harness(sess: &ParseSess,
203
207
204
208
let cx = TestCtxt {
205
209
ext_cx,
210
+ panic_strategy,
206
211
def_site,
207
212
test_cases : Vec :: new ( ) ,
208
213
reexport_test_harness_main,
@@ -248,9 +253,14 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
248
253
let ecx = & cx. ext_cx ;
249
254
let test_id = Ident :: new ( sym:: test, sp) ;
250
255
256
+ let runner_name = match cx. panic_strategy {
257
+ PanicStrategy :: Unwind => "test_main_static" ,
258
+ PanicStrategy :: Abort => "test_main_static_abort" ,
259
+ } ;
260
+
251
261
// test::test_main_static(...)
252
262
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) ] ) ) ;
254
264
255
265
test_runner. span = sp;
256
266
0 commit comments