17
17
extern crate clap;
18
18
extern crate quickchecking;
19
19
20
- use clap:: { App , Arg } ;
21
- use std:: path:: Path ;
20
+ use clap:: { Arg , ArgAction , Command } ;
21
+ use std:: path:: PathBuf ;
22
22
23
- // Validate CLI argument input for generation range.
24
- fn validate_generate_range ( v : String ) -> Result < ( ) , String > {
23
+ // Parse CLI argument input for generation range.
24
+ fn parse_generate_range ( v : & str ) -> Result < usize , String > {
25
25
match v. parse :: < usize > ( ) {
26
- Ok ( _ ) => Ok ( ( ) ) ,
26
+ Ok ( v ) => Ok ( v ) ,
27
27
Err ( _) => Err ( String :: from (
28
28
"Generate range could not be converted to a usize." ,
29
29
) ) ,
30
30
}
31
31
}
32
32
33
- // Validate CLI argument input for tests count.
34
- fn validate_tests_count ( v : String ) -> Result < ( ) , String > {
35
- match v. parse :: < usize > ( ) {
36
- Ok ( _ ) => Ok ( ( ) ) ,
33
+ // Parse CLI argument input for tests count.
34
+ fn parse_tests_count ( v : & str ) -> Result < u64 , String > {
35
+ match v. parse :: < u64 > ( ) {
36
+ Ok ( v ) => Ok ( v ) ,
37
37
Err ( _) => Err ( String :: from (
38
38
"Tests count could not be converted to a usize." ,
39
39
) ) ,
40
40
}
41
41
}
42
42
43
- // Validate CLI argument input for fuzzed headers output path.
44
- fn validate_path ( v : String ) -> Result < ( ) , String > {
45
- match Path :: new ( & v) . is_dir ( ) {
46
- true => Ok ( ( ) ) ,
43
+ // Parse CLI argument input for fuzzed headers output path.
44
+ fn parse_path ( v : & str ) -> Result < PathBuf , String > {
45
+ let path = PathBuf :: from ( v) ;
46
+ match path. is_dir ( ) {
47
+ true => Ok ( path) ,
47
48
false => Err ( String :: from ( "Provided directory path does not exist." ) ) ,
48
49
}
49
50
}
50
51
51
52
fn main ( ) {
52
- let matches = App :: new ( "quickchecking" )
53
+ let matches = Command :: new ( "quickchecking" )
53
54
. version ( "0.2.0" )
54
55
. about (
55
56
"Bindgen property tests with quickcheck. \
56
57
Generate random valid C code and pass it to the \
57
58
csmith/predicate.py script",
58
59
)
59
60
. arg (
60
- Arg :: with_name ( "path" )
61
- . short ( "p" )
61
+ Arg :: new ( "path" )
62
+ . short ( 'p' )
62
63
. long ( "path" )
63
64
. value_name ( "PATH" )
64
65
. help (
65
66
"Optional. Preserve generated headers for inspection, \
66
67
provide directory path for header output. [default: None] ",
67
68
)
68
- . takes_value ( true )
69
- . validator ( validate_path ) ,
69
+ . action ( ArgAction :: Set )
70
+ . value_parser ( parse_path ) ,
70
71
)
71
72
. arg (
72
- Arg :: with_name ( "range" )
73
- . short ( "r" )
73
+ Arg :: new ( "range" )
74
+ . short ( 'r' )
74
75
. long ( "range" )
75
76
. value_name ( "RANGE" )
76
77
. help (
@@ -80,13 +81,13 @@ fn main() {
80
81
to grow much for execution time to increase \
81
82
significantly.",
82
83
)
83
- . takes_value ( true )
84
+ . action ( ArgAction :: Set )
84
85
. default_value ( "32" )
85
- . validator ( validate_generate_range ) ,
86
+ . value_parser ( parse_generate_range ) ,
86
87
)
87
88
. arg (
88
- Arg :: with_name ( "count" )
89
- . short ( "c" )
89
+ Arg :: new ( "count" )
90
+ . short ( 'c' )
90
91
. long ( "count" )
91
92
. value_name ( "COUNT" )
92
93
. help (
@@ -96,16 +97,15 @@ fn main() {
96
97
large. Increase this number if you're willing to \
97
98
wait a while.",
98
99
)
99
- . takes_value ( true )
100
+ . action ( ArgAction :: Set )
100
101
. default_value ( "2" )
101
- . validator ( validate_tests_count ) ,
102
+ . value_parser ( parse_tests_count ) ,
102
103
)
103
104
. get_matches ( ) ;
104
105
105
- let output_path: Option < & str > = matches. value_of ( "path" ) ;
106
- let generate_range: usize =
107
- matches. value_of ( "range" ) . unwrap ( ) . parse :: < usize > ( ) . unwrap ( ) ;
108
- let tests: u64 = matches. value_of ( "count" ) . unwrap ( ) . parse :: < u64 > ( ) . unwrap ( ) ;
106
+ let output_path = matches. get_one :: < PathBuf > ( "path" ) . map ( PathBuf :: as_path) ;
107
+ let generate_range = * matches. get_one :: < usize > ( "range" ) . unwrap ( ) ;
108
+ let tests = * matches. get_one :: < u64 > ( "count" ) . unwrap ( ) ;
109
109
110
110
quickchecking:: test_bindgen ( generate_range, tests, output_path)
111
111
}
0 commit comments