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

fix(forge): add coverage to test setUp #6123

Merged
merged 2 commits into from
Nov 3, 2023

Conversation

Inphi
Copy link
Contributor

@Inphi Inphi commented Oct 26, 2023

Motivation

Improve forge coverage reporting of functions called during test setUp. This allows initializer functions, but not ctors, called during setUp (ex: #4553) to be covered.

Solution

The TestSetup is extended to include coverage info. The setUp coverage is then merged with HitMaps generated by test runners.

Consider the coverage reporting of the CounterTest:test_Increment test generated by forge init. Prior to this change, we see that Counter.setNumber isn't covered because it's only called during setUp:
image

With this patch, we get full test coverage in Counter.sol:
image

@Inphi Inphi marked this pull request as ready for review October 26, 2023 15:43
Copy link
Member

@Evalir Evalir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks reasonable—Is it possible for you to provide a screenshot of this working when using lcov or something similar for vis? Just to ensure everything looks okay.

Copy link
Member

@Evalir Evalir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this will also need rebasing—sorry about this, lots of moving parts rn, we'll be done soon!

@Inphi
Copy link
Contributor Author

Inphi commented Nov 1, 2023

@Evalir Thanks for the review. PR's been rebased and I've added lcov generated reports of the changes to the PR description.

Copy link
Member

@Evalir Evalir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice, looks reasonable, and tests look good. Pending @mattsse and nit

crates/forge/src/runner.rs Outdated Show resolved Hide resolved
@mattsse mattsse merged commit 65e7f98 into foundry-rs:master Nov 3, 2023
16 checks passed
@Inphi Inphi deleted the inphi/setup-cov branch November 3, 2023 15:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants