mirror of
https://github.com/rust-lang/rust.git
synced 2025-06-04 19:29:07 +00:00
Put panic=abort test support behind -Z panic_abort_tests
This commit is contained in:
parent
88376842a0
commit
3f0254e3cf
@ -1279,6 +1279,8 @@ options! {DebuggingOptions, DebuggingSetter, basic_debugging_options,
|
|||||||
"show extended diagnostic help"),
|
"show extended diagnostic help"),
|
||||||
terminal_width: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
|
terminal_width: Option<usize> = (None, parse_opt_uint, [UNTRACKED],
|
||||||
"set the current terminal width"),
|
"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],
|
continue_parse_after_error: bool = (false, parse_bool, [TRACKED],
|
||||||
"attempt to recover from parse errors (experimental)"),
|
"attempt to recover from parse errors (experimental)"),
|
||||||
dep_tasks: bool = (false, parse_bool, [UNTRACKED],
|
dep_tasks: bool = (false, parse_bool, [UNTRACKED],
|
||||||
|
@ -441,6 +441,8 @@ fn configure_and_expand_inner<'a>(
|
|||||||
sess.diagnostic(),
|
sess.diagnostic(),
|
||||||
&sess.features_untracked(),
|
&sess.features_untracked(),
|
||||||
sess.panic_strategy(),
|
sess.panic_strategy(),
|
||||||
|
sess.target.target.options.panic_strategy,
|
||||||
|
sess.opts.debugging_opts.panic_abort_tests,
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -43,6 +43,8 @@ pub fn inject(
|
|||||||
span_diagnostic: &errors::Handler,
|
span_diagnostic: &errors::Handler,
|
||||||
features: &Features,
|
features: &Features,
|
||||||
panic_strategy: PanicStrategy,
|
panic_strategy: PanicStrategy,
|
||||||
|
platform_panic_strategy: PanicStrategy,
|
||||||
|
enable_panic_abort_tests: bool,
|
||||||
) {
|
) {
|
||||||
// Check for #![reexport_test_harness_main = "some_name"] which gives the
|
// Check for #![reexport_test_harness_main = "some_name"] which gives the
|
||||||
// main test function the name `some_name` without hygiene. This needs to be
|
// 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);
|
let test_runner = get_test_runner(span_diagnostic, &krate);
|
||||||
|
|
||||||
if should_test {
|
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,
|
generate_test_harness(sess, resolver, reexport_test_harness_main,
|
||||||
krate, features, panic_strategy, test_runner)
|
krate, features, panic_strategy, test_runner)
|
||||||
}
|
}
|
||||||
|
@ -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() {
|
|
||||||
}
|
|
@ -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
|
|
||||||
|
|
20
src/test/ui/test-panic-abort-disabled.rs
Normal file
20
src/test/ui/test-panic-abort-disabled.rs
Normal 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);
|
||||||
|
}
|
4
src/test/ui/test-panic-abort-disabled.stderr
Normal file
4
src/test/ui/test-panic-abort-disabled.stderr
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
error: building tests with panic=abort is not yet supported
|
||||||
|
|
||||||
|
error: aborting due to previous error
|
||||||
|
|
@ -1,5 +1,5 @@
|
|||||||
// no-prefer-dynamic
|
// no-prefer-dynamic
|
||||||
// compile-flags: --test -Cpanic=abort
|
// compile-flags: --test -Cpanic=abort -Zpanic_abort_tests
|
||||||
// run-flags: --test-threads=1
|
// run-flags: --test-threads=1
|
||||||
// run-fail
|
// run-fail
|
||||||
// check-run-results
|
// check-run-results
|
||||||
|
Loading…
Reference in New Issue
Block a user