-
Notifications
You must be signed in to change notification settings - Fork 15
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
Feature request: add a tag for the unit test coverage approach #65
Comments
I see, that sounds super interesting. It's a tiny bit big in scope, but I think it's reasonable. Could you give a more practical example? If I understand correctly, Also, it would be nice to get @PaulRBerg 's opinion as well. |
Modified the op with something hopefully more illustrative. There is indeed an inclusion relation between branch and path, as a full path coverage should be the most exhaustive possible coverage (iirc, one can compute the number of path, as it's just some graph theory), but
This feature request is quite small tho, as it's basically including a tag to the contract (without breaking |
Ah, this is great, now I see it clearly, thanks for sharing! This is really, really useful, so we should actually prioritize it. I think we need to design a bit how it will look like though, not convinced that emitting different contracts is the way. |
Just to be clear, having two different trees for the same function in the same
generates contract TestMe {
function test_FooWhenAAndBAreTrue() external {
// it should return true
}
function test_FooWhenAIsFalse() external {
// it should return false
}
modifier givenAIsTrue() {
_;
}
function test_FooWhenBIsTrue() external givenAIsTrue {
// it should return true
}
function test_FooWhenBIsFalse() external givenAIsTrue {
// it should return false
}
modifier givenAIsFalse() {
_;
}
function test_FooWhenBIsTrue2() external givenAIsFalse {
// it should return false
}
function test_FooWhenBIsFalse2() external givenAIsFalse {
// it should return false
}
} |
You're right, it would be for this example, but in real use-case, one usually pick a single coverage (so this would rather pin the difference between different functions tested using different coverage - random example in the /trees/ files of this pr). For instance, if you're testing a contract with 3 external functions, maybe 2 of them are super short/simple flow (and a path coverage is realistic) while the third one has a huge number of branches and conditional op (so branch coverage is probably better), imo, this difference should be documented somewhere. |
NB this could be used for other test "tags" too actually (fuzz vs static for instance), so a tree comment which is translated to a |
I see, I think this is the key point, right? It shouldn't be surprising to people reading which kind of coverage they are using. I agree this should be clear. An interesting thing to think about is how does the test evolve with the evolution of the function. Say that we used branch coverage initially for this function: bool foo (bool a, bool b) {
if (a && b) {
return true;
}
return false;
}
(which note that is not an entirely correct spec, because the second branch should be something like "Otherwise") But then we change it to: bool foo (bool a, bool b) {
if (a) {
if (b) {
return true;
}
return false;
}
else {
if (b) {
return false;
}
return true;
}
} (this function is just Now path coverage is the easier way to maintain the spec.
Could you expand a bit with an example of this? Sorry about all the back and forth, I want to make sure we get this right. |
unfortunately not able to reviesw this proposal at this time, tagging @andreivladbrg and @smol-ninja in case they want to contribute. |
Path-coverage driven development :D ? But yes, you're now laying out the different path explicitly, not sure we should all start coding such tho 🥲
I don't do such separation personally (I rather tend to cover a given path then fuzz within it, a bit like how concolic fuzzing would work iic), but some repo's are maintaining different folder for static vs fuzzed tests, maybe interesting to have this kind of added doc for them too? I had a bit of a shower thought and was thinking of closing this issue for another one with a slightly different scope (encompassing this one): _parsing the comments after a root or a |
Sry for the delayed response!
Hmmm, could you give a practical example of how this would look like? |
Sure! In other words, it's including the comments as additional
would generate /// @dev This is a branch coverage.
contract TestMe {
function test_FooWhenAAndBAreTrue() external {
// it should return true
}
/// @dev b false would cover the same branch.
function test_FooWhenAIsFalse() external {
// it should return false
}
} |
Cool, that makes sense 👍 The example is not accurate though, because
which generates contract TestMefoo {
modifier whenAIsFalse() {
_;
}
function test_WhenBIsFalse() external whenAIsFalse {
// it should return false
}
} Which comment should become the natspec? |
I think this should become: /// @dev This is a branch coverage.
contract TestMefoo {
/// @dev first comment.
modifier whenAIsFalse() {
_;
}
/// @dev second comment.
function test_WhenBIsFalse() external whenAIsFalse {
// it should return false
}
} wdyt? |
Sgtm, let's do it! |
I think this doesn't need a CLI flag since it's additive and makes sense. I'd rather we don't emit |
As always, if you need any help lmk. If you don't plan to work on it lmk as well. |
Hmm, true, natspecs only makes sense if docs are generated, which is perhaps not routinely done for tests. |
WIP branch: https://github.com/drgorillamd/bulloak/tree/feat/function-comments |
It's looking good! Parsing is the roughest part of the code, so good luck! 🙈 |
It would be interesting to find a way to specify the coverage used while building a tree (and reflect it in the test contract name or top-level comment).
For instance, for the following function and coverage type, we'd scaffold 2 tests contracts which we could name
Foo_Test_Branch
andFoo_Test_FullPath
based on the following coverages (amongst other possibilities):
with the tree
with the following tree
The text was updated successfully, but these errors were encountered: