1+ use indexmap:: IndexMap ;
2+ use std:: path:: { Path , PathBuf } ;
3+
14mod utils;
2- use utils:: * ;
5+ use utils:: { assert_eq , * } ;
36
4- #[ test]
5- fn test_proofs ( ) -> eyre:: Result < ( ) > {
7+ pub fn get_proofs ( ) -> Result < Vec < PathBuf > > {
68 let mut proofs = vec ! [ ] ;
79 for entry in std:: fs:: read_dir ( "tests/proofs" ) ? {
810 let entry = entry?;
@@ -13,8 +15,14 @@ fn test_proofs() -> eyre::Result<()> {
1315 proofs. push ( path) ;
1416 }
1517 }
16-
1718 proofs. sort ( ) ;
19+ Ok ( proofs)
20+ }
21+
22+ #[ test]
23+ fn test_proofs ( ) -> Result < ( ) > {
24+ let proofs = get_proofs ( ) ?;
25+
1826 expect ! [ [ r#"
1927 [
2028 "tests/proofs/ad_hoc.rs",
@@ -26,15 +34,40 @@ fn test_proofs() -> eyre::Result<()> {
2634 "# ] ]
2735 . assert_debug_eq ( & proofs) ;
2836
37+ let mut v_json = Vec :: < Vec < SerFunction > > :: with_capacity ( proofs. len ( ) ) ;
2938 for path in & proofs {
3039 let file_stem = path. file_stem ( ) . and_then ( |f| f. to_str ( ) ) . unwrap ( ) ;
31- let json = cmd ( & [ & format ! ( "tests/proofs/{file_stem}.rs" ) ] ) ;
32- expect_file ! [ format!( "./snapshots/{file_stem}.json" ) ] . assert_eq ( & json) ;
40+ let text = cmd ( & [ & format ! ( "tests/proofs/{file_stem}.rs" ) ] ) ;
41+ expect_file ! [ format!( "./snapshots/{file_stem}.json" ) ] . assert_eq ( & text) ;
42+ v_json. push ( serde_json:: from_str ( & text) . unwrap ( ) ) ;
3343 }
3444
45+ assert_unique_hash ( & proofs, & v_json) ;
46+
3547 Ok ( ( ) )
3648}
3749
50+ fn assert_unique_hash ( proofs : & [ PathBuf ] , v_json : & [ Vec < SerFunction > ] ) {
51+ let mut map = IndexMap :: < & str , Vec < ( & Path , & str ) > > :: new ( ) ;
52+ for ( v, proof) in v_json. iter ( ) . zip ( proofs) {
53+ for json in v {
54+ let def_id = & * json. def_id ;
55+ let item = ( & * * proof, def_id) ;
56+ map. entry ( & json. hash )
57+ . and_modify ( |v_item| v_item. push ( item) )
58+ . or_insert_with ( || vec ! [ item] ) ;
59+ }
60+ }
61+ for ( hash, v_item) in & map {
62+ let v_item_len = v_item. len ( ) ;
63+ assert_eq ! (
64+ v_item_len, 1 ,
65+ "{hash} should only correspond to single item, but \
66+ {v_item_len} items have the hash value:\n {v_item:?}",
67+ ) ;
68+ }
69+ }
70+
3871#[ test]
3972/// Make sure latest kani is installed through cargo.
4073fn kani_installed ( ) {
0 commit comments