Skip to content

Commit

Permalink
fix: always compile sources when running tests (#7572)
Browse files Browse the repository at this point in the history
  • Loading branch information
klkvr authored Apr 5, 2024
1 parent dfab23e commit c2162e2
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions crates/forge/bin/cmd/test/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -166,13 +166,13 @@ impl TestArgs {
.collect::<BTreeMap<_, _>>();

// 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::<BTreeSet<_>>();

if sources.is_empty() {
if test_sources.is_empty() {
if filter.is_empty() {
println!(
"No tests found in project! \
Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit c2162e2

Please sign in to comment.