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: always compile sources when running tests #7572

Merged
merged 1 commit into from
Apr 5, 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
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));
Comment on lines +204 to +205
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah this makes sense


Ok(test_sources)
}

/// Executes all the tests in the project.
Expand Down
Loading