Skip to content

Commit f2d9efb

Browse files
authored
Documentation: Change first-steps examples structure (rust-lang#1147)
* Documentation: Change `first-steps` examples structure * Use version numbers
1 parent 9416c03 commit f2d9efb

File tree

8 files changed

+27
-18
lines changed

8 files changed

+27
-18
lines changed

docs/src/tutorial-first-steps.md

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ Kani is unlike the testing tools you may already be familiar with.
44
Much of testing is concerned with thinking of new corner cases that need to be covered.
55
With Kani, all the corner cases are covered from the start, and the new concern is narrowing down the scope to something manageable for the checker.
66

7-
Consider this first program (which can be found under [`kani-first-steps`](https://github.com/model-checking/kani/tree/main/docs/src/tutorial/kani-first-steps/)):
7+
Consider this first program (which can be found under [`first-steps-v1`](https://github.com/model-checking/kani/tree/main/docs/src/tutorial/first-steps-v1/)):
88

99
```rust,noplaypen
10-
{{#include tutorial/kani-first-steps/src/lib.rs:code}}
10+
{{#include tutorial/first-steps-v1/src/main.rs:code}}
1111
```
1212

1313
Think about the test harness you would need to write to test this function.
@@ -18,7 +18,7 @@ And if this function was more complicated—for example, if some of the branches
1818
We can try to property test a function like this, but if we're naive about it (and consider all possible `u32` inputs), then it's unlikely we'll ever find the bug.
1919

2020
```rust,noplaypen
21-
{{#include tutorial/kani-first-steps/src/lib.rs:proptest}}
21+
{{#include tutorial/first-steps-v1/src/main.rs:proptest}}
2222
```
2323

2424
```
@@ -32,7 +32,7 @@ There's only 1 in 4 billion inputs that fail, so it's vanishingly unlikely the p
3232
With Kani, however, we can use `kani::any()` to represent all possible `u32` values:
3333

3434
```rust,noplaypen
35-
{{#include tutorial/kani-first-steps/src/lib.rs:kani}}
35+
{{#include tutorial/first-steps-v1/src/main.rs:kani}}
3636
```
3737

3838
```
@@ -60,10 +60,10 @@ Here, we've just got some nondeterministic inputs up front, but that's something
6060
To see traces, run:
6161

6262
```
63-
kani --visualize src/lib.rs
63+
kani --visualize src/main.rs
6464
```
6565

66-
This command runs Kani and generates the HTML report in `report/html/index.html`.
66+
This command runs Kani and generates the HTML report in `report-main/html/index.html`.
6767
Open the report with your preferred browser.
6868
From this report, we can find the trace of the failure and filter through it to find the relevant line (at present time, an unfortunate amount of generated code is present in the trace):
6969

@@ -143,10 +143,11 @@ VERIFICATION:- FAILED
143143
## Assertions, Assumptions, and Harnesses
144144

145145
It seems a bit odd that we can take billions of inputs when our function only handles up to a few thousand.
146-
Let's encode this fact about our function by asserting some reasonable bound on our input, after we've fixed our bug:
146+
Let's encode this fact about our function by asserting some reasonable bound on our input, after we've fixed our bug (code available under
147+
[`first-steps-v2`](https://github.com/model-checking/kani/tree/main/docs/src/tutorial/first-steps-v2/)):
147148

148149
```rust,noplaypen
149-
{{#include tutorial/kani-first-steps/src/final_form.rs:code}}
150+
{{#include tutorial/first-steps-v2/src/main.rs:code}}
150151
```
151152

152153
Now we've stated our previously implicit expectation: this function should never be called with inputs that are too big.
@@ -172,7 +173,7 @@ Much like property testing (which would also fail in this assertion), we need to
172173
Here's a revised example of the proof harness, one that now succeeds:
173174

174175
```rust,noplaypen
175-
{{#include tutorial/kani-first-steps/src/final_form.rs:kani}}
176+
{{#include tutorial/first-steps-v2/src/main.rs:kani}}
176177
```
177178

178179
But now we must wonder if we've really fully tested our function.
@@ -182,8 +183,8 @@ Fortunately, Kani is able to report a coverage metric for each proof harness.
182183
Try running:
183184

184185
```
185-
kani --visualize src/final_form.rs --harness verify_success
186-
open report/html/index.html
186+
kani --visualize src/main.rs --harness verify_success
187+
open report-verify_success/html/index.html
187188
```
188189

189190
The beginning of the report includes coverage information.

docs/src/tutorial/kani-first-steps/Cargo.toml renamed to docs/src/tutorial/first-steps-v1/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# Copyright Kani Contributors
22
# SPDX-License-Identifier: Apache-2.0 OR MIT
33
[package]
4-
name = "kani-first-steps"
4+
name = "first-steps-v1"
55
version = "0.1.0"
66
edition = "2018"
77

docs/src/tutorial/kani-first-steps/src/lib.rs renamed to docs/src/tutorial/first-steps-v1/src/main.rs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,5 @@
11
// Copyright Kani Contributors
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
3-
// kani-verify-fail
4-
5-
pub mod final_form;
63

74
// ANCHOR: code
85
fn estimate_size(x: u32) -> u32 {
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Copyright Kani Contributors
2+
# SPDX-License-Identifier: Apache-2.0 OR MIT
3+
[package]
4+
name = "first-steps-v2"
5+
version = "0.1.0"
6+
edition = "2018"
7+
8+
[dependencies]
9+
10+
[dev-dependencies]
11+
proptest = "1.0.0"
12+
13+
[workspace]

docs/src/tutorial/kani-first-steps/src/final_form.rs renamed to docs/src/tutorial/first-steps-v2/src/main.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,9 +61,7 @@ fn verify_success() {
6161

6262
#[cfg(kani)]
6363
#[kani::proof]
64-
fn verify_failure() {
64+
fn main() {
6565
let x: u32 = kani::any();
6666
let y = estimate_size(x);
6767
}
68-
69-
fn main() {}

0 commit comments

Comments
 (0)