Skip to content

Commit

Permalink
Put panic=abort test support behind -Z panic_abort_tests
Browse files Browse the repository at this point in the history
  • Loading branch information
tmandry committed Sep 28, 2019
1 parent 8837684 commit 3f0254e
Show file tree
Hide file tree
Showing 8 changed files with 45 additions and 15 deletions.
2 changes: 2 additions & 0 deletions src/librustc/session/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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],
Expand Down
2 changes: 2 additions & 0 deletions src/librustc_interface/passes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
});

Expand Down
16 changes: 16 additions & 0 deletions src/libsyntax_ext/test_harness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)
}
Expand Down
10 changes: 0 additions & 10 deletions src/test/ui/panic-runtime/libtest-unwinds.rs

This file was deleted.

4 changes: 0 additions & 4 deletions src/test/ui/panic-runtime/libtest-unwinds.stderr

This file was deleted.

20 changes: 20 additions & 0 deletions src/test/ui/test-panic-abort-disabled.rs
Original file line number Diff line number Diff line change
@@ -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);
}
4 changes: 4 additions & 0 deletions src/test/ui/test-panic-abort-disabled.stderr
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
error: building tests with panic=abort is not yet supported

error: aborting due to previous error

2 changes: 1 addition & 1 deletion src/test/ui/test-panic-abort.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down

0 comments on commit 3f0254e

Please sign in to comment.