-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Forge Coverage does not include testFail_ unit test functions #4259
Comments
FWIW, it is not recommended to use |
Agree that testFail is an anti-pattern, I use it anyways because I am lazy if Foundry devs don't want us using the anti-pattern they should remove or deprecate the feature if they do not want to remove or deprecate the feature then they should make it work with coverage |
IIRC the reason Refactoring to use function test_RevertWhen_Smth() external {
vm.expectRevert();
foo.call();
} you don't necessarily have to pass a revert reason string or a custom error selector - passing no arg will pass the test for any revert. |
Yes I am well aware that you can refactor the code to get coverage to work My point is it's a betrayal of user expectations, since you generally expect features in a dev environment to work with each other If you don't want to make testFail work, then maybe a good move would be to explicitly inform folks testFail is deprecated in the foundry book and tell people not to use it, or to remove mentions of testFail at all in the foundry book either way, I don't care, Foundry devs should do whatever they want, this is obviously a minor issue and if the devs want to #wontfix it then you can close the issue. I just wanted folks to be aware that the current way took at least 5 minutes out of my day to realize the coverage was not working with the testFail feature |
Foundry is an open-source project, ser. It is as much your and my own responsibility to make this piece of software better - nat just the core maintainers'. At any rate, I agree that the Foundry Book should be updated to indicate that |
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (cd7850b 2023-02-02T00:07:41.087456684Z)
What command(s) is the bug in?
forge coverage
Operating System
Linux
Describe the bug
Hi All,
Apologies if this bug is a duplicate or known issue, I did not see anything when I searched for it.
The
forge coverage
tool does not appear to consider any functions called inside a testFail type test as valid calls of a function for coverage. Example below:Sample Code
src/Counter.sol
test/Counter.t.sol
foundry.toml
Expected Correct Output
The coverage tool should print that the percentage of functions called is greater than 0, since the
setNumber
function was called in thetestFail_setNumber
test.The text was updated successfully, but these errors were encountered: