Skip to content

Commit bac388d

Browse files
committed
test: automatically generate jsons for proofs
This commit moves standard_proofs and standard_proofs_with_contracts to proofs folder. Since the file path to proofs change, hash values change.
1 parent e07d632 commit bac388d

File tree

7 files changed

+58
-39
lines changed

7 files changed

+58
-39
lines changed

tests/proofs.rs

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
mod utils;
2+
use utils::*;
3+
4+
#[test]
5+
fn test_proofs() -> eyre::Result<()> {
6+
let mut proofs = vec![];
7+
for entry in std::fs::read_dir("tests/proofs")? {
8+
let entry = entry?;
9+
let path = entry.path();
10+
if path.is_file()
11+
&& path.extension().and_then(|ext| Some(ext.to_str()? == "rs")).unwrap_or(false)
12+
{
13+
proofs.push(path);
14+
}
15+
}
16+
17+
expect![[r#"
18+
[
19+
"tests/proofs/standard_proofs_with_contracts.rs",
20+
"tests/proofs/standard_proofs.rs",
21+
]
22+
"#]]
23+
.assert_debug_eq(&proofs);
24+
25+
for path in &proofs {
26+
let file_stem = path.file_stem().and_then(|f| f.to_str()).unwrap();
27+
let json = cmd(&[&format!("tests/proofs/{file_stem}.rs")]);
28+
expect_file![format!("./snapshots/{file_stem}.json")].assert_eq(&json);
29+
}
30+
31+
Ok(())
32+
}
File renamed without changes.

tests/snapshots.rs

Lines changed: 0 additions & 14 deletions
This file was deleted.

tests/snapshots/standard_proofs.json

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
[
22
{
3-
"hash": "42109808322873561223875447740690337681",
3+
"hash": "46975737574545431849805961234274153517",
44
"def_id": "DefId { id: 1, name: \"verify::standard_proof_empty\" }",
5-
"file": "tests/standard_proofs.rs",
5+
"file": "tests/proofs/standard_proofs.rs",
66
"attrs": [
77
"#[kanitool::proof]"
88
],
99
"func": "fn standard_proof_empty() {}",
1010
"callees": []
1111
},
1212
{
13-
"hash": "119935654822495658609677948466451012436",
13+
"hash": "154269283551974763216917429380903124467",
1414
"def_id": "DefId { id: 0, name: \"verify::standard_proof\" }",
15-
"file": "tests/standard_proofs.rs",
15+
"file": "tests/proofs/standard_proofs.rs",
1616
"attrs": [
1717
"#[kanitool::proof]"
1818
],
@@ -51,9 +51,9 @@
5151
]
5252
},
5353
{
54-
"hash": "353125589356689115114026576863231049982",
54+
"hash": "58801092890548413495612860413695445693",
5555
"def_id": "DefId { id: 2, name: \"verify::recursive_callees\" }",
56-
"file": "tests/standard_proofs.rs",
56+
"file": "tests/proofs/standard_proofs.rs",
5757
"attrs": [
5858
"#[kanitool::proof]"
5959
],
@@ -596,12 +596,12 @@
596596
},
597597
{
598598
"def_id": "DefId { id: 4, name: \"m::func1\" }",
599-
"file": "tests/standard_proofs.rs",
599+
"file": "tests/proofs/standard_proofs.rs",
600600
"func": "pub fn func1() {\n let _a = \"\".trim();\n }"
601601
},
602602
{
603603
"def_id": "DefId { id: 3, name: \"top_level\" }",
604-
"file": "tests/standard_proofs.rs",
604+
"file": "tests/proofs/standard_proofs.rs",
605605
"func": "pub fn top_level() {\n m::func1();\n}"
606606
}
607607
]

tests/snapshots/standard_proofs_with_contracts.json

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
[
22
{
3-
"hash": "883956136257843376812272307543917525328",
3+
"hash": "638100731549357801415843699110435929671",
44
"def_id": "DefId { id: 13, name: \"verify::standard_proof_with_contract_requires\" }",
5-
"file": "tests/standard_proofs_with_contracts.rs",
5+
"file": "tests/proofs/standard_proofs_with_contracts.rs",
66
"attrs": [
77
"#[kanitool::proof]"
88
],
@@ -1225,40 +1225,40 @@
12251225
},
12261226
{
12271227
"def_id": "DefId { id: 0, name: \"verify::contract_requires\" }",
1228-
"file": "tests/standard_proofs_with_contracts.rs",
1228+
"file": "tests/proofs/standard_proofs_with_contracts.rs",
12291229
"func": "#[kani::requires(a > 0)]"
12301230
},
12311231
{
12321232
"def_id": "DefId { id: 1, name: \"verify::contract_requires::kani_register_contract\" }",
1233-
"file": "tests/standard_proofs_with_contracts.rs",
1233+
"file": "tests/proofs/standard_proofs_with_contracts.rs",
12341234
"func": "#[kani::requires(a > 0)]"
12351235
},
12361236
{
12371237
"def_id": "DefId { id: 1, name: \"verify::contract_requires::kani_register_contract\" }",
1238-
"file": "tests/standard_proofs_with_contracts.rs",
1238+
"file": "tests/proofs/standard_proofs_with_contracts.rs",
12391239
"func": "#[kani::requires(a > 0)]"
12401240
},
12411241
{
12421242
"def_id": "DefId { id: 2, name: \"verify::contract_requires::kani_contract_mode\" }",
1243-
"file": "tests/standard_proofs_with_contracts.rs",
1243+
"file": "tests/proofs/standard_proofs_with_contracts.rs",
12441244
"func": "#[kani::requires(a > 0)]"
12451245
},
12461246
{
12471247
"def_id": "DefId { id: 1, name: \"verify::contract_requires::kani_register_contract\" }",
1248-
"file": "tests/standard_proofs_with_contracts.rs",
1248+
"file": "tests/proofs/standard_proofs_with_contracts.rs",
12491249
"func": "#[kani::requires(a > 0)]"
12501250
},
12511251
{
12521252
"def_id": "DefId { id: 1, name: \"verify::contract_requires::kani_register_contract\" }",
1253-
"file": "tests/standard_proofs_with_contracts.rs",
1253+
"file": "tests/proofs/standard_proofs_with_contracts.rs",
12541254
"func": "#[kani::requires(a > 0)]"
12551255
}
12561256
]
12571257
},
12581258
{
1259-
"hash": "1209015469125850433012148577517296907918",
1259+
"hash": "153447193349631547573109754293264803070",
12601260
"def_id": "DefId { id: 32, name: \"verify::standard_proof_with_contract_ensures\" }",
1261-
"file": "tests/standard_proofs_with_contracts.rs",
1261+
"file": "tests/proofs/standard_proofs_with_contracts.rs",
12621262
"attrs": [
12631263
"#[kanitool::proof]"
12641264
],
@@ -2481,32 +2481,32 @@
24812481
},
24822482
{
24832483
"def_id": "DefId { id: 14, name: \"verify::contract_ensures\" }",
2484-
"file": "tests/standard_proofs_with_contracts.rs",
2484+
"file": "tests/proofs/standard_proofs_with_contracts.rs",
24852485
"func": "#[kani::ensures(|&ret| ret > 0)]"
24862486
},
24872487
{
24882488
"def_id": "DefId { id: 16, name: \"verify::contract_ensures::kani_contract_mode\" }",
2489-
"file": "tests/standard_proofs_with_contracts.rs",
2489+
"file": "tests/proofs/standard_proofs_with_contracts.rs",
24902490
"func": "#[kani::ensures(|&ret| ret > 0)]"
24912491
},
24922492
{
24932493
"def_id": "DefId { id: 15, name: \"verify::contract_ensures::kani_register_contract\" }",
2494-
"file": "tests/standard_proofs_with_contracts.rs",
2494+
"file": "tests/proofs/standard_proofs_with_contracts.rs",
24952495
"func": "#[kani::ensures(|&ret| ret > 0)]"
24962496
},
24972497
{
24982498
"def_id": "DefId { id: 15, name: \"verify::contract_ensures::kani_register_contract\" }",
2499-
"file": "tests/standard_proofs_with_contracts.rs",
2499+
"file": "tests/proofs/standard_proofs_with_contracts.rs",
25002500
"func": "#[kani::ensures(|&ret| ret > 0)]"
25012501
},
25022502
{
25032503
"def_id": "DefId { id: 15, name: \"verify::contract_ensures::kani_register_contract\" }",
2504-
"file": "tests/standard_proofs_with_contracts.rs",
2504+
"file": "tests/proofs/standard_proofs_with_contracts.rs",
25052505
"func": "#[kani::ensures(|&ret| ret > 0)]"
25062506
},
25072507
{
25082508
"def_id": "DefId { id: 15, name: \"verify::contract_ensures::kani_register_contract\" }",
2509-
"file": "tests/standard_proofs_with_contracts.rs",
2509+
"file": "tests/proofs/standard_proofs_with_contracts.rs",
25102510
"func": "#[kani::ensures(|&ret| ret > 0)]"
25112511
}
25122512
]

tests/utils.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
use assert_cmd::Command;
22

3-
pub use expect_test::expect_file;
3+
#[allow(unused_imports)] // seems a bug in clippy
4+
pub use expect_test::{expect, expect_file};
45
#[allow(unused_imports)] // seems a bug in clippy
56
pub use pretty_assertions::assert_eq;
67

0 commit comments

Comments
 (0)