Skip to content

Commit 1c0a6f9

Browse files
authored
Merge pull request #29 from os-checker/test-proof-for-contract
Test: support of `#[kani::proof_for_contract]`
2 parents 399c079 + 9534240 commit 1c0a6f9

File tree

5 files changed

+5136
-5
lines changed

5 files changed

+5136
-5
lines changed

tests/proofs.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,13 @@ fn test_proofs() -> eyre::Result<()> {
1414
}
1515
}
1616

17+
proofs.sort();
1718
expect![[r#"
1819
[
19-
"tests/proofs/standard_proofs_with_contracts.rs",
20-
"tests/proofs/standard_proofs.rs",
2120
"tests/proofs/ad_hoc.rs",
21+
"tests/proofs/proofs_for_contract.rs",
22+
"tests/proofs/standard_proofs.rs",
23+
"tests/proofs/standard_proofs_with_contracts.rs",
2224
]
2325
"#]]
2426
.assert_debug_eq(&proofs);
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#[cfg(kani)]
2+
mod verify {
3+
#[kani::requires(a > 0)]
4+
fn contract_requires(a: u8) {}
5+
6+
#[kani::proof_for_contract(contract_requires)]
7+
fn single_contract_requires() {
8+
contract_requires(0);
9+
}
10+
11+
#[kani::ensures(|&ret| ret > 0)]
12+
fn contract_ensures(a: u8) -> u8 {
13+
a
14+
}
15+
16+
#[kani::proof_for_contract(contract_ensures)]
17+
fn single_with_contract_ensures() {
18+
contract_ensures(0);
19+
}
20+
21+
#[kani::proof_for_contract(contract_requires)]
22+
fn two_contracts_requires_and_ensures() {
23+
let val = contract_ensures(0);
24+
contract_requires(val);
25+
}
26+
27+
#[kani::requires(a > 0)]
28+
#[kani::ensures(|&ret| ret > 0)]
29+
fn contract(a: u8) -> u8 {
30+
a
31+
}
32+
33+
#[kani::proof_for_contract(contract)]
34+
fn single_contract() {
35+
let val = contract(1);
36+
assert!(val > 0);
37+
}
38+
}

tests/proofs/standard_proofs_with_contracts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ mod verify {
2121
#[kani::proof]
2222
fn two_contracts_requires_and_ensures() {
2323
let val = contract_ensures(0);
24-
contract_ensures(val);
24+
contract_requires(val);
2525
}
2626

2727
#[kani::requires(a > 0)]

0 commit comments

Comments
 (0)