Skip to content

Commit

Permalink
Add test basic cases
Browse files Browse the repository at this point in the history
  • Loading branch information
JustusAdam committed Feb 5, 2024
1 parent 8f6eb3e commit 5057572
Show file tree
Hide file tree
Showing 8 changed files with 105 additions and 0 deletions.
11 changes: 11 additions & 0 deletions tests/expected/function-contract/history/clone_fail.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
error[E0382]: borrow of moved value: `ptr`
value borrowed here after move\
move occurs because `ptr` has type `&mut NoCopy<u32>`, which does not implement the `Copy` trait

error[E0382]: borrow of moved value: `ptr`
#[kani::ensures(old(ptr).0 + 1 == ptr.0)]\
value moved here
#[kani::modifies(&mut ptr.0)]\
value borrowed here after move\
fn modify(ptr: &mut NoCopy<u32>) {\
move occurs because `ptr` has type `&mut NoCopy<u32>`, which does not implement the `Copy` trait
24 changes: 24 additions & 0 deletions tests/expected/function-contract/history/clone_fail.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT
// kani-flags: -Zfunction-contracts

struct NoCopy<T>(T);

impl<T: kani::Arbitrary> kani::Arbitrary for NoCopy<T> {
fn any() -> Self {
Self(kani::any())
}
}

#[kani::ensures(old(ptr).0 + 1 == ptr.0)]
#[kani::requires(ptr.0 < 100)]
#[kani::modifies(&mut ptr.0)]
fn modify(ptr: &mut NoCopy<u32>) {
ptr.0 += 1;
}

#[kani::proof_for_contract(modify)]
fn main() {
let mut i = kani::any();
modify(&mut i);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VERIFICATION:- SUCCESSFUL
25 changes: 25 additions & 0 deletions tests/expected/function-contract/history/clone_pass.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT
// kani-flags: -Zfunction-contracts

#[derive(Clone)]
struct NoCopy<T>(T);

impl<T: kani::Arbitrary> kani::Arbitrary for NoCopy<T> {
fn any() -> Self {
Self(kani::any())
}
}

#[kani::ensures(old(ptr.clone()).0 + 1 == ptr.0)]
#[kani::requires(ptr.0 < 100)]
#[kani::modifies(&mut ptr.0)]
fn modify(ptr: &mut NoCopy<u32>) {
ptr.0 += 1;
}

#[kani::proof_for_contract(modify)]
fn main() {
let mut i = kani::any();
modify(&mut i);
}
7 changes: 7 additions & 0 deletions tests/expected/function-contract/history/simple_fail.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
assertion\
- Status: FAILURE\
- Description: "old(*ptr) == *ptr"

Failed Checks: old(*ptr) == *ptr

VERIFICATION:- FAILED
16 changes: 16 additions & 0 deletions tests/expected/function-contract/history/simple_fail.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT
// kani-flags: -Zfunction-contracts

#[kani::ensures(old(*ptr) == *ptr)]
#[kani::requires(*ptr < 100)]
#[kani::modifies(ptr)]
fn modify(ptr: &mut u32) {
*ptr += 1;
}

#[kani::proof_for_contract(modify)]
fn main() {
let mut i = kani::any();
modify(&mut i);
}
5 changes: 5 additions & 0 deletions tests/expected/function-contract/history/simple_pass.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
assertion\
- Status: SUCCESS\
- Description: "old(*ptr + 1) == *ptr"\

VERIFICATION:- SUCCESSFUL
16 changes: 16 additions & 0 deletions tests/expected/function-contract/history/simple_pass.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Copyright Kani Contributors
// SPDX-License-Identifier: Apache-2.0 OR MIT
// kani-flags: -Zfunction-contracts

#[kani::ensures(old(*ptr + 1) == *ptr)]
#[kani::requires(*ptr < 100)]
#[kani::modifies(ptr)]
fn modify(ptr: &mut u32) {
*ptr += 1;
}

#[kani::proof_for_contract(modify)]
fn main() {
let mut i = kani::any();
modify(&mut i);
}

0 comments on commit 5057572

Please sign in to comment.