-
Notifications
You must be signed in to change notification settings - Fork 99
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add implementation for the
#[kani::should_panic]
attribute (#2315)
- Loading branch information
1 parent
38d1f6f
commit bd1ac2d
Showing
19 changed files
with
236 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
error: custom attribute panicked | ||
#[kani::proof] does not take any arguments for now | ||
#[kani::proof] does not take any arguments currently | ||
|
||
error: custom attribute panicked | ||
#[kani::proof] cannot be applied to async functions that take inputs for now |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
** 2 of 2 failed\ | ||
Failed Checks: panicked on the `if` branch! | ||
Failed Checks: panicked on the `else` branch! | ||
VERIFICATION:- SUCCESSFUL (encountered one or more panics as expected) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
//! Checks that verfication passes when `#[kani::should_panic]` is used and all | ||
//! failures encountered are panics. | ||
#[kani::proof] | ||
#[kani::should_panic] | ||
fn check() { | ||
if kani::any() { | ||
panic!("panicked on the `if` branch!"); | ||
} else { | ||
panic!("panicked on the `else` branch!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
error: only one '#[kani::should_panic]' attribute is allowed per harness | ||
error: aborting due to previous error |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
//! Checks that `#[kani::should_panic]` can only be used once. | ||
#[kani::proof] | ||
#[kani::should_panic] | ||
#[kani::should_panic] | ||
fn check() {} |
1 change: 1 addition & 0 deletions
1
tests/ui/should-panic-attribute/multiple-harnesses-panic/expected
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
Complete - 3 successfully verified harnesses, 0 failures, 3 total. |
23 changes: 23 additions & 0 deletions
23
tests/ui/should-panic-attribute/multiple-harnesses-panic/test.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
//! Checks that the verification summary printed at the end considers all | ||
//! harnesses as "successfully verified". | ||
#[kani::proof] | ||
#[kani::should_panic] | ||
fn harness1() { | ||
panic!("panicked on `harness1`!"); | ||
} | ||
|
||
#[kani::proof] | ||
#[kani::should_panic] | ||
fn harness2() { | ||
panic!("panicked on `harness2`!"); | ||
} | ||
|
||
#[kani::proof] | ||
#[kani::should_panic] | ||
fn harness3() { | ||
panic!("panicked on `harness3`!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
- Status: SUCCESS\ | ||
- Description: "assertion failed: 1 + 1 == 2" | ||
** 0 of 1 failed | ||
VERIFICATION:- FAILED (encountered no panics, but at least one was expected) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
//! Checks that verfication fails when `#[kani::should_panic]` is used and no | ||
//! panics are encountered. | ||
#[kani::proof] | ||
#[kani::should_panic] | ||
fn check() { | ||
assert!(1 + 1 == 2); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
overflow.undefined-shift.1\ | ||
- Status: FAILURE\ | ||
- Description: "shift distance too large" | ||
Failed Checks: attempt to shift left with overflow | ||
Failed Checks: panicked on the `1` arm! | ||
Failed Checks: panicked on the `0` arm! | ||
Failed Checks: shift distance too large | ||
VERIFICATION:- FAILED (encountered failures other than panics, which were unexpected) |
23 changes: 23 additions & 0 deletions
23
tests/ui/should-panic-attribute/unexpected-failures/test.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
//! Checks that verfication fails when `#[kani::should_panic]` is used but not | ||
//! all failures encountered are panics. | ||
fn trigger_overflow() { | ||
let x: u32 = kani::any(); | ||
let _ = 42 << x; | ||
} | ||
|
||
#[kani::proof] | ||
#[kani::should_panic] | ||
fn check() { | ||
match kani::any() { | ||
0 => panic!("panicked on the `0` arm!"), | ||
1 => panic!("panicked on the `1` arm!"), | ||
_ => { | ||
trigger_overflow(); | ||
() | ||
} | ||
} | ||
} |
Oops, something went wrong.