Skip to content

Commit 00fbce0

Browse files
committed
tests: add diff snapshots for proofs in compare folder
1 parent 9cf3ad9 commit 00fbce0

File tree

5 files changed

+127
-8
lines changed

5 files changed

+127
-8
lines changed

tests/compare.rs

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
use std::fs::{copy, remove_file};
2-
1+
use std::fs::{copy, create_dir_all, remove_file};
32
mod utils;
43
use utils::{assert_eq, *};
54

@@ -10,22 +9,38 @@ fn get(text: &str, start: &str) -> SerFunction {
109
}
1110

1211
const COMPARE: &str = "tests/compare";
12+
const SNAP_COMPARE: &str = "tests/snapshots/compare";
13+
const EXPECT_COMPARE: &str = "./snapshots/compare";
1314

1415
fn compare(
15-
tmp: &str,
16+
shared_file: &str,
1617
v_file: &[&str],
1718
f: &str,
1819
assert: impl Fn(&SerFunction, &SerFunction, &str, &str, &str),
1920
) {
21+
struct ProofPath {
22+
src_file: String,
23+
hash_json: String,
24+
hash_json_expected: String,
25+
}
26+
2027
let len = v_file.len();
2128
assert!(len > 1);
22-
let tmp = format!("{COMPARE}/{tmp}.rs");
29+
let v_path: Vec<_> = v_file
30+
.iter()
31+
.map(|file| ProofPath {
32+
src_file: format!("{COMPARE}/{file}.rs"),
33+
hash_json: format!("{SNAP_COMPARE}/{file}.json"),
34+
hash_json_expected: format!("{EXPECT_COMPARE}/{file}.json"),
35+
})
36+
.collect();
37+
let tmp = format!("{COMPARE}/{shared_file}.rs");
2338

2439
let mut v_func = vec![];
25-
for ele in v_file {
26-
copy(format!("{COMPARE}/{ele}.rs"), &tmp).unwrap();
40+
for path in &v_path {
41+
copy(&path.src_file, &tmp).unwrap();
2742
let text = run_dv(&[&tmp]);
28-
expect_file![format!("./snapshots/compare/{ele}.json")].assert_eq(&text);
43+
expect_file![&path.hash_json_expected].assert_eq(&text);
2944
v_func.push(get(&text, f));
3045
}
3146

@@ -38,10 +53,19 @@ fn compare(
3853
assert(&v_func[i], &v_func[j], f, v_file[i], v_file[j]);
3954
}
4055
}
56+
57+
if let [old, new] = v_path.as_slice() {
58+
let diff = run_vrs_diff(&old.hash_json, &new.hash_json);
59+
let diff_json = format!("{EXPECT_COMPARE}/diff/{shared_file}.json");
60+
expect_file![diff_json].assert_eq(&diff);
61+
}
4162
}
4263

