From 3f0254e3cf7656bd3726372106e98532b1575e2d Mon Sep 17 00:00:00 2001 From: Tyler Mandry Date: Thu, 19 Sep 2019 19:33:38 -0700 Subject: [PATCH] Put panic=abort test support behind -Z panic_abort_tests --- src/librustc/session/config.rs | 2 ++ src/librustc_interface/passes.rs | 2 ++ src/libsyntax_ext/test_harness.rs | 16 +++++++++++++++ src/test/ui/panic-runtime/libtest-unwinds.rs | 10 ---------- .../ui/panic-runtime/libtest-unwinds.stderr | 4 ---- src/test/ui/test-panic-abort-disabled.rs | 20 +++++++++++++++++++ src/test/ui/test-panic-abort-disabled.stderr | 4 ++++ src/test/ui/test-panic-abort.rs | 2 +- 8 files changed, 45 insertions(+), 15 deletions(-) delete mode 100644 src/test/ui/panic-runtime/libtest-unwinds.rs delete mode 100644 src/test/ui/panic-runtime/libtest-unwinds.stderr create mode 100644 src/test/ui/test-panic-abort-disabled.rs create mode 100644 src/test/ui/test-panic-abort-disabled.stderr diff --git a/src/librustc/session/config.rs b/src/librustc/session/config.rs index cbb22f1e44830..f56d57847f3d0 100644 --- a/src/librustc/session/config.rs +++ b/src/librustc/session/config.rs @@ -1279,6 +1279,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options, "show extended diagnostic help"), terminal_width: Option = (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], diff --git a/src/librustc_interface/passes.rs b/src/librustc_interface/passes.rs index 41d3b5b52b4a5..8474bae5a71d2 100644 --- a/src/librustc_interface/passes.rs +++ b/src/librustc_interface/passes.rs @@ -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, ) }); diff --git a/src/libsyntax_ext/test_harness.rs b/src/libsyntax_ext/test_harness.rs index dcaf07341e550..f79ad1419e0b1 100644 --- a/src/libsyntax_ext/test_harness.rs +++ b/src/libsyntax_ext/test_harness.rs @@ -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) } diff --git a/src/test/ui/panic-runtime/libtest-unwinds.rs b/src/test/ui/panic-runtime/libtest-unwinds.rs deleted file mode 100644 index bc13072612a29..0000000000000 --- a/src/test/ui/panic-runtime/libtest-unwinds.rs +++ /dev/null @@ -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() { -} diff --git a/src/test/ui/panic-runtime/libtest-unwinds.stderr b/src/test/ui/panic-runtime/libtest-unwinds.stderr deleted file mode 100644 index 704b81ae1ce08..0000000000000 --- a/src/test/ui/panic-runtime/libtest-unwinds.stderr +++ /dev/null @@ -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 - diff --git a/src/test/ui/test-panic-abort-disabled.rs b/src/test/ui/test-panic-abort-disabled.rs new file mode 100644 index 0000000000000..f24046ff0e8d2 --- /dev/null +++ b/src/test/ui/test-panic-abort-disabled.rs @@ -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); +} diff --git a/src/test/ui/test-panic-abort-disabled.stderr b/src/test/ui/test-panic-abort-disabled.stderr new file mode 100644 index 0000000000000..a8d9bad43ed3c --- /dev/null +++ b/src/test/ui/test-panic-abort-disabled.stderr @@ -0,0 +1,4 @@ +error: building tests with panic=abort is not yet supported + +error: aborting due to previous error + diff --git a/src/test/ui/test-panic-abort.rs b/src/test/ui/test-panic-abort.rs index b77bb78b4b170..415ecbf7b38cd 100644 --- a/src/test/ui/test-panic-abort.rs +++ b/src/test/ui/test-panic-abort.rs @@ -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