Skip to content

Commit 938039e

Browse files
authored
fuzz: add cargo clippy check for fuzz directory (#10466)
1 parent 1ce8990 commit 938039e

File tree

4 files changed

+13
-5
lines changed

4 files changed

+13
-5
lines changed

.github/workflows/code-quality.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,12 @@ jobs:
147147
CARGO_UTILITY_LIST_OPTIONS="$(for u in ${UTILITY_LIST}; do echo -n "-puu_${u} "; done;)"
148148
S=$(cargo clippy --all-targets $extra --tests --benches -pcoreutils ${CARGO_UTILITY_LIST_OPTIONS} -- -D warnings 2>&1) && printf "%s\n" "$S" || { printf "%s\n" "$S" ; printf "%s" "$S" | sed -E -n -e '/^error:/{' -e "N; s/^error:[[:space:]]+(.*)\\n[[:space:]]+-->[[:space:]]+(.*):([0-9]+):([0-9]+).*$/::${fault_type} file=\2,line=\3,col=\4::${fault_prefix}: \`cargo clippy\`: \1 (file:'\2', line:\3)/p;" -e '}' ; fault=true ; }
149149
if [ -n "${{ steps.vars.outputs.FAIL_ON_FAULT }}" ] && [ -n "$fault" ]; then exit 1 ; fi
150+
- name: "cargo clippy on fuzz dir"
151+
if: runner.os != 'Windows'
152+
shell: bash
153+
run: |
154+
cd fuzz
155+
cargo clippy --workspace --all-targets --all-features -- -D warnings
150156
151157
style_spellcheck:
152158
name: Style/spelling

fuzz/.cargo/config.toml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[build]
2+
rustflags = ["--cfg", "fuzzing"]

fuzz/fuzz_targets/fuzz_non_utf8_paths.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ use std::env::temp_dir;
1414
use std::ffi::{OsStr, OsString};
1515
use std::fs;
1616
use std::os::unix::ffi::{OsStrExt, OsStringExt};
17-
use std::path::PathBuf;
17+
use std::path::{Path, PathBuf};
1818

1919
use uufuzz::{CommandResult, run_gnu_cmd};
2020
// Programs that typically take file/path arguments and should be tested
@@ -148,15 +148,15 @@ fn setup_test_files() -> Result<(PathBuf, Vec<PathBuf>), std::io::Error> {
148148
// Try to create the file - this may fail on some filesystems
149149
if let Ok(mut file) = fs::File::create(&file_path) {
150150
use std::io::Write;
151-
let _ = write!(file, "test content for file {}\n", i);
151+
let _ = writeln!(file, "test content for file {}", i);
152152
test_files.push(file_path);
153153
}
154154
}
155155

156156
Ok((temp_root, test_files))
157157
}
158158

159-
fn test_program_with_non_utf8_path(program: &str, path: &PathBuf) -> CommandResult {
159+
fn test_program_with_non_utf8_path(program: &str, path: &Path) -> CommandResult {
160160
let path_os = path.as_os_str();
161161

162162
// Use the locally built uutils binary instead of system PATH

fuzz/fuzz_targets/fuzz_test.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ fn generate_test_arg() -> String {
135135
if test_arg.arg_type == ArgType::INTEGER {
136136
arg.push_str(&format!(
137137
"{} {} {}",
138-
rng.random_range(-100..=100).to_string(),
138+
rng.random_range(-100..=100),
139139
test_arg.arg,
140-
rng.random_range(-100..=100).to_string()
140+
rng.random_range(-100..=100)
141141
));
142142
} else if test_arg.arg_type == ArgType::STRINGSTRING {
143143
let random_str = generate_random_string(rng.random_range(1..=10));

0 commit comments

Comments
 (0)