4364
#[test]
4465
fn test_compare() {
66+
_ = create_dir_all(SNAP_COMPARE);
67+
_ = create_dir_all(format!("{SNAP_COMPARE}/diff"));
68+
4569
fn eq(fn1: &SerFunction, fn2: &SerFunction, f: &str, f1: &str, f2: &str) {
4670
assert_eq!(
4771
fn1.hash, fn2.hash,
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
[
2+
{
3+
"hash": "16423392687644375364724657870187103190",
4+
"name": "std::ptr::drop_in_place::<{closure@tests/compare/contract.rs:11:5: 11:29}>",
5+
"file": "library/core/src/ptr/mod.rs"
6+
},
7+
{
8+
"hash": "16423392687644375364724657870187103190",
9+
"name": "std::ptr::drop_in_place::<{closure@tests/compare/contract.rs:11:5: 11:29}>",
10+
"file": "library/core/src/ptr/mod.rs"
11+
},
12+
{
13+
"hash": "16423392687644375364724657870187103190",
14+
"name": "std::ptr::drop_in_place::<{closure@tests/compare/contract.rs:11:5: 11:29}>",
15+
"file": "library/core/src/ptr/mod.rs"
16+
},
17+
{
18+
"hash": "16423392687644375364724657870187103190",
19+
"name": "std::ptr::drop_in_place::<{closure@tests/compare/contract.rs:11:5: 11:29}>",
20+
"file": "library/core/src/ptr/mod.rs"
21+
},
22+
{
23+
"hash": "124569496921490884488960393718969893620",
24+
"name": "verify::g",
25+
"file": "tests/compare/contract.rs"
26+
},
27+
{
28+
"hash": "73887258241161092881667616569680888010",
29+
"name": "verify::g::kani_contract_mode",
30+
"file": "tests/compare/contract.rs"
31+
},
32+
{
33+
"hash": "5310357021794338182513150670169962678",
34+
"name": "verify::g::kani_force_fn_once::<(), {closure@tests/compare/contract.rs:11:5: 11:29}>",
35+
"file": "tests/compare/contract.rs"
36+
},
37+
{
38+
"hash": "5310357021794338182513150670169962678",
39+
"name": "verify::g::kani_force_fn_once::<(), {closure@tests/compare/contract.rs:11:5: 11:29}>",
40+
"file": "tests/compare/contract.rs"
41+
},
42+
{
43+
"hash": "5310357021794338182513150670169962678",
44+
"name": "verify::g::kani_force_fn_once::<(), {closure@tests/compare/contract.rs:11:5: 11:29}>",
45+
"file": "tests/compare/contract.rs"
46+
},
47+
{
48+
"hash": "5310357021794338182513150670169962678",
49+
"name": "verify::g::kani_force_fn_once::<(), {closure@tests/compare/contract.rs:11:5: 11:29}>",
50+
"file": "tests/compare/contract.rs"
51+
},
52+
{
53+
"hash": "82608928646705306325144146458835407768",
54+
"name": "verify::g::kani_register_contract::<(), {closure@tests/compare/contract.rs:11:5: 11:29}>",
55+
"file": "tests/compare/contract.rs"
56+
},
57+
{
58+
"hash": "82608928646705306325144146458835407768",
59+
"name": "verify::g::kani_register_contract::<(), {closure@tests/compare/contract.rs:11:5: 11:29}>",
60+
"file": "tests/compare/contract.rs"
61+
},
62+
{
63+
"hash": "82608928646705306325144146458835407768",
64+
"name": "verify::g::kani_register_contract::<(), {closure@tests/compare/contract.rs:11:5: 11:29}>",
65+
"file": "tests/compare/contract.rs"
66+
},
67+
{
68+
"hash": "82608928646705306325144146458835407768",
69+
"name": "verify::g::kani_register_contract::<(), {closure@tests/compare/contract.rs:11:5: 11:29}>",
70+
"file": "tests/compare/contract.rs"
71+
},
72+
{
73+
"hash": "843182267809226023016425080225293048998",
74+
"name": "verify::g::{closure#0}::REENTRY",
75+
"file": "tests/compare/contract.rs"
76+
}
77+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"hash": "6049791535301547191723508871959023129",
4+
"name": "verify::proof1",
5+
"file": "tests/compare/gen_proofs_by_nested_macros.rs",
6+
"proof_kind": "Standard"
7+
}
8+
]
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[
2+
{
3+
"hash": "1360231931955151956814099580363286591245",
4+
"name": "verify::g",
5+
"file": "tests/compare/proof.rs",
6+
"proof_kind": "Standard"
7+
}
8+
]

tests/utils.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ pub fn run_dv(args: &[&str]) -> String {
1111
run(env!("CARGO_PKG_NAME"), args)
1212
}
1313

14-
pub fn run_vrs(args: &[&str]) -> String {
14+
// verify_rust_std diff --old tests/snapshots/compare/proof1.json --new tests/snapshots/compare/proof2.json --hash-json
15+
pub fn run_vrs_diff(old: &str, new: &str) -> String {
16+
let args = &["diff", "--old", old, "--new", new, "--hash-json"];
1517
run("verify_rust_std", args)
1618
}
1719

0 commit comments

Comments
 (0)