From 710ba992da07991cc9f5edcd06b3d5477c307890 Mon Sep 17 00:00:00 2001 From: lukacan Date: Thu, 1 Feb 2024 15:23:56 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FIX:=20Check=20fuzz=20test=20nam?= =?UTF-8?q?e=20collision=20by=20checking=20the=20name=20against=20HashSet?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- crates/client/src/test_generator.rs | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/crates/client/src/test_generator.rs b/crates/client/src/test_generator.rs index 860b9b39..85748ac0 100644 --- a/crates/client/src/test_generator.rs +++ b/crates/client/src/test_generator.rs @@ -212,18 +212,26 @@ 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 .read_dir() .unwrap() - .map(|r| r.unwrap()) + .map(|r| r.unwrap().file_name().to_str().unwrap().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 += 1; + } else { + break fuzz_id; + } + } }; let new_fuzz_test = format!("fuzz_{fuzz_id}");