-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
When the same SECTION is encountered multiple times in one cycle, catch crashes on assert #2802
Comments
Note: this should hopefully be somewhat coherent, but I've been staring at the code for a few hours and it's late, so sorry if it isnt 😄 The problemWhen the section is acquired the second time, we have already So, the minimal solution is to not enter the section if So, could we just check The solutionSo, we cannot hack it, we have to do it properly. The goal is to track if a section was already encountered during the current cycle and if so, it's an error. I think the most robust solution is to remember the serial number of the cycle in each Extension of the solutionAlternatively, instead of erroring out, we can say "ok, let's make this a new section and make it work". That would mean that the section tracker tracks also "generation" in addition to name and location. What about generatorsI think it could work the same - if we encounter a generator a second time in the same cycle, we just say it's a different generator. Although I have not studied how generators are implemented yet - even understanding how sections work took me a few hours. Why it might not be a good idea after allThe problem comes with reporting - how do we distinguish between the two identical sections? We don't. Hence, I think we should force the user to insert (dynamic) sections to make the sections unique. How to report the errorCatch should probably just throw an exception. But could the malicious user just |
Another potentially interesting test case with generators: TEST_CASE("foo") {
std::cout << "new run\n";
for (int i = 0; i < 3; ++i) {
SECTION("section") {
int n = GENERATE(1, 2);
std::cout << n << "\n";
}
}
} Edit: probably not interesting after all - it's the SECTION that will make it or break it. And generators directly in a loop are handled correctly now. |
Describe the bug
Suppose we have nested SECTIONs in a helper function and call that function from one TEST_CASE, from the same section. Then the same sections are entered multiple times (because they have the same name and location). The same could be achieved by a loop.
In that scenario, Catch asserts/segfaults (see the attached compiler explorer link).
Expected behavior
Either it should work "as expected", or it should error out with a reasonable error message. Also, the documentation of
SECTION
should include clear warning that this is not supported (also a link toDYNAMIC_SECTION
would be handy).Reproduction steps
https://godbolt.org/z/rMP8vf6xe
Platform information:
The text was updated successfully, but these errors were encountered: