Skip to content

Commit 6f36f87

Browse files
committed
Put panic=abort test support behind -Z panic_abort_tests
1 parent c396c12 commit 6f36f87

File tree

6 files changed

+30
-1
lines changed

6 files changed

+30
-1
lines changed

src/librustc/session/config.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1295,6 +1295,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12951295
"show extended diagnostic help"),
12961296
terminal_width: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
12971297
"set the current terminal width"),
1298+
panic_abort_tests: bool = (false, parse_bool, [TRACKED],
1299+
"support compiling tests with panic=abort"),
12981300
continue_parse_after_error: bool = (false, parse_bool, [TRACKED],
12991301
"attempt to recover from parse errors (experimental)"),
13001302
dep_tasks: bool = (false, parse_bool, [UNTRACKED],

src/librustc_interface/passes.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ fn configure_and_expand_inner<'a>(
447447
sess.diagnostic(),
448448
&sess.features_untracked(),
449449
sess.panic_strategy(),
450+
sess.opts.debugging_opts.panic_abort_tests,
450451
)
451452
});
452453

src/libsyntax_ext/test_harness.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ pub fn inject(
4343
span_diagnostic: &errors::Handler,
4444
features: &Features,
4545
panic_strategy: PanicStrategy,
46+
enable_panic_abort_tests: bool,
4647
) {
4748
// Check for #![reexport_test_harness_main = "some_name"] which gives the
4849
// main test function the name `some_name` without hygiene. This needs to be
@@ -55,6 +56,10 @@ pub fn inject(
5556
// even in non-test builds
5657
let test_runner = get_test_runner(span_diagnostic, &krate);
5758

59+
let panic_strategy = match (panic_strategy, enable_panic_abort_tests) {
60+
(PanicStrategy::Abort, true) => PanicStrategy::Abort,
61+
_ => PanicStrategy::Unwind,
62+
};
5863
if should_test {
5964
generate_test_harness(sess, resolver, reexport_test_harness_main,
6065
krate, features, panic_strategy, test_runner)
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// no-prefer-dynamic
2+
// compile-flags: --test -Cpanic=abort
3+
// run-flags: --test-threads=1
4+
// run-fail
5+
// check-run-results
6+
7+
#![cfg(test)]
8+
9+
#[test]
10+
fn it_works() {
11+
assert_eq!(1 + 1, 2);
12+
}
13+
14+
#[test]
15+
#[should_panic]
16+
fn it_panics() {
17+
assert_eq!(1 + 1, 4);
18+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
running 2 tests
3+
test it_panics ...

src/test/ui/test-panic-abort.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// no-prefer-dynamic
2-
// compile-flags: --test -Cpanic=abort
2+
// compile-flags: --test -Cpanic=abort -Zpanic_abort_tests
33
// run-flags: --test-threads=1
44
// run-fail
55
// check-run-results

0 commit comments

Comments
 (0)