@@ -3,7 +3,7 @@ use crate::{
33 MultiContractRunner , MultiContractRunnerBuilder ,
44 decode:: decode_console_logs,
55 gas_report:: GasReport ,
6- multi_runner:: { is_test_contract , matches_artifact} ,
6+ multi_runner:: matches_artifact,
77 result:: { SuiteResult , TestOutcome , TestStatus } ,
88 traces:: {
99 CallTraceDecoderBuilder , InternalTraceMode , TraceKind ,
@@ -24,8 +24,8 @@ use foundry_common::{
2424 EmptyTestFilter , TestFunctionExt , compile:: ProjectCompiler , evm:: EvmArgs , fs, shell,
2525} ;
2626use foundry_compilers:: {
27- ProjectCompileOutput , artifacts:: output_selection:: OutputSelection ,
28- compilers:: multi:: MultiCompiler ,
27+ Language , ProjectCompileOutput , artifacts:: output_selection:: OutputSelection ,
28+ compilers:: multi:: MultiCompiler , multi :: MultiCompilerLanguage , utils :: source_files_iter ,
2929} ;
3030use foundry_config:: {
3131 Config , figment,
@@ -207,17 +207,18 @@ impl TestArgs {
207207 /// This means that it will return all sources that are not test contracts or that match the
208208 /// filter. We want to compile all non-test sources always because tests might depend on them
209209 /// dynamically through cheatcodes.
210- ///
211- /// Returns `None` if all sources should be compiled.
212210 #[ instrument( target = "forge::test" , skip_all) ]
213211 pub fn get_sources_to_compile (
214212 & self ,
215213 config : & Config ,
216214 test_filter : & ProjectPathsAwareFilter ,
217- ) -> Result < Option < BTreeSet < PathBuf > > > {
215+ ) -> Result < BTreeSet < PathBuf > > {
218216 // An empty filter doesn't filter out anything.
217+ // We can still optimize slightly by excluding scripts.
219218 if test_filter. is_empty ( ) {
220- return Ok ( None ) ;
219+ return Ok ( source_files_iter ( & config. src , MultiCompilerLanguage :: FILE_EXTENSIONS )
220+ . chain ( source_files_iter ( & config. test , MultiCompilerLanguage :: FILE_EXTENSIONS ) )
221+ . collect ( ) ) ;
221222 }
222223
223224 let mut project = config. create_project ( true , true ) ?;
@@ -230,15 +231,14 @@ impl TestArgs {
230231 eyre:: bail!( "Compilation failed" ) ;
231232 }
232233
233- let sources = output
234+ Ok ( output
234235 . artifact_ids ( )
235236 . filter_map ( |( id, artifact) | artifact. abi . as_ref ( ) . map ( |abi| ( id, abi) ) )
236237 . filter ( |( id, abi) | {
237- ! is_test_contract ( abi . functions ( ) ) || matches_artifact ( test_filter, id, abi)
238+ id . source . starts_with ( & config . src ) || matches_artifact ( test_filter, id, abi)
238239 } )
239240 . map ( |( id, _) | id. source )
240- . collect :: < BTreeSet < _ > > ( ) ;
241- Ok ( Some ( sources) )
241+ . collect ( ) )
242242 }
243243
244244 /// Executes all the tests in the project.
@@ -275,7 +275,7 @@ impl TestArgs {
275275 let compiler = ProjectCompiler :: new ( )
276276 . dynamic_test_linking ( config. dynamic_test_linking )
277277 . quiet ( shell:: is_json ( ) || self . junit )
278- . files ( self . get_sources_to_compile ( & config, & filter) ?. unwrap_or_default ( ) ) ;
278+ . files ( self . get_sources_to_compile ( & config, & filter) ?) ;
279279 let output = compiler. compile ( & project) ?;
280280
281281 // Create test options from general project settings and compiler output.
0 commit comments