Skip to content

Commit 3f0254e

Browse files
committed
Put panic=abort test support behind -Z panic_abort_tests
1 parent 8837684 commit 3f0254e

File tree

8 files changed

+45
-15
lines changed

8 files changed

+45
-15
lines changed

src/librustc/session/config.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
12791279
"show extended diagnostic help"),
12801280
terminal_width: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
12811281
"set the current terminal width"),
1282+
panic_abort_tests: bool = (false, parse_bool, [TRACKED],
1283+
"support compiling tests with panic=abort"),
12821284
continue_parse_after_error: bool = (false, parse_bool, [TRACKED],
12831285
"attempt to recover from parse errors (experimental)"),
12841286
dep_tasks: bool = (false, parse_bool, [UNTRACKED],

src/librustc_interface/passes.rs

+2
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,8 @@ fn configure_and_expand_inner<'a>(
441441
sess.diagnostic(),
442442
&sess.features_untracked(),
443443
sess.panic_strategy(),
444+
sess.target.target.options.panic_strategy,
445+
sess.opts.debugging_opts.panic_abort_tests,
444446
)
445447
});
446448

src/libsyntax_ext/test_harness.rs

+16
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,8 @@ pub fn inject(
4343
span_diagnostic: &errors::Handler,
4444
features: &Features,
4545
panic_strategy: PanicStrategy,
46+
platform_panic_strategy: PanicStrategy,
47+
enable_panic_abort_tests: bool,
4648
) {
4749
// Check for #![reexport_test_harness_main = "some_name"] which gives the
4850
// main test function the name `some_name` without hygiene. This needs to be
@@ -56,6 +58,20 @@ pub fn inject(
5658
let test_runner = get_test_runner(span_diagnostic, &krate);
5759

5860
if should_test {
61+
let panic_strategy = match (panic_strategy, enable_panic_abort_tests) {
62+
(PanicStrategy::Abort, true) =>
63+
PanicStrategy::Abort,
64+
(PanicStrategy::Abort, false) if panic_strategy == platform_panic_strategy => {
65+
// Silently allow compiling with panic=abort on these platforms,
66+
// but with old behavior (abort if a test fails).
67+
PanicStrategy::Unwind
68+
}
69+
(PanicStrategy::Abort, false) => {
70+
span_diagnostic.err("building tests with panic=abort is not yet supported");
71+
PanicStrategy::Unwind
72+
}
73+
(PanicStrategy::Unwind, _) => PanicStrategy::Unwind,
74+
};
5975
generate_test_harness(sess, resolver, reexport_test_harness_main,
6076
krate, features, panic_strategy, test_runner)
6177
}

src/test/ui/panic-runtime/libtest-unwinds.rs

-10
This file was deleted.

src/test/ui/panic-runtime/libtest-unwinds.stderr

-4
This file was deleted.
+20
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// error-pattern:building tests with panic=abort is not yet supported
2+
// no-prefer-dynamic
3+
// compile-flags: --test -Cpanic=abort
4+
// run-flags: --test-threads=1
5+
6+
// ignore-wasm no panic or subprocess support
7+
// ignore-emscripten no panic or subprocess support
8+
9+
#![cfg(test)]
10+
11+
#[test]
12+
fn it_works() {
13+
assert_eq!(1 + 1, 2);
14+
}
15+
16+
#[test]
17+
#[should_panic]
18+
fn it_panics() {
19+
assert_eq!(1 + 1, 4);
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
error: building tests with panic=abort is not yet supported
2+
3+
error: aborting due to previous error
4+

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

+1-1
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)