Put panic=abort test support behind -Z panic_abort_tests

This commit is contained in:
Tyler Mandry 2019-09-19 19:33:38 -07:00
parent 88376842a0
commit 3f0254e3cf
8 changed files with 45 additions and 15 deletions

View file

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

View file

@ -441,6 +441,8 @@ fn configure_and_expand_inner<'a>(
sess.diagnostic(),
&sess.features_untracked(),
sess.panic_strategy(),
sess.target.target.options.panic_strategy,
sess.opts.debugging_opts.panic_abort_tests,
)
});

View file

@ -43,6 +43,8 @@ pub fn inject(
span_diagnostic: &errors::Handler,
features: &Features,
panic_strategy: PanicStrategy,
platform_panic_strategy: PanicStrategy,
enable_panic_abort_tests: bool,
) {
// Check for #![reexport_test_harness_main = "some_name"] which gives the
// main test function the name `some_name` without hygiene. This needs to be
@ -56,6 +58,20 @@ pub fn inject(
let test_runner = get_test_runner(span_diagnostic, &krate);
if should_test {
let panic_strategy = match (panic_strategy, enable_panic_abort_tests) {
(PanicStrategy::Abort, true) =>
PanicStrategy::Abort,
(PanicStrategy::Abort, false) if panic_strategy == platform_panic_strategy => {
// Silently allow compiling with panic=abort on these platforms,
// but with old behavior (abort if a test fails).
PanicStrategy::Unwind
}
(PanicStrategy::Abort, false) => {
span_diagnostic.err("building tests with panic=abort is not yet supported");
PanicStrategy::Unwind
}
(PanicStrategy::Unwind, _) => PanicStrategy::Unwind,
};
generate_test_harness(sess, resolver, reexport_test_harness_main,
krate, features, panic_strategy, test_runner)
}

View file

@ -1,10 +0,0 @@
// error-pattern:is not compiled with this crate's panic strategy `abort`
// compile-flags:-C panic=abort
// ignore-wasm32-bare compiled with panic=abort by default
#![feature(test)]
extern crate test;
fn main() {
}

View file

@ -1,4 +0,0 @@
error: the linked panic runtime `panic_unwind` is not compiled with this crate's panic strategy `abort`
error: aborting due to previous error

View file

@ -0,0 +1,20 @@
// error-pattern:building tests with panic=abort is not yet supported
// no-prefer-dynamic
// compile-flags: --test -Cpanic=abort
// run-flags: --test-threads=1
// ignore-wasm no panic or subprocess support
// ignore-emscripten no panic or subprocess support
#![cfg(test)]
#[test]
fn it_works() {
assert_eq!(1 + 1, 2);
}
#[test]
#[should_panic]
fn it_panics() {
assert_eq!(1 + 1, 4);
}

View file

@ -0,0 +1,4 @@
error: building tests with panic=abort is not yet supported
error: aborting due to previous error

View file

@ -1,5 +1,5 @@
// no-prefer-dynamic
// compile-flags: --test -Cpanic=abort
// compile-flags: --test -Cpanic=abort -Zpanic_abort_tests
// run-flags: --test-threads=1
// run-fail
// check-run-results