Skip to content

Commit d4cb0f7

Browse files
authored
Deduplicate dependencies (#2429)
* Deduplicate dependencies * Update `clap` usage of `quickchecking`
1 parent 3433695 commit d4cb0f7

File tree

5 files changed

+44
-116
lines changed

5 files changed

+44
-116
lines changed

Cargo.lock

Lines changed: 9 additions & 80 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

bindgen-cli/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ name = "bindgen"
2424
bindgen = { path = "../bindgen", version = "=0.64.0", features = ["cli", "experimental"] }
2525
shlex = "1"
2626
clap = { version = "4", features = ["derive"] }
27-
env_logger = { version = "0.9.0", optional = true }
27+
env_logger = { version = "0.10.0", optional = true }
2828
log = { version = "0.4", optional = true }
2929

3030
[features]

bindgen-tests/tests/quickchecking/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ name = "quickchecking"
1313
path = "src/bin.rs"
1414

1515
[dependencies]
16-
clap = "2.28"
16+
clap = "4"
1717
lazy_static = "1.0"
1818
quickcheck = "1.0"
1919
tempfile = "3"

bindgen-tests/tests/quickchecking/src/bin.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -17,60 +17,61 @@
1717
extern crate clap;
1818
extern crate quickchecking;
1919

20-
use clap::{App, Arg};
21-
use std::path::Path;
20+
use clap::{Arg, ArgAction, Command};
21+
use std::path::PathBuf;
2222

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> {
2525
match v.parse::<usize>() {
26-
Ok(_) => Ok(()),
26+
Ok(v) => Ok(v),
2727
Err(_) => Err(String::from(
2828
"Generate range could not be converted to a usize.",
2929
)),
3030
}
3131
}
3232

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),
3737
Err(_) => Err(String::from(
3838
"Tests count could not be converted to a usize.",
3939
)),
4040
}
4141
}
4242

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),
4748
false => Err(String::from("Provided directory path does not exist.")),
4849
}
4950
}
5051

5152
fn main() {
52-
let matches = App::new("quickchecking")
53+
let matches = Command::new("quickchecking")
5354
.version("0.2.0")
5455
.about(
5556
"Bindgen property tests with quickcheck. \
5657
Generate random valid C code and pass it to the \
5758
csmith/predicate.py script",
5859
)
5960
.arg(
60-
Arg::with_name("path")
61-
.short("p")
61+
Arg::new("path")
62+
.short('p')
6263
.long("path")
6364
.value_name("PATH")
6465
.help(
6566
"Optional. Preserve generated headers for inspection, \
6667
provide directory path for header output. [default: None] ",
6768
)
68-
.takes_value(true)
69-
.validator(validate_path),
69+
.action(ArgAction::Set)
70+
.value_parser(parse_path),
7071
)
7172
.arg(
72-
Arg::with_name("range")
73-
.short("r")
73+
Arg::new("range")
74+
.short('r')
7475
.long("range")
7576
.value_name("RANGE")
7677
.help(
@@ -80,13 +81,13 @@ fn main() {
8081
to grow much for execution time to increase \
8182
significantly.",
8283
)
83-
.takes_value(true)
84+
.action(ArgAction::Set)
8485
.default_value("32")
85-
.validator(validate_generate_range),
86+
.value_parser(parse_generate_range),
8687
)
8788
.arg(
88-
Arg::with_name("count")
89-
.short("c")
89+
Arg::new("count")
90+
.short('c')
9091
.long("count")
9192
.value_name("COUNT")
9293
.help(
@@ -96,16 +97,15 @@ fn main() {
9697
large. Increase this number if you're willing to \
9798
wait a while.",
9899
)
99-
.takes_value(true)
100+
.action(ArgAction::Set)
100101
.default_value("2")
101-
.validator(validate_tests_count),
102+
.value_parser(parse_tests_count),
102103
)
103104
.get_matches();
104105

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();
109109

110110
quickchecking::test_bindgen(generate_range, tests, output_path)
111111
}

bindgen-tests/tests/quickchecking/src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ use quickcheck::{Gen, QuickCheck, TestResult};
2727
use std::error::Error;
2828
use std::fs::File;
2929
use std::io::Write;
30-
use std::path::PathBuf;
30+
use std::path::{Path, PathBuf};
3131
use std::process::{Command, Output};
3232
use std::sync::Mutex;
3333
use tempfile::Builder;
@@ -107,11 +107,10 @@ fn bindgen_prop(header: fuzzers::HeaderC) -> TestResult {
107107
pub fn test_bindgen(
108108
generate_range: usize,
109109
tests: u64,
110-
output_path: Option<&str>,
110+
output_path: Option<&Path>,
111111
) {
112112
if let Some(path) = output_path {
113-
CONTEXT.lock().unwrap().output_path =
114-
Some(String::from(PathBuf::from(path).to_str().unwrap()));
113+
CONTEXT.lock().unwrap().output_path = Some(path.display().to_string());
115114
}
116115

117116
QuickCheck::new()

0 commit comments

Comments
 (0)