summaryrefslogtreecommitdiff
path: root/bindgen-tests/tests/quickchecking/src
diff options
context:
space:
mode:
Diffstat (limited to 'bindgen-tests/tests/quickchecking/src')
-rw-r--r--bindgen-tests/tests/quickchecking/src/fuzzers.rs11
-rw-r--r--bindgen-tests/tests/quickchecking/src/lib.rs46
2 files changed, 22 insertions, 35 deletions
diff --git a/bindgen-tests/tests/quickchecking/src/fuzzers.rs b/bindgen-tests/tests/quickchecking/src/fuzzers.rs
index b609dd5a..4188f8f5 100644
--- a/bindgen-tests/tests/quickchecking/src/fuzzers.rs
+++ b/bindgen-tests/tests/quickchecking/src/fuzzers.rs
@@ -327,12 +327,7 @@ impl Arbitrary for ArrayDimensionC {
let dimensions = g.gen_range(0, 5);
let mut def = String::new();
- let lower_bound;
- if cfg!(feature = "zero-sized-arrays") {
- lower_bound = 0;
- } else {
- lower_bound = 1;
- }
+ let lower_bound = i32::from(cfg!(feature = "zero-sized-arrays"));
for _ in 1..dimensions {
// 16 is an arbitrary "not too big" number for capping array size.
@@ -400,7 +395,7 @@ impl Arbitrary for StructDeclarationC {
fn arbitrary<G: Gen>(g: &mut G) -> StructDeclarationC {
// Reduce generator size as a method of putting a bound on recursion.
// When size < 1 the empty list is generated.
- let reduced_size: usize = (g.size() / 2) as usize + 1;
+ let reduced_size: usize = (g.size() / 2) + 1;
let mut decl_list: DeclarationListC =
Arbitrary::arbitrary(&mut StdGen::new(thread_rng(), reduced_size));
let mut fields: DeclarationListC = DeclarationListC { decls: vec![] };
@@ -448,7 +443,7 @@ impl Arbitrary for UnionDeclarationC {
fn arbitrary<G: Gen>(g: &mut G) -> UnionDeclarationC {
// Reduce generator size as a method of putting a bound on recursion.
// When size < 1 the empty list is generated.
- let reduced_size: usize = (g.size() / 2) as usize + 1;
+ let reduced_size: usize = (g.size() / 2) + 1;
let mut decl_list: DeclarationListC =
Arbitrary::arbitrary(&mut StdGen::new(thread_rng(), reduced_size));
let mut fields: DeclarationListC = DeclarationListC { decls: vec![] };
diff --git a/bindgen-tests/tests/quickchecking/src/lib.rs b/bindgen-tests/tests/quickchecking/src/lib.rs
index b09d1c49..75bfc237 100644
--- a/bindgen-tests/tests/quickchecking/src/lib.rs
+++ b/bindgen-tests/tests/quickchecking/src/lib.rs
@@ -63,32 +63,27 @@ fn run_predicate_script(
header_file.write_all(header.to_string().as_bytes())?;
header_file.sync_all()?;
- let header_path_string;
- match header_path.into_os_string().into_string() {
- Ok(s) => header_path_string = s,
- Err(_) => return Err(From::from("error converting path into String")),
- }
+ let header_path_string = header_path
+ .into_os_string()
+ .into_string()
+ .map_err(|_| "error converting path into String")?;
let mut predicate_script_path = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
predicate_script_path.push("../../csmith-fuzzing/predicate.py");
- let predicate_script_path_string;
- match predicate_script_path.into_os_string().into_string() {
- Ok(s) => predicate_script_path_string = s,
- Err(_) => return Err(From::from("error converting path into String")),
- }
+ let predicate_script_path_string = predicate_script_path
+ .into_os_string()
+ .into_string()
+ .map_err(|_| "error converting path into String")?;
// Copy generated temp files to output_path directory for inspection.
// If `None`, output path not specified, don't copy.
- match CONTEXT.lock().unwrap().output_path {
- Some(ref path) => {
- Command::new("cp")
- .arg("-a")
- .arg(&dir.path().to_str().unwrap())
- .arg(&path)
- .output()?;
- }
- None => {}
+ if let Some(ref path) = CONTEXT.lock().unwrap().output_path {
+ Command::new("cp")
+ .arg("-a")
+ .arg(dir.path().to_str().unwrap())
+ .arg(path)
+ .output()?;
}
Ok(Command::new(&predicate_script_path_string)
@@ -101,10 +96,10 @@ fn run_predicate_script(
// status of that command.
fn bindgen_prop(header: fuzzers::HeaderC) -> TestResult {
match run_predicate_script(header) {
- Ok(o) => return TestResult::from_bool(o.status.success()),
+ Ok(o) => TestResult::from_bool(o.status.success()),
Err(e) => {
println!("{:?}", e);
- return TestResult::from_bool(false);
+ TestResult::from_bool(false)
}
}
}
@@ -118,12 +113,9 @@ pub fn test_bindgen(
tests: usize,
output_path: Option<&str>,
) {
- match output_path {
- Some(path) => {
- CONTEXT.lock().unwrap().output_path =
- Some(String::from(PathBuf::from(path).to_str().unwrap()));
- }
- None => {} // Path not specified, don't provide output.
+ if let Some(path) = output_path {
+ CONTEXT.lock().unwrap().output_path =
+ Some(String::from(PathBuf::from(path).to_str().unwrap()));
}
QuickCheck::new()