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,8 @@ pub fn inject(
40
42
krate : & mut ast:: Crate ,
41
43
span_diagnostic : & errors:: Handler ,
42
44
features : & Features ,
45
+ panic_strategy : PanicStrategy ,
46
+ enable_panic_abort_tests : bool ,
43
47
) {
44
48
// Check for #![reexport_test_harness_main = "some_name"] which gives the
45
49
// main test function the name `some_name` without hygiene. This needs to be
@@ -52,9 +56,13 @@ pub fn inject(
52
56
// even in non-test builds
53
57
let test_runner = get_test_runner ( span_diagnostic, & krate) ;
54
58
59
+ let panic_strategy = match ( panic_strategy, enable_panic_abort_tests) {
60
+ ( PanicStrategy :: Abort , true ) => PanicStrategy :: Abort ,
61
+ _ => PanicStrategy :: Unwind ,
62
+ } ;
55
63
if should_test {
56
64
generate_test_harness ( sess, resolver, reexport_test_harness_main,
57
- krate, features, test_runner)
65
+ krate, features, panic_strategy , test_runner)
58
66
}
59
67
}
60
68
@@ -183,6 +191,7 @@ fn generate_test_harness(sess: &ParseSess,
183
191
reexport_test_harness_main : Option < Symbol > ,
184
192
krate : & mut ast:: Crate ,
185
193
features : & Features ,
194
+ panic_strategy : PanicStrategy ,
186
195
test_runner : Option < ast:: Path > ) {
187
196
let mut econfig = ExpansionConfig :: default ( "test" . to_string ( ) ) ;
188
197
econfig. features = Some ( features) ;
@@ -203,6 +212,7 @@ fn generate_test_harness(sess: &ParseSess,
203
212
204
213
let cx = TestCtxt {
205
214
ext_cx,
215
+ panic_strategy,
206
216
def_site,
207
217
test_cases : Vec :: new ( ) ,
208
218
reexport_test_harness_main,
@@ -248,9 +258,14 @@ fn mk_main(cx: &mut TestCtxt<'_>) -> P<ast::Item> {
248
258
let ecx = & cx. ext_cx ;
249
259
let test_id = Ident :: new ( sym:: test, sp) ;
250
260
261
+ let runner_name = match cx. panic_strategy {
262
+ PanicStrategy :: Unwind => "test_main_static" ,
263
+ PanicStrategy :: Abort => "test_main_static_abort" ,
264
+ } ;
265
+
251
266
// test::test_main_static(...)
252
267
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) ] ) ) ;
254
269
255
270
test_runner. span = sp;
256
271
0 commit comments