Open aleybovich opened 6 years ago
@aleybovich Currently there is not. Agree this might be useful in some cases though.
@cgewecke Is this something you are planning to do or should I close this issue?
@aleybovich I think it should stay open - tagging it as a possible enhancement.
maybe just adopt the existing istanbul interface for ignoring code for coverage ?
@chapati23 Thanks for that link!
@cgewecke - are you planning to implement this in the future? It would be a very useful feature for many, I'm sure. For example, many contracts have trivial setters with no logic besides assigning a variable (like changing a dependent contract address) and those could be excluded from unit tests.
Trivial setters may as well be tested. In my situatian, I have code like
function myFunc(MyEnum memory val) {
if (val == MyEnum.one) {
...
} else if (val == MyEnum.two) {
...
} else {
revert("Invalid enum value");
}
}
As far as I can tell, there is no way to reach the revert in the else
clause. I don't want to remove the revert though in case some day a new value is added, but is not explicitly supported in this function.
Any update?
Love to have this.
A use-case is having internal function overrides required by Solidity during multiple inheritances, but not exposed with a public function.
I have a helper contract that is used just for tests and I want it to be excluded from the coverage results.
This thread https://github.com/sc-forks/solidity-coverage/issues/17 states that ignoring files can be accomplished "using the / istanbul ignore . . . / strategy".
I've not been able to exclude the file or specific code using / istanbul ... / directives.
In the case of a test helper contract, it would be better if the helper contract was excluded from coverage results rather than included and showing as covered (IMO)
maybe just adopt the existing istanbul interface for ignoring code for coverage ?
I couldn't get this to work with hardhat/solidity. It the above meaning that it should be achievable this way now, or a suggestion of a way it could be implemented?
Would like this for stuff like supportsInterface
and overrides of openzeppelin contracts that are required but difficult to test by themselves.
// The following functions are overrides required by Solidity.
function _beforeTokenTransfer(
address operator,
address from,
address to,
uint256[] memory ids,
uint256[] memory amounts,
bytes memory data
) internal override(ERC1155, ERC1155Supply) {
super._beforeTokenTransfer(operator, from, to, ids, amounts, data);
}
function supportsInterface(bytes4 interfaceId)
public
view
override(ERC1155, AccessControl)
returns (bool)
{
return super.supportsInterface(interfaceId);
}
I need this too!
Any updates on this ?
+1, would be very useful.
Is there a way to exclude some solidity code from coverage testing, like its done in JS with istanbul directives in comments?