foundry icon indicating copy to clipboard operation
foundry copied to clipboard

Tracking: Coverage

Open onbjerg opened this issue 2 years ago • 6 comments

There's still some missing features and improvements for coverage:

Data/functionality

  • [x] #1962
  • [x] #1963
  • [x] #1964
  • [x] #1967
  • [x] #1965

User facing

  • [ ] #1966

Misc

  • [x] #1969
  • [ ] #1968

onbjerg avatar Jun 14 '22 20:06 onbjerg

@onbjerg When I run forge coverage at https://github.com/nation3/court, I get this error:

could not find anchor: no matching instruction in range CollateralAgreementFramework:3834:2:7
forge coverage 
warning: Unknown section [default] found in foundry.toml. This notation for profiles has been deprecated and may result in the profile not being registered in future versions. Please use [profile.default] instead or run `forge config --fix`.
warning: Unknown section [default] found in lib/solmate/foundry.toml. This notation for profiles has been deprecated and may result in the profile not being registered in future versions. Please use [profile.default] instead or run `forge config --fix`.
warning: Unknown section [intense] found in lib/solmate/foundry.toml. This notation for profiles has been deprecated and may result in the profile not being registered in future versions. Please use [profile.default] instead or run `forge config --fix`.
[⠒] Compiling...
[⠒] Compiling 11 files with 0.8.14
[⠑] Solc 0.8.14 finished in 992.33ms
Compiler run successful
Analysing contracts...
Error: 
could not find anchor: no matching instruction in range CollateralAgreementFramework:3834:2:7

Does could not find anchor mean that we are missing some code coverage configuration in our project?

forge --version
forge 0.2.0 (37e4376 2022-07-16T00:05:51.461078Z)

aahna-ashina avatar Jul 16 '22 03:07 aahna-ashina

Please check the other issues on coverage - this is not on your side, but coverage is not stable yet, so there are edge cases that are not covered. This is one edge case where it could not find an opcode that matches the source range, so we fail and return instead of showing a potentially incorrect coverage report

onbjerg avatar Jul 16 '22 18:07 onbjerg

@onbjerg Is there a way to exclude *.sol files in the test/ folder when running forge coverage?

aahna-ashina avatar Aug 18 '22 01:08 aahna-ashina

@aahna-ashina I had the same question and what I ended up doing is exclude them in codecov.yml instead with:

ignore:
  - "./tests/"

elenadimitrova avatar Aug 18 '22 06:08 elenadimitrova

Thanks @elenadimitrova, great idea to ignore the tests in Codecov directly.

However, it should be possible to do this with Forge itself - ideally, there would be a --ignore flag in the forge coverage command.

I created an issue to track this as a feature request: https://github.com/foundry-rs/foundry/issues/4006.

Update: it looks like it is not possible to ignore globs on all coverage tracking platforms - for instance, Coveralls doesn't offer this feature. Thus, it would be really helpful for Foundry to have an --ignore flag.

PaulRBerg avatar Jan 02 '23 10:01 PaulRBerg

I have recently discovered several bugs in the coverage command. Posting here for cross-reference:

  • [ ] https://github.com/foundry-rs/foundry/issues/4294
  • [x] https://github.com/foundry-rs/foundry/issues/4305
  • [ ] https://github.com/foundry-rs/foundry/issues/4309
  • [ ] https://github.com/foundry-rs/foundry/issues/4310
  • [ ] https://github.com/foundry-rs/foundry/issues/4311
  • [ ] https://github.com/foundry-rs/foundry/issues/4314
  • [ ] https://github.com/foundry-rs/foundry/issues/4315
  • [ ] https://github.com/foundry-rs/foundry/issues/4316

PaulRBerg avatar Feb 12 '23 19:02 PaulRBerg