-
Notifications
You must be signed in to change notification settings - Fork 84
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add tests for issues related to std linking (#1801)
Add tests for #564, #208 and #87. Unfortunately, it looks like there are still issues with with how we are encoding panic threads and dynamic objects which are causing two of the test cases to fail.
- Loading branch information
Showing
3 changed files
with
81 additions
and
4 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
// Copyright Kani Contributors | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
|
||
//! This test was created to cover panic hook handling by Kani. | ||
//! Tracking issue: <https://github.com/model-checking/kani/issues/208> | ||
use std::panic; | ||
|
||
#[kani::proof] | ||
#[kani::unwind(2)] | ||
fn custom_hook() { | ||
panic::set_hook(Box::new(|_| { | ||
assert!(false); | ||
})); | ||
|
||
let _ = panic::take_hook(); | ||
|
||
panic!("Normal panic"); | ||
} |
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,50 @@ | ||
// SPDX-License-Identifier: Apache-2.0 OR MIT | ||
// | ||
// Modifications Copyright Kani Contributors | ||
// See GitHub history for details. | ||
|
||
//! This test is to check how Kani handle some std functions. The original issue was: | ||
//! <https://github.com/model-checking/kani/issues/564> | ||
//! This code was extracted from Rust by Example book. | ||
trait UsernameWidget { | ||
// Get the selected username out of this widget | ||
fn get(&self) -> String; | ||
} | ||
|
||
trait AgeWidget { | ||
// Get the selected age out of this widget | ||
fn get(&self) -> u8; | ||
} | ||
|
||
// A form with both a UsernameWidget and an AgeWidget | ||
struct Form { | ||
username: String, | ||
age: u8, | ||
} | ||
|
||
impl UsernameWidget for Form { | ||
fn get(&self) -> String { | ||
self.username.clone() | ||
} | ||
} | ||
|
||
impl AgeWidget for Form { | ||
fn get(&self) -> u8 { | ||
self.age | ||
} | ||
} | ||
|
||
#[kani::proof] | ||
pub fn main() { | ||
let form = Form { username: "rustacean".to_owned(), age: 28 }; | ||
|
||
// If you uncomment this line, you'll get an error saying | ||
// "multiple `get` found". Because, after all, there are multiple methods | ||
// named `get`. | ||
// println!("{}", form.get()); | ||
|
||
let username = <Form as UsernameWidget>::get(&form); | ||
assert_eq!("rustacean".to_owned(), username); | ||
let age = <Form as AgeWidget>::get(&form); | ||
assert_eq!(28, age); | ||
} |