diff --git a/crates/forge/bin/main.rs b/crates/forge/bin/main.rs index 1c7095026e29..2aaa82d62fdb 100644 --- a/crates/forge/bin/main.rs +++ b/crates/forge/bin/main.rs @@ -82,6 +82,11 @@ fn main() -> Result<()> { ForgeSubcommand::Clean { root } => { let config = utils::load_config_with_root(root); config.project()?.cleanup()?; + + // Remove fuzz cache directory. + if let Some(fuzz_cache) = config.fuzz.failure_persist_dir { + let _ = std::fs::remove_dir_all(fuzz_cache); + } Ok(()) } ForgeSubcommand::Snapshot(cmd) => { diff --git a/crates/forge/tests/cli/cmd.rs b/crates/forge/tests/cli/cmd.rs index df6a306f5cab..a4deb8bcef3d 100644 --- a/crates/forge/tests/cli/cmd.rs +++ b/crates/forge/tests/cli/cmd.rs @@ -2,7 +2,9 @@ use crate::constants::*; use foundry_compilers::{artifacts::Metadata, remappings::Remapping, ConfigurableContractArtifact}; -use foundry_config::{parse_with_profile, BasicConfig, Chain, Config, SolidityErrorCode}; +use foundry_config::{ + parse_with_profile, BasicConfig, Chain, Config, FuzzConfig, SolidityErrorCode, +}; use foundry_test_utils::{ foundry_compilers::PathStyle, rpc::next_etherscan_api_key, @@ -544,6 +546,20 @@ forgetest_init!(can_clean_config, |prj, cmd| { assert!(!artifact.exists()); }); +// checks that `clean` removes fuzz cache dir +forgetest_init!(can_clean_fuzz_cache, |prj, cmd| { + let config = Config { fuzz: FuzzConfig::new("cache/fuzz".into()), ..Default::default() }; + prj.write_config(config); + // default test contract is written in custom out directory + let cache_dir = prj.root().join("cache/fuzz"); + let _ = fs::create_dir(cache_dir.clone()); + assert!(cache_dir.exists()); + + cmd.forge_fuse().arg("clean"); + cmd.output(); + assert!(!cache_dir.exists()); +}); + // checks that extra output works forgetest_init!(can_emit_extra_output, |prj, cmd| { cmd.args(["build", "--extra-output", "metadata"]);