Skip to content

Commit 4d23c41

Browse files
committed
Test cross-crate runtime contract checks
These tests capture the behaviour that the decision to include/exclude runtime contract assertions is determined on a per-crate basis, i.e. by the flags used to compile each crate.
1 parent a172a66 commit 4d23c41

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
//@ [unchk_pass] compile-flags: -Zcontract-checks=no
2+
//@ [unchk_fail] compile-flags: -Zcontract-checks=yes
3+
//@ [chk_pass] compile-flags: -Zcontract-checks=no
4+
//@ [chk_fail] compile-flags: -Zcontract-checks=yes
5+
6+
#![crate_type = "lib"]
7+
#![feature(contracts)]
8+
9+
extern crate core;
10+
use core::contracts::requires;
11+
12+
/// Example function with a spec to be called across a crate boundary.
13+
#[requires(x > 0)]
14+
pub fn id_if_positive(x: u32) -> u32 {
15+
x
16+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
//@ aux-build:id.rs
2+
//@ revisions: unchk_pass unchk_fail chk_pass chk_fail
3+
//
4+
// The dependency crate `id` can be compiled with runtime contract checking
5+
// enabled independently of whether this crate is compiled with contract checks
6+
// or not.
7+
//
8+
// chk/unchk indicates whether this crate is compiled with contracts or not
9+
// and pass/fail indicates whether the `id` crate is compiled with contract checks.
10+
//
11+
//@ [unchk_pass] run-pass
12+
//@ [unchk_fail] run-crash
13+
//@ [chk_pass] run-pass
14+
//@ [chk_fail] run-crash
15+
//
16+
//
17+
//@ [unchk_pass] compile-flags: -Zcontract-checks=no
18+
//@ [unchk_fail] compile-flags: -Zcontract-checks=no
19+
//@ [chk_pass] compile-flags: -Zcontract-checks=yes
20+
//@ [chk_fail] compile-flags: -Zcontract-checks=yes
21+
22+
extern crate id;
23+
24+
fn main() {
25+
id::id_if_positive(0);
26+
}

0 commit comments

Comments
 (0)