foundry icon indicating copy to clipboard operation
foundry copied to clipboard

`forge coverage --contracts contracts` is including tests & script directories

Open gigamesh opened this issue 3 years ago • 1 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 (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?

image

gigamesh avatar Sep 09 '22 15:09 gigamesh

@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

rkrasiuk avatar Sep 09 '22 16:09 rkrasiuk

Looks like you can do this via the lcov tool, as in:

forge coverage --report lcov
lcov --remove lcov.info 'test/*' 'script/*' > lcov.info

hayesgm avatar Oct 13 '22 21:10 hayesgm

Looks like you can do this via the lcov tool, 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

PierrickGT avatar Oct 17 '22 23:10 PierrickGT

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?

DucaRick avatar Oct 26 '22 15:10 DucaRick

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!

PierrickGT avatar Nov 01 '22 01:11 PierrickGT

Isn't this issue a duplicate of #2988?

PaulRBerg avatar Feb 08 '23 16:02 PaulRBerg

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 avatar May 01 '23 07:05 yohanelly95

@yohanelly95 you can use --match-path unit/**/*.sol.

Related: https://github.com/foundry-rs/foundry/issues/3841

PaulRBerg avatar May 01 '23 07:05 PaulRBerg

You might also want to refactor your tests to use @mds1's test naming convention so that you can use filtering regexes.

PaulRBerg avatar May 01 '23 07:05 PaulRBerg

@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

yohanelly95 avatar May 01 '23 08:05 yohanelly95

No worries. The benefit of using a community-wide naming standard is that linting tools can be built on top of, e.g. ScopeLint.

PaulRBerg avatar May 01 '23 09:05 PaulRBerg

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

zerosnacks avatar Jun 26 '24 12:06 zerosnacks