Skip to content

Commit 0e59612

Browse files
committed
test: refactor compare
1 parent bac388d commit 0e59612

File tree

1 file changed

+25
-34
lines changed

1 file changed

+25
-34
lines changed

tests/compare.rs

Lines changed: 25 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -10,47 +10,38 @@ fn get(text: &str, start: &str) -> SerFunction {
1010
v.into_iter().find(|f| f.func.starts_with(start)).unwrap()
1111
}
1212

13-
#[test]
14-
fn compare_proof() {
15-
let file = "tests/compare/proof.rs";
13+
const COMPARE: &str = "tests/compare";
1614

17-
copy("tests/compare/proof1.rs", file).unwrap();
18-
let text1 = &cmd(&["tests/compare/proof.rs"]);
19-
expect_file!["./snapshots/proof1.json"].assert_eq(text1);
15+
fn compare(tmp: &str, v_file: &[&str], f: &str) {
16+
let len = v_file.len();
17+
assert!(len > 1);
18+
let tmp = format!("{COMPARE}/{tmp}.rs");
2019

21-
// Add another proof won't affact the previous one.
22-
copy("tests/compare/proof2.rs", file).unwrap();
23-
let text2 = &cmd(&["tests/compare/proof.rs"]);
24-
expect_file!["./snapshots/proof2.json"].assert_eq(text2);
20+
let mut v_func = vec![];
21+
for ele in v_file {
22+
copy(format!("{COMPARE}/{ele}.rs"), &tmp).unwrap();
23+
let text = cmd(&[&tmp]);
24+
expect_file![format!("./snapshots/{ele}.json")].assert_eq(&text);
25+
v_func.push(get(&text, f));
26+
}
2527

26-
remove_file(file).unwrap();
28+
remove_file(tmp).unwrap();
2729

28-
let f = "pub fn f()";
2930
// For the same proof (w.r.t same path and body),
3031
// the hash value must be the same.
31-
assert_eq!(get(text1, f).hash, get(text2, f).hash);
32+
for i in 0..len - 1 {
33+
for j in 1..len {
34+
assert_eq!(
35+
v_func[i].hash, v_func[j].hash,
36+
"Hash values are not equal: {} ≠ {}",
37+
v_file[i], v_file[j]
38+
);
39+
}
40+
}
3241
}
3342

3443
#[test]
35-
fn compare_contract() {
36-
let file = "tests/compare/contract.rs";
37-
38-
copy("tests/compare/contract1.rs", file).unwrap();
39-
let text1 = &cmd(&["tests/compare/contract.rs"]);
40-
expect_file!["./snapshots/contract1.json"].assert_eq(text1);
41-
42-
copy("tests/compare/contract2.rs", file).unwrap();
43-
let text2 = &cmd(&["tests/compare/contract.rs"]);
44-
expect_file!["./snapshots/contract2.json"].assert_eq(text2);
45-
46-
remove_file(file).unwrap();
47-
48-
let f = "pub fn f()";
49-
let f1 = get(text1, f);
50-
let f2 = get(text2, f);
51-
let callees1 = f1.callee_sorted_by_file_func();
52-
let callees2 = f2.callee_sorted_by_file_func();
53-
54-
assert_eq!(callees1, callees2);
55-
assert_eq!(f1.hash, f2.hash);
44+
fn test_compare() {
45+
compare("proof", &["proof1", "proof2"], "pub fn f()");
46+
compare("contract", &["contract1", "contract2"], "pub fn f()");
5647
}

0 commit comments

Comments
 (0)