Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 FIX: Check fuzz test name collision by checking the name against HashSet #114

Merged
merged 2 commits into from
Feb 8, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 20 additions & 7 deletions crates/client/src/test_generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,18 +212,31 @@ impl TestGenerator {
let fuzz_id = if fuzz_dir_path.read_dir()?.next().is_none() {
0
} else {
let mut directories: Vec<_> = fuzz_dir_path
let mut directories: std::collections::HashSet<_> = fuzz_dir_path
Ikrk marked this conversation as resolved.
Show resolved Hide resolved
.read_dir()
.unwrap()
.map(|r| r.unwrap())
.expect("Reading directory failed")
.map(|r| {
r.expect("Reading directory; DirEntry error")
.file_name()
.to_string_lossy()
.to_string()
})
.collect();

// INFO discard known entries created by framework, everything else
// created by user will be taken as fuzz test.
directories.retain(|x| x.file_name() != "fuzzing");
directories.retain(|x| x.file_name() != "Cargo.toml");

directories.len()
directories.retain(|x| x != "fuzzing");
directories.retain(|x| x != "Cargo.toml");

let mut fuzz_id = directories.len();
loop {
let fuzz_test = format!("fuzz_{fuzz_id}");
if directories.contains(&fuzz_test) && fuzz_id < usize::MAX {
fuzz_id += 1;
} else {
break fuzz_id;
}
}
};

let new_fuzz_test = format!("fuzz_{fuzz_id}");
Expand Down
Loading