1- use assert_cmd:: Command ;
2- use distributed_verification:: SerFunction ;
3- use expect_test:: expect_file;
4- use pretty_assertions:: assert_eq;
5- use std:: fs:: { copy, remove_file} ;
6-
7- fn cmd ( args : & [ & str ] ) -> String {
8- let mut command = Command :: cargo_bin ( env ! ( "CARGO_PKG_NAME" ) ) . unwrap ( ) ;
9- command. env ( "RUST_LOG" , "off" ) . args ( args) ;
10- let output = command. output ( ) . unwrap ( ) ;
11- assert ! (
12- output. status. success( ) ,
13- "Failed to test standard_proof.rs:\n {}" ,
14- std:: str :: from_utf8( & output. stderr) . unwrap( )
15- ) ;
16-
17- String :: from_utf8 ( output. stdout ) . unwrap ( )
18- }
1+ mod utils;
2+ use utils:: * ;
193
204#[ test]
215fn standard_proofs ( ) {
@@ -28,54 +12,3 @@ fn standard_proofs_with_contracts() {
2812 let json = cmd ( & [ "tests/standard_proofs_with_contracts.rs" ] ) ;
2913 expect_file ! [ "./snapshots/standard_proofs_with_contracts.json" ] . assert_eq ( & json) ;
3014}
31-
32- fn get ( text : & str , start : & str ) -> SerFunction {
33- let json = & text[ text. find ( "[\n " ) . unwrap ( ) ..] ;
34- let v: Vec < SerFunction > = serde_json:: from_str ( json) . unwrap ( ) ;
35- v. into_iter ( ) . find ( |f| f. func . starts_with ( start) ) . unwrap ( )
36- }
37-
38- #[ test]
39- fn compare_proof ( ) {
40- let file = "tests/compare/proof.rs" ;
41-
42- copy ( "tests/compare/proof1.rs" , file) . unwrap ( ) ;
43- let text1 = & cmd ( & [ "tests/compare/proof.rs" ] ) ;
44- expect_file ! [ "./snapshots/proof1.json" ] . assert_eq ( text1) ;
45-
46- // Add another proof won't affact the previous one.
47- copy ( "tests/compare/proof2.rs" , file) . unwrap ( ) ;
48- let text2 = & cmd ( & [ "tests/compare/proof.rs" ] ) ;
49- expect_file ! [ "./snapshots/proof2.json" ] . assert_eq ( text2) ;
50-
51- remove_file ( file) . unwrap ( ) ;
52-
53- let f = "pub fn f()" ;
54- // For the same proof (w.r.t same path and body),
55- // the hash value must be the same.
56- assert_eq ! ( get( text1, f) . hash, get( text2, f) . hash) ;
57- }
58-
59- #[ test]
60- fn compare_contract ( ) {
61- let file = "tests/compare/contract.rs" ;
62-
63- copy ( "tests/compare/contract1.rs" , file) . unwrap ( ) ;
64- let text1 = & cmd ( & [ "tests/compare/contract.rs" ] ) ;
65- expect_file ! [ "./snapshots/contract1.json" ] . assert_eq ( text1) ;
66-
67- copy ( "tests/compare/contract2.rs" , file) . unwrap ( ) ;
68- let text2 = & cmd ( & [ "tests/compare/contract.rs" ] ) ;
69- expect_file ! [ "./snapshots/contract2.json" ] . assert_eq ( text2) ;
70-
71- remove_file ( file) . unwrap ( ) ;
72-
73- let f = "pub fn f()" ;
74- let f1 = get ( text1, f) ;
75- let f2 = get ( text2, f) ;
76- let callees1 = f1. callee_sorted_by_file_func ( ) ;
77- let callees2 = f2. callee_sorted_by_file_func ( ) ;
78-
79- assert_eq ! ( callees1, callees2) ;
80- assert_eq ! ( f1. hash, f2. hash) ;
81- }
0 commit comments