You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// SPDX-License-Identifier: BSD-3-Clause-Clearpragma solidity0.8.22;
contractBranch {
function branch(boollhs, boolrhs) externalreturns (bool){
bool result;
if (lhs || rhs){
result =true;
}
return result;
}
}
With this simple test:
// SPDX-License-Identifier: UNLICENSEDpragma solidity0.8.22;
import {Test, console2} from"forge-std/Test.sol";
import {Branch} from"../src/Branch.sol";
contractBranchTestisTest {
Branch public branch;
function setUp() public {
branch =newBranch();
}
function test_branch() public {
branch.branch(true,false);
}
}
forge coverage (latest forge version, with default params) returns 100% coverage for % Branches, which is obviously incorrect. On the other hand, the saùe test returns 50% coverage with hardhat coverage which seems more correct.
The text was updated successfully, but these errors were encountered:
I think there is a logical error in your test setup as you run the test once and there is no branching occuring as lhs evaluates, skipping over rhs.
if (lhs || rhs){
result = true;
}
Rewriting the test as
contract Branch {
function branch(bool foo) external returns (bool){
bool result;
if (foo) {
result = true;
} else {
result = false;
}
return result;
}
}
contract BranchTest is Test {
Branch public branch;
function setUp() public {
branch = new Branch();
}
function test_branch() public {
branch.branch(true);
}
}
Component
Forge
Have you ensured that all of these are up to date?
What version of Foundry are you on?
forge 0.2.0 (3d6bfdd 2023-12-16T00:20:53.761034000Z)
What command(s) is the bug in?
forge coverage
Operating System
macOS (Apple Silicon)
Describe the bug
I tested this contract :
With this simple test:
forge coverage
(latest forge version, with default params) returns 100% coverage for % Branches, which is obviously incorrect. On the other hand, the saùe test returns 50% coverage with hardhat coverage which seems more correct.The text was updated successfully, but these errors were encountered: