mirror of
https://github.com/rust-lang/rust.git
synced 2025-09-30 16:26:10 +00:00

And introduce two new directives for ui tests: * `run-crash` * `run-fail-or-crash` Normally a `run-fail` ui test like tests that panic shall not be terminated by a signal like `SIGABRT`. So begin having that as a hard requirement. Some of our current tests do terminate by a signal/crash however. Introduce and use `run-crash` for those tests. Note that Windows crashes are not handled by signals but by certain high bits set on the process exit code. Example exit code for crash on Windows: `0xc000001d`. Because of this, we define "crash" on all platforms as "not exit with success and not exit with a regular failure code in the range 1..=127". Some tests behave differently on different targets: * Targets without unwind support will abort (crash) instead of exit with failure code 101 after panicking. As a special case, allow crashes for `run-fail` tests for such targets. * Different sanitizer implementations handle detected memory problems differently. Some abort (crash) the process while others exit with failure code 1. Introduce and use `run-fail-or-crash` for such tests.
44 lines
1.3 KiB
Rust
44 lines
1.3 KiB
Rust
//@ revisions: unchk_pass unchk_fail_pre unchk_fail_post chk_pass chk_fail_pre chk_fail_post
|
|
//
|
|
//@ [unchk_pass] run-pass
|
|
//@ [unchk_fail_pre] run-pass
|
|
//@ [unchk_fail_post] run-pass
|
|
//@ [chk_pass] run-pass
|
|
//
|
|
//@ [chk_fail_pre] run-crash
|
|
//@ [chk_fail_post] run-crash
|
|
//
|
|
//@ [unchk_pass] compile-flags: -Zcontract-checks=no
|
|
//@ [unchk_fail_pre] compile-flags: -Zcontract-checks=no
|
|
//@ [unchk_fail_post] compile-flags: -Zcontract-checks=no
|
|
//
|
|
//@ [chk_pass] compile-flags: -Zcontract-checks=yes
|
|
//@ [chk_fail_pre] compile-flags: -Zcontract-checks=yes
|
|
//@ [chk_fail_post] compile-flags: -Zcontract-checks=yes
|
|
|
|
#![feature(contracts)]
|
|
//~^ WARN the feature `contracts` is incomplete and may not be safe to use and/or cause compiler crashes [incomplete_features]
|
|
|
|
#[core::contracts::requires(x.baz > 0)]
|
|
#[core::contracts::ensures(|ret| *ret > 100)]
|
|
fn tail(x: Baz) -> i32
|
|
{
|
|
x.baz + 50
|
|
}
|
|
|
|
struct Baz { baz: i32 }
|
|
|
|
const BAZ_PASS_PRE_POST: Baz = Baz { baz: 100 };
|
|
#[cfg(any(unchk_fail_post, chk_fail_post))]
|
|
const BAZ_FAIL_POST: Baz = Baz { baz: 10 };
|
|
#[cfg(any(unchk_fail_pre, chk_fail_pre))]
|
|
const BAZ_FAIL_PRE: Baz = Baz { baz: -10 };
|
|
|
|
fn main() {
|
|
assert_eq!(tail(BAZ_PASS_PRE_POST), 150);
|
|
#[cfg(any(unchk_fail_pre, chk_fail_pre))]
|
|
tail(BAZ_FAIL_PRE);
|
|
#[cfg(any(unchk_fail_post, chk_fail_post))]
|
|
tail(BAZ_FAIL_POST);
|
|
}
|