`forge coverage --contracts contracts` is including tests & script directories
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 (f540aa9 2022-09-09T00:09:51.262286Z)
What command(s) is the bug in?
forge coverage --contracts contracts
Operating System
No response
Describe the bug
Shouldn't this only be including what is in my contracts dir?
@gigamesh --contracts is one of the project options specifying the dir, where the source files are located. i am not sure that coverage target filtering is supported yet, correct me if I'm wrong @onbjerg. it can only filter the tests, not the target contracts
Looks like you can do this via the lcov tool, as in:
forge coverage --report lcov
lcov --remove lcov.info 'test/*' 'script/*' > lcov.info
Looks like you can do this via the
lcovtool, as in:forge coverage --report lcov lcov --remove lcov.info 'test/*' 'script/*' > lcov.info
I get the following error when running this command:
lcov: ERROR: no valid records found in tracefile lcov.info
Below works for me:
forge coverage --report lcov
lcov --remove lcov.info -o lcov.info '**/**/test/**' '**/**/mocks/**.sol'
@PierrickGT For you this would translate to:
forge coverage --report lcov
lcov --remove lcov.info -o lcov.info 'test/*' 'script/*'
If still no records are found, maybe your file filter is not right?
Below works for me:
forge coverage --report lcov lcov --remove lcov.info -o lcov.info '**/**/test/**' '**/**/mocks/**.sol'@PierrickGT For you this would translate to:
forge coverage --report lcov lcov --remove lcov.info -o lcov.info 'test/*' 'script/*'If still no records are found, maybe your file filter is not right?
Ah thanks, it works!
Isn't this issue a duplicate of #2988?
problem I am facing is forge coverage tends to Run tests, and since I have a few fuzzed tests it takes way too long. I want coverage to ignore the fuzzed tests which Ive included in a separate folder inside the test folder (/tests/fuzzing).
Any way around this? I've gone through the pruning of lcov and thats fine. But since forge coverage itself takes so long I want to reduce the time taken by ignore all fuzzed tests. cc @PaulRBerg
@yohanelly95 you can use --match-path unit/**/*.sol.
Related: https://github.com/foundry-rs/foundry/issues/3841
You might also want to refactor your tests to use @mds1's test naming convention so that you can use filtering regexes.
@yohanelly95 you can use
--match-path unit/**/*.sol.Related: #3841
I see so I tried something like forge coverage --no-match-path test/fuzzed/**.sol and it seemed to work. I am using a naming convention but without the _ will consider making the naming convention changes. Thank you! @PaulRBerg
No worries. The benefit of using a community-wide naming standard is that linting tools can be built on top of, e.g. ScopeLint.
Marking as duplicate of https://github.com/foundry-rs/foundry/issues/2988
Planning to be resolved by https://github.com/foundry-rs/foundry/pull/7301