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

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

Closed
2 tasks done
pedrommaiaa opened this issue Jun 22, 2022 · 5 comments
Closed
2 tasks done
Assignees
Labels
C-forge Command: forge Cmd-forge-build Command: forge build Cmd-forge-test Command: forge test T-bug Type: bug

Comments

@pedrommaiaa
Copy link
Contributor

Component

Forge

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

  • Foundry
  • 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 pedrommaiaa added the T-bug Type: bug label Jun 22, 2022
@onbjerg onbjerg added this to Foundry Jun 22, 2022
@onbjerg onbjerg moved this to Todo in Foundry Jun 22, 2022
@mattsse
Copy link
Member

mattsse commented Jun 22, 2022

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

@pedrommaiaa
Copy link
Contributor Author

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.

@onbjerg onbjerg added Cmd-forge-test Command: forge test C-forge Command: forge Cmd-forge-build Command: forge build labels Jun 22, 2022
@onbjerg onbjerg added this to the v1.0.0 milestone Aug 11, 2022
@onbjerg
Copy link
Member

onbjerg commented Aug 11, 2022

Related to sparse mode which had some bugs

@onbjerg onbjerg removed this from the v1.0.0 milestone Aug 23, 2022
@skyonedot
Copy link

skyonedot commented Apr 26, 2024

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

@klkvr
Copy link
Member

klkvr commented Jun 2, 2024

Fixed by #7334 and #7941

@klkvr klkvr closed this as completed Jun 2, 2024
@jenpaff jenpaff moved this from Todo to Completed in Foundry Sep 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-forge Command: forge Cmd-forge-build Command: forge build Cmd-forge-test Command: forge test T-bug Type: bug
Projects
Status: Completed
Development

No branches or pull requests

5 participants