mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
fuzz: fix clippy warnings
This commit is contained in:
parent
e6f9e358d4
commit
a576054d42
5 changed files with 13 additions and 13 deletions
|
@ -32,7 +32,7 @@ pub fn is_gnu_cmd(cmd_path: &str) -> Result<(), std::io::Error> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn generate_and_run_uumain<F>(args: &mut Vec<OsString>, uumain_function: F) -> (String, i32)
|
pub fn generate_and_run_uumain<F>(args: &[OsString], uumain_function: F) -> (String, i32)
|
||||||
where
|
where
|
||||||
F: FnOnce(std::vec::IntoIter<OsString>) -> i32,
|
F: FnOnce(std::vec::IntoIter<OsString>) -> i32,
|
||||||
{
|
{
|
||||||
|
@ -45,7 +45,7 @@ where
|
||||||
|
|
||||||
{
|
{
|
||||||
unsafe { dup2(pipe_fds[1], STDOUT_FILENO) };
|
unsafe { dup2(pipe_fds[1], STDOUT_FILENO) };
|
||||||
uumain_exit_status = uumain_function(args.clone().into_iter());
|
uumain_exit_status = uumain_function(args.to_owned().into_iter());
|
||||||
unsafe { dup2(original_stdout_fd, STDOUT_FILENO) };
|
unsafe { dup2(original_stdout_fd, STDOUT_FILENO) };
|
||||||
unsafe { libc::close(original_stdout_fd) };
|
unsafe { libc::close(original_stdout_fd) };
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,6 @@ fuzz_target!(|data: &[u8]| {
|
||||||
let args = data
|
let args = data
|
||||||
.split(|b| *b == delim)
|
.split(|b| *b == delim)
|
||||||
.filter_map(|e| std::str::from_utf8(e).ok())
|
.filter_map(|e| std::str::from_utf8(e).ok())
|
||||||
.map(|e| OsString::from(e));
|
.map(OsString::from);
|
||||||
uumain(args);
|
uumain(args);
|
||||||
});
|
});
|
||||||
|
|
|
@ -84,7 +84,7 @@ fuzz_target!(|_data: &[u8]| {
|
||||||
let mut args = vec![OsString::from("expr")];
|
let mut args = vec![OsString::from("expr")];
|
||||||
args.extend(expr.split_whitespace().map(OsString::from));
|
args.extend(expr.split_whitespace().map(OsString::from));
|
||||||
|
|
||||||
let (rust_output, uumain_exit_code) = generate_and_run_uumain(&mut args, uumain);
|
let (rust_output, uumain_exit_code) = generate_and_run_uumain(&args, uumain);
|
||||||
|
|
||||||
// Run GNU expr with the provided arguments and compare the output
|
// Run GNU expr with the provided arguments and compare the output
|
||||||
match run_gnu_cmd(CMD_PATH, &args[1..], true) {
|
match run_gnu_cmd(CMD_PATH, &args[1..], true) {
|
||||||
|
@ -96,16 +96,16 @@ fuzz_target!(|_data: &[u8]| {
|
||||||
println!("GNU code: {}", gnu_exit_code);
|
println!("GNU code: {}", gnu_exit_code);
|
||||||
panic!("Different error codes");
|
panic!("Different error codes");
|
||||||
}
|
}
|
||||||
if rust_output != gnu_output {
|
if rust_output == gnu_output {
|
||||||
println!("Expression: {}", expr);
|
|
||||||
println!("Rust output: {}", rust_output);
|
|
||||||
println!("GNU output: {}", gnu_output);
|
|
||||||
panic!("Different output between Rust & GNU");
|
|
||||||
} else {
|
|
||||||
println!(
|
println!(
|
||||||
"Outputs matched for expression: {} => Result: {}",
|
"Outputs matched for expression: {} => Result: {}",
|
||||||
expr, rust_output
|
expr, rust_output
|
||||||
);
|
);
|
||||||
|
} else {
|
||||||
|
println!("Expression: {}", expr);
|
||||||
|
println!("Rust output: {}", rust_output);
|
||||||
|
println!("GNU output: {}", gnu_output);
|
||||||
|
panic!("Different output between Rust & GNU");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
|
|
|
@ -5,6 +5,6 @@ use uucore::parse_glob;
|
||||||
|
|
||||||
fuzz_target!(|data: &[u8]| {
|
fuzz_target!(|data: &[u8]| {
|
||||||
if let Ok(s) = std::str::from_utf8(data) {
|
if let Ok(s) = std::str::from_utf8(data) {
|
||||||
_ = parse_glob::from_str(s)
|
_ = parse_glob::from_str(s);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
|
@ -142,7 +142,7 @@ fn generate_test_arg() -> String {
|
||||||
0 => {
|
0 => {
|
||||||
arg.push_str(&rng.gen_range(-100..=100).to_string());
|
arg.push_str(&rng.gen_range(-100..=100).to_string());
|
||||||
}
|
}
|
||||||
1 | 2 | 3 => {
|
1..=3 => {
|
||||||
let test_arg = test_args
|
let test_arg = test_args
|
||||||
.choose(&mut rng)
|
.choose(&mut rng)
|
||||||
.expect("Failed to choose a random test argument");
|
.expect("Failed to choose a random test argument");
|
||||||
|
@ -204,7 +204,7 @@ fuzz_target!(|_data: &[u8]| {
|
||||||
args.push(OsString::from(generate_test_arg()));
|
args.push(OsString::from(generate_test_arg()));
|
||||||
}
|
}
|
||||||
|
|
||||||
let (rust_output, uumain_exit_status) = generate_and_run_uumain(&mut args, uumain);
|
let (rust_output, uumain_exit_status) = generate_and_run_uumain(&args, uumain);
|
||||||
|
|
||||||
// Run GNU test with the provided arguments and compare the output
|
// Run GNU test with the provided arguments and compare the output
|
||||||
match run_gnu_cmd(CMD_PATH, &args[1..], false) {
|
match run_gnu_cmd(CMD_PATH, &args[1..], false) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue