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(coverage): lcov avoid double reporting for line hit #8400

Merged
merged 4 commits into from
Jul 12, 2024

Conversation

grandizzy
Copy link
Collaborator

Motivation

The line hit is reported doubled in lcov report. That can be repro with a contract

contract AContract {
    int256 public i;

    function foo() public {
        i = 1;
    }
}

and test

contract AContractTest is Test {
    function testFoo() public {
        AContract a = new AContract();
        a.foo();
    }
}

running
forge coverage --report lcov && genhtml lcov.info -o report && firefox report/index.html will generate report below

image

That happens because the generated lcov report contains DA:8,1 line 2 times (DA: line number, hit count)

Solution

  • avoid adding line hit count twice (as a line and also as a statement)

@grandizzy grandizzy marked this pull request as ready for review July 10, 2024 14:56
@grandizzy grandizzy requested a review from zerosnacks July 10, 2024 14:57
Copy link
Member

@DaniPopes DaniPopes left a comment

Choose a reason for hiding this comment

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

Needs snapbox assertions

@grandizzy
Copy link
Collaborator Author

Needs snapbox assertions

not sure how to do that since this one is LCOV report related only (that is to make sure certain line is not written twice in lcov.info file), do you have any suggestion? thanks

@DaniPopes
Copy link
Member

DaniPopes commented Jul 11, 2024

Just replace assert_eq! with assert_data_eq!, and use str![] for the string literal

@grandizzy
Copy link
Collaborator Author

Just replace assert_eq! with assert_data_eq!, and use str![] for the string literal

done ba4d759 thank you!

@grandizzy grandizzy requested a review from DaniPopes July 12, 2024 06:31
@DaniPopes DaniPopes merged commit 5b84163 into foundry-rs:master Jul 12, 2024
20 checks passed
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