foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Forge compiles all test contracts when specified to only use one contract.

Open pedrommaiaa opened this issue 3 years ago • 4 comments

Component

Forge

Have you ensured that all of these are up to date?

  • [X] Foundry
  • [X] Foundryup

What version of Foundry are you on?

forge 0.2.0 (935c113 2022-06-22T00:14:50.974796Z)

What command(s) is the bug in?

forge test --match-contract <CONTRACT_NAME>

Operating System

macOS (Apple Silicon)

Describe the bug

I'm not sure if this is intended behavior or not but would be nice if when using forge test --match-contract <CONTRACT_NAME> the only test contract that is compiled is the contract mentioned and all the necessary imports.

This is how the situation unfolded for me:

I made a change in a function in contract A.sol and I have two test contracts BTest.sol and CTest.sol both with tests using that function, I'm aware that tests in contract CTest.sol will fail to compile so I wanted to only test contract BTest.sol. Because forge compiles all contracts at the same time I'm unable to test BTest.sol without fixing CTest.sol.

pedrommaiaa avatar Jun 22 '22 12:06 pedrommaiaa

I see, the contract filter is applied after the project is compiled.

filtering before we compile is not that trivial because of dependencies that may be in conflict with the filter.

But I guess for test contracts it shouldn't be that problematic since those usually only inherit.

this is the first time this came up, so have to think about if support for this scenario is worth adding.

a current workaround would be to use two test folders and two profiles so you can test separately via FOUNDRY_PROFILE=b forge test

mattsse avatar Jun 22 '22 12:06 mattsse

Awesome! Feel free to close this issue if you decide that support won't be added. Would be good to add this to the foundry book if anyone has a similar issue.

pedrommaiaa avatar Jun 22 '22 14:06 pedrommaiaa

Related to sparse mode which had some bugs

onbjerg avatar Aug 11 '22 19:08 onbjerg

same trouble, is there any better solution rather set two folder? it seem pass two yeas👀

skyonedot avatar Apr 26 '24 13:04 skyonedot

Fixed by https://github.com/foundry-rs/foundry/pull/7334 and https://github.com/foundry-rs/foundry/pull/7941

klkvr avatar Jun 02 '24 22:06 klkvr