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

document forge coverage #567

Closed
devtooligan opened this issue Aug 28, 2022 · 4 comments
Closed

document forge coverage #567

devtooligan opened this issue Aug 28, 2022 · 4 comments
Assignees
Labels
A-forge Area: forge S-blocked Status: Blocked T-new Type: new docs

Comments

@devtooligan
Copy link
Contributor

see foundry-rs/foundry#1576

@onbjerg
Copy link
Member

onbjerg commented Sep 1, 2022

Blocked since coverage is still not considered stable even for foundry.

@onbjerg onbjerg added A-forge Area: forge T-new Type: new docs S-blocked Status: Blocked labels Sep 1, 2022
@onbjerg onbjerg self-assigned this Sep 1, 2022
@artdgn
Copy link

artdgn commented Dec 22, 2022

Information on usage (and even the availability of the feature) was hard to find.

Perhaps it's worth to find some sort of a solution for new / potentially unstable features that would balance the usefulness of being able to find basic documentation using a search engine, with maintenance effort. I don't know how it's currently set up, but maybe some auto-generated documentation from the latest implementation docstrings can be an option.

@Cezarry
Copy link

Cezarry commented Apr 22, 2024

Hey, I'm trying forge coverage on test project and it's not detecting all branches (for me 1 branch is missing by coverage).
Function to test:

    function deposit() external payable {
        if (msg.value == 0) {
            revert CanNotDepositZeroEthers();
        }

        if (charity.canDonate()) {
            uint256 charityAmount = (msg.value * charityPercentage) / 1000;
            charity.donate{value: charityAmount}();
        }
    }

Tests:

    function test_Deposit_WithDonation() public {
        uint256 expectedDonatedAmount = (depositAmount * charityPercentage) / 1000;
        uint256 expectedDepositAmount = depositAmount - expectedDonatedAmount;

        _deposit(address(this), depositAmount);

        assertEq(address(charity).balance, expectedDonatedAmount);
        assertEq(address(wallet).balance, expectedDepositAmount);
    }

    function test_Deposit_WithoutDonation() public {
        uint256 expectedDonatedAmount = 0;
        uint256 expectedDepositAmount = depositAmount;
        uint256 charityDeadline = charity.moneyCollectingDeadline();
        vm.warp(charityDeadline);

        _deposit(address(this), depositAmount);

        assertEq(address(charity).balance, expectedDonatedAmount);
        assertEq(address(wallet).balance, expectedDepositAmount);
    }

so my if statement is covered by those two tests, but coverage debug says:

- Function "" (location: source ID 28, line 16, chars 332-537, hits: 0)
- Line (location: source ID 28, line 17, chars 423-437, hits: 0)
- Statement (location: source ID 28, line 17, chars 423-437, hits: 0)
- Line (location: source ID 28, line 18, chars 447-482, hits: 0)
- Statement (location: source ID 28, line 18, chars 447-482, hits: 0)
- Line (location: source ID 28, line 19, chars 492-530, hits: 0)
- Statement (location: source ID 28, line 19, chars 492-530, hits: 0)
- Branch (branch: 1, path: 0) (location: source ID 28, line 29, chars 723-877, hits: 0)

where line 29 is if (charity.canDonate()). Any ideas? :)

@zerosnacks
Copy link
Member

Marking as resolved by https://book.getfoundry.sh/reference/forge/forge-coverage#forge-coverage and people generally seem to find their way around the command

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-forge Area: forge S-blocked Status: Blocked T-new Type: new docs
Projects
No open projects
Status: Done
Development

No branches or pull requests

5 participants