From acc610ddc8be0a5cbb50755dd8e2bce837ab1663 Mon Sep 17 00:00:00 2001 From: Arsenii Kulikov Date: Fri, 5 Apr 2024 21:45:52 +0400 Subject: [PATCH] fix: always compile sources when running tests --- crates/forge/bin/cmd/test/mod.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/crates/forge/bin/cmd/test/mod.rs b/crates/forge/bin/cmd/test/mod.rs index b4c26e7ee175..104fa4c486e0 100644 --- a/crates/forge/bin/cmd/test/mod.rs +++ b/crates/forge/bin/cmd/test/mod.rs @@ -20,7 +20,7 @@ use foundry_common::{ evm::EvmArgs, shell, }; -use foundry_compilers::artifacts::output_selection::OutputSelection; +use foundry_compilers::{artifacts::output_selection::OutputSelection, utils::source_files_iter}; use foundry_config::{ figment, figment::{ @@ -166,13 +166,13 @@ impl TestArgs { .collect::>(); // Filter sources by their abis and contract names. - let sources = abis + let mut test_sources = abis .iter() .filter(|(id, abi)| matches_contract(id, abi, filter)) .map(|(id, _)| id.source.clone()) .collect::>(); - if sources.is_empty() { + if test_sources.is_empty() { if filter.is_empty() { println!( "No tests found in project! \ @@ -201,7 +201,10 @@ impl TestArgs { eyre::bail!("No tests to run"); } - Ok(sources) + // Always recompile all sources to ensure that `getCode` cheatcode can use any artifact. + test_sources.extend(source_files_iter(project.paths.sources)); + + Ok(test_sources) } /// Executes all the tests in the project.