@@ -26,15 +26,17 @@ fn main() -> Result<()> {
2626 let cmd = Command :: new ( "verify" )
2727 . args ( [
2828 arg ! ( [ version] "Verify specific version of Core (use \" all\" for all versions)" ) . required ( true ) ,
29+ arg ! ( -t --tests <TEST_OUTPUT > "Optionally check claimed status of tests" ) . required ( false ) ,
2930 ] ) ;
3031
3132 let matches = cmd. clone ( ) . get_matches ( ) ;
3233 let version = matches. get_one :: < String > ( "version" ) . unwrap ( ) ;
34+ let test_output = matches. get_one :: < String > ( "tests" ) ;
3335
3436 if version == "all" {
35- verify_all_versions ( ) ?;
37+ verify_all_versions ( test_output ) ?;
3638 } else if let Ok ( v) = version. parse :: < Version > ( ) {
37- verify_version ( v) ?;
39+ verify_version ( v, test_output ) ?;
3840 } else {
3941 eprint ! ( "Unrecognised version: {} (supported versions:" , version) ;
4042 for version in VERSIONS {
@@ -46,15 +48,15 @@ fn main() -> Result<()> {
4648 Ok ( ( ) )
4749}
4850
49- fn verify_all_versions ( ) -> Result < ( ) > {
51+ fn verify_all_versions ( test_output : Option < & String > ) -> Result < ( ) > {
5052 for version in VERSIONS {
5153 println ! ( "Verifying for Bitcoin Core version {} ...\n " , version) ;
52- verify_version ( version) ?;
54+ verify_version ( version, test_output ) ?;
5355 }
5456 Ok ( ( ) )
5557}
5658
57- fn verify_version ( version : Version ) -> Result < ( ) > {
59+ fn verify_version ( version : Version , test_output : Option < & String > ) -> Result < ( ) > {
5860 let s = format ! ( "{}::METHOD data" , version) ;
5961 let msg = format ! ( "Checking that the {} list is correct" , s) ;
6062 check ( & msg) ;
@@ -75,7 +77,7 @@ fn verify_version(version: Version) -> Result<()> {
7577
7678 let msg = "Checking that the status claimed in the version specific rustdocs is correct" ;
7779 check ( msg) ;
78- verify_status ( version) ?;
80+ verify_status ( version, test_output ) ?;
7981 close ( correct) ;
8082
8183 Ok ( ( ) )
@@ -100,7 +102,7 @@ fn verify_correct_methods(version: Version, methods: Vec<String>, msg: &str) ->
100102}
101103
102104/// Verifies that the status we claim is correct.
103- fn verify_status ( version : Version ) -> Result < ( ) > {
105+ fn verify_status ( version : Version , test_output : Option < & String > ) -> Result < ( ) > {
104106 let methods = versioned:: methods_and_status ( version) ?;
105107 for method in methods {
106108 let out =
@@ -113,8 +115,10 @@ fn verify_status(version: Version) -> Result<()> {
113115 if !model:: type_exists ( version, & method. name ) ? {
114116 eprintln ! ( "missing model type: {}" , output_method( out) ) ;
115117 }
116- if !check_integration_test_crate:: test_exists ( version, & method. name ) ? {
117- eprintln ! ( "missing integration test: {}" , method. name) ;
118+ if let Some ( test_output) = test_output {
119+ if !check_integration_test_crate:: test_exists ( version, & method. name , test_output) ? {
120+ eprintln ! ( "missing integration test: {}" , method. name) ;
121+ }
118122 }
119123 }
120124 Status :: Untested => {
@@ -125,8 +129,10 @@ fn verify_status(version: Version) -> Result<()> {
125129 eprintln ! ( "missing model type: {}" , output_method( out) ) ;
126130 }
127131 // Make sure we didn't forget to mark as tested after implementing integration test.
128- if check_integration_test_crate:: test_exists ( version, & method. name ) ? {
129- eprintln ! ( "found integration test for untested method: {}" , method. name) ;
132+ if let Some ( test_output) = test_output {
133+ if check_integration_test_crate:: test_exists ( version, & method. name , test_output) ? {
134+ eprintln ! ( "found integration test for untested method: {}" , method. name) ;
135+ }
130136 }
131137 }
132138 Status :: Omitted | Status :: Todo => { /* Nothing to verify */ }
@@ -158,49 +164,30 @@ mod check_integration_test_crate {
158164
159165 use crate :: Version ;
160166
161- /// Path to the model module file.
162- fn paths ( ) -> Vec < PathBuf > {
163- // TODO: "mining", "util", "zmq"
164- let sections =
165- [ "blockchain" , "control" , "generating" , "network" , "raw_transactions" , "wallet" ] ;
166- let mut paths = vec ! [ ] ;
167- for section in sections {
168- paths. push ( PathBuf :: from ( format ! ( "../integration_test/tests/{}.rs" , section) ) ) ;
169- }
170- paths
171- }
172-
173- fn all_test_functions ( ) -> Result < Vec < String > > {
167+ fn all_test_functions ( test_output : & str ) -> Result < Vec < String > > {
174168 let mut functions = vec ! [ ] ;
175169
176- for path in paths ( ) {
177- let file = File :: open ( & path) . with_context ( || {
178- format ! ( "Failed to grep for test functions in {}" , path. display( ) )
179- } ) ?;
180- let reader = io:: BufReader :: new ( file) ;
181-
182- // let re = Regex::new(®ex::escape(r"fn ([a-z_]+)\(\) \{"))?;
183- let fn_re = Regex :: new ( r"fn ([a-z_]+)" ) ?;
184- let todo_re = Regex :: new ( r"todo" ) ?;
170+ let path = PathBuf :: from ( test_output) ;
171+ let file = File :: open ( & path) . with_context ( || {
172+ format ! ( "Failed to open test output file {}" , path. display( ) )
173+ } ) ?;
174+ let reader = io:: BufReader :: new ( file) ;
175+ let test_re = Regex :: new ( r"test ([a-z_]+) ... ok" ) ?;
185176
186- for line in reader. lines ( ) {
187- let line = line?;
177+ for line in reader. lines ( ) {
178+ let line = line?;
188179
189- if todo_re. is_match ( & line) {
190- continue ;
191- }
192-
193- if let Some ( caps) = fn_re. captures ( & line) {
194- let function = caps. get ( 1 ) . unwrap ( ) . as_str ( ) ;
195- functions. push ( function. to_string ( ) ) ;
196- }
180+ if let Some ( caps) = test_re. captures ( & line) {
181+ let function = caps. get ( 1 ) . unwrap ( ) . as_str ( ) ;
182+ functions. push ( function. to_string ( ) ) ;
197183 }
198184 }
185+
199186 Ok ( functions)
200187 }
201188
202189 /// Checks that a type exists in `model` module.
203- pub fn test_exists ( version : Version , method_name : & str ) -> Result < bool > {
190+ pub fn test_exists ( version : Version , method_name : & str , test_output : & str ) -> Result < bool > {
204191 let method = match method:: Method :: from_name ( version, method_name) {
205192 Some ( m) => m,
206193 None =>
@@ -210,7 +197,7 @@ mod check_integration_test_crate {
210197 ) ) ) ,
211198 } ;
212199
213- let tests = all_test_functions ( ) ?;
200+ let tests = all_test_functions ( test_output ) ?;
214201 if !tests. contains ( & method. function . to_string ( ) ) {
215202 Ok ( false )
216203 } else {
0 commit comments