|
| 1 | +// Copyright Kani Contributors |
| 2 | +// SPDX-License-Identifier: Apache-2.0 OR MIT |
| 3 | + |
| 4 | +//! This package is intended to assist in manually testing the features of the |
| 5 | +//! extension. The tests to be performed are the following: |
| 6 | +//! |
| 7 | +//! 1. Run verification for `test_success` and check that it passes. |
| 8 | +//! 2. Run verification for `test_failure` and check that it fails with |
| 9 | +//! "assertion failed: x < 4096". |
| 10 | +//! 3. Click on "Generate concrete test for test_failure" and check that a new |
| 11 | +//! Rust unit test is added after "test_failure". |
| 12 | +//! 4. Check that the actions "Run Test (Kani)" and "Debug Harness (Kani)" |
| 13 | +//! appear above the Rust unit test that was generated in the previous step. |
| 14 | +//! 5. Click on the "Run Test (Kani)" action. Check that the test runs on a |
| 15 | +//! terminal and it panics as expected. |
| 16 | +//! 6. Click on the "Debug Harness (Kani)" action. Check that the debugging mode |
| 17 | +//! is started (debugging controls should appear on the top) and stop it by |
| 18 | +//! clicking on the red square button. |
| 19 | +//! 7. Toggle on the "Codelens-kani: Highlight" option in "Settings > Kani". |
| 20 | +//! 8. Check that the "Get coverage info" action appears for the "test_success" |
| 21 | +//! and "test_failure" harnesses. |
| 22 | +//! 9. Run the "Get coverage info" action for "test_coverage". Check that all |
| 23 | +//! lines in "test_coverage" are green. In addition, check that in |
| 24 | +//! "funs::find_index": |
| 25 | +//! - The first and last highlighted lines are yellow. |
| 26 | +//! - The second and third highlighted lines are green. |
| 27 | +//! - The remaining highlighted line is red. |
| 28 | +//! Comments indicating the correct colors are available in "funs::find_index". |
| 29 | +mod funs; |
| 30 | + |
| 31 | +#[cfg(kani)] |
| 32 | +mod verify { |
| 33 | + use super::*; |
| 34 | + |
| 35 | + #[kani::proof] |
| 36 | + fn test_success() { |
| 37 | + let x: u32 = kani::any(); |
| 38 | + kani::assume(x < 4096); |
| 39 | + let y = funs::estimate_size(x); |
| 40 | + assert!(y < 10); |
| 41 | + } |
| 42 | + |
| 43 | + #[kani::proof] |
| 44 | + fn test_failure() { |
| 45 | + let x: u32 = kani::any(); |
| 46 | + let y = funs::estimate_size(x); |
| 47 | + assert!(y < 10); |
| 48 | + } |
| 49 | + |
| 50 | + #[kani::proof] |
| 51 | + fn test_coverage() { |
| 52 | + let numbers = [10, 20, 30, 40, 50]; |
| 53 | + let target = 30; |
| 54 | + let result = funs::find_index(&numbers, target); |
| 55 | + assert_eq!(result, Some(2)); |
| 56 | + } |
| 57 | +} |
0 commit comments