@@ -53,37 +53,48 @@ fn main() -> Result<()> {
5353}
5454
5555fn verify_all_versions ( test_output : Option < & String > , quiet : bool ) -> Result < ( ) > {
56+ let mut any_failed = false ;
5657 for version in VERSIONS {
5758 println ! ( "\n Verifying for Bitcoin Core version {} ..." , version) ;
58- verify_version ( version, test_output, quiet) ?;
59+ if verify_version ( version, test_output, quiet) . is_err ( ) {
60+ any_failed = true ;
61+ }
62+ }
63+ if any_failed {
64+ return Err ( anyhow:: anyhow!( "verification failed for one or more versions" ) )
5965 }
6066 Ok ( ( ) )
6167}
6268
6369fn verify_version ( version : Version , test_output : Option < & String > , quiet : bool ) -> Result < ( ) > {
70+ let mut failures = 0 ;
71+
6472 let s = format ! ( "{}::METHOD data" , version) ;
6573 let msg = format ! ( "Checking that the {} list is correct" , s) ;
6674 check ( & msg, quiet) ;
67- let correct = verify_correct_methods ( version, method:: all_methods ( version) , & s) ?;
68- close ( correct, quiet) ;
69- if !correct {
70- process:: exit ( 1 ) ;
75+ match verify_correct_methods ( version, method:: all_methods ( version) , & s) {
76+ Ok ( ( ) ) => close ( true , quiet) ,
77+ Err ( e) => { if !quiet { eprintln ! ( "{}" , e) ; } close ( false , quiet) ; failures += 1 ; }
7178 }
7279
7380 let s = "rustdoc version specific rustdocs" ;
7481 let msg = format ! ( "Checking that the {} list is correct" , s) ;
7582 check ( & msg, quiet) ;
76- let correct = verify_correct_methods ( version, versioned:: all_methods ( version) ?, s) ?;
77- close ( correct, quiet) ;
78- if !correct {
79- process:: exit ( 1 ) ;
83+ match verify_correct_methods ( version, versioned:: all_methods ( version) ?, s) {
84+ Ok ( ( ) ) => close ( true , quiet) ,
85+ Err ( e) => { if !quiet { eprintln ! ( "{}" , e) ; } close ( false , quiet) ; failures += 1 ; }
8086 }
8187
8288 let msg = "Checking that the status claimed in the version specific rustdocs is correct" ;
8389 check ( msg, quiet) ;
84- verify_status ( version, test_output) ?;
85- close ( correct, quiet) ;
90+ match verify_status ( version, test_output) {
91+ Ok ( ( ) ) => close ( true , quiet) ,
92+ Err ( e) => { if !quiet { eprintln ! ( "{}" , e) ; } close ( false , quiet) ; failures += 1 ; }
93+ }
8694
95+ if failures > 0 {
96+ return Err ( anyhow:: anyhow!( "verification failed ({} check(s) failed)" , failures) ) ;
97+ }
8798 Ok ( ( ) )
8899}
89100
@@ -94,40 +105,53 @@ fn check(msg: &str, quiet: bool) {
94105}
95106
96107fn close ( correct : bool , quiet : bool ) {
97- if correct && !quiet {
108+ if quiet { return ; }
109+ if correct {
98110 println ! ( "Correct \u{2713} \n " ) ;
111+ } else {
112+ println ! ( "\u{001b} [31mIncorrect \u{2717} \u{001b} [0m \n " ) ;
99113 }
100114}
101115
102116/// Verifies that the correct set of methods are documented.
103- fn verify_correct_methods ( version : Version , methods : Vec < String > , msg : & str ) -> Result < bool > {
117+ fn verify_correct_methods ( version : Version , methods : Vec < String > , msg : & str ) -> Result < ( ) > {
104118 let ssot = ssot:: all_methods ( version) ?;
105119 let want = ssot. iter ( ) . map ( |s| s. as_str ( ) ) . collect :: < Vec < & str > > ( ) ;
106120 let got = methods. iter ( ) . map ( |s| s. as_str ( ) ) . collect :: < Vec < & str > > ( ) ;
107- Ok ( verify:: correct_methods ( & got, & want, msg) )
121+ if !verify:: correct_methods ( & got, & want, msg) {
122+ return Err ( anyhow:: anyhow!( "incorrect {}" , msg) ) ;
123+ }
124+ Ok ( ( ) )
108125}
109126
110127/// Verifies that the status we claim is correct.
111128fn verify_status ( version : Version , test_output : Option < & String > ) -> Result < ( ) > {
112129 let methods = versioned:: methods_and_status ( version) ?;
130+ let mut failures = 0 ;
113131 for method in methods {
114132 match method. status {
115133 Status :: Done => {
116- check_types_exist_if_required ( version, & method. name ) ?;
134+ if check_types_exist_if_required ( version, & method. name ) . is_err ( ) {
135+ failures += 1 ;
136+ }
117137
118138 if let Some ( test_output) = test_output {
119- if ! check_integration_test_crate:: test_exists ( version, & method. name , test_output) ? {
139+ if check_integration_test_crate:: test_exists ( version, & method. name , test_output) . is_err ( ) {
120140 eprintln ! ( "missing integration test: {}" , method. name) ;
141+ failures += 1 ;
121142 }
122143 }
123144 }
124145 Status :: Untested => {
125- check_types_exist_if_required ( version, & method. name ) ?;
146+ if check_types_exist_if_required ( version, & method. name ) . is_err ( ) {
147+ failures += 1 ;
148+ }
126149
127150 // Make sure we didn't forget to mark as tested after implementing integration test.
128151 if let Some ( test_output) = test_output {
129- if check_integration_test_crate:: test_exists ( version, & method. name , test_output) ? {
152+ if check_integration_test_crate:: test_exists ( version, & method. name , test_output) . is_ok ( ) {
130153 eprintln ! ( "found integration test for untested method: {}" , method. name) ;
154+ failures += 1 ;
131155 }
132156 }
133157 }
@@ -137,15 +161,20 @@ fn verify_status(version: Version, test_output: Option<&String>) -> Result<()> {
137161
138162 if versioned:: type_exists ( version, & method. name ) ? && !versioned:: requires_type ( version, & method. name ) ? {
139163 eprintln ! ( "return type found but method is omitted or TODO: {}" , output_method( out) ) ;
164+ failures += 1 ;
140165 }
141166
142167 if model:: type_exists ( version, & method. name ) ? && !model:: requires_type ( version, & method. name ) ? {
143168 eprintln ! ( "model type found but method is omitted or TODO: {}" , output_method( out) ) ;
169+ failures += 1 ;
144170 }
145171 }
146172 }
147173 }
148174
175+ if failures > 0 {
176+ return Err ( anyhow:: anyhow!( "status verification failed ({} issue(s))" , failures) ) ;
177+ }
149178 Ok ( ( ) )
150179}
151180
@@ -154,12 +183,15 @@ fn check_types_exist_if_required(version: Version, method_name: &str) -> Result<
154183
155184 if versioned:: requires_type ( version, method_name) ? && !versioned:: type_exists ( version, method_name) ? {
156185 eprintln ! ( "missing return type: {}" , output_method( out) ) ;
186+ return Err ( anyhow:: anyhow!( "missing return type" ) ) ;
157187 }
158188 if model:: requires_type ( version, method_name) ? && !model:: type_exists ( version, method_name) ? {
159189 eprintln ! ( "missing model type: {}" , output_method( out) ) ;
190+ return Err ( anyhow:: anyhow!( "missing model type" ) ) ;
160191 }
161192 if model:: type_exists ( version, method_name) ? && !model:: requires_type ( version, method_name) ? {
162193 eprintln ! ( "found model type when none expected: {}" , output_method( out) ) ;
194+ return Err ( anyhow:: anyhow!( "unexpected model type" ) ) ;
163195 }
164196 Ok ( ( ) )
165197}
0 commit comments