-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
GENERATE macro causes assertion failure if used after a SECTION #1938
Comments
This is definitely not intended, but I have some misgivings about the semantics after this is fixed. TEST_CASE() {
SECTION("A") { ... }
int i = GENERATE(1, 2);
SECTION("B") { ... }
} feels like it should run "A" once and "B" twice, but the only reasonable implementation requires "A" to be run twice as well. |
Agreed that it would make sense to only run A once in that example. That's certainly what I'd expect. |
Well, I have a prototype (and very, very, very ugly) implementation for this. After playing around with it, I am not sure how happy I am with how the tests look vs how they run. The problem is that while the simple case makes sense, and the following runs 3 assertions TEST_CASE() {
SECTION("first") { SUCCEED(); }
int _ = GENERATE(1, 2);
SECTION("second") { SUCCEED(); }
} nesting this further can make the result quite confusing. Even though I just implemented the feature, I had to draw a diagram to figure out why the code below reports 14 assertions. TEST_CASE("#1938 - mixed sections and generates") {
auto i = GENERATE(1, 2);
SECTION("A") {
SUCCEED("A");
}
auto j = GENERATE(3, 4);
SECTION("B") {
SUCCEED("B");
}
auto k = GENERATE(5, 6);
CAPTURE(i, j, k);
SUCCEED();
} So, the way I see it, there are 3 possibilities here
I will have to think about which one I prefer. |
What you have there (I think described as case 2) seems totally expected to me. I wasn't surprised to see 14 assertions:
Option (3) seems like it would just lead to extra runtime without any benefit, since those later generators cannot possibly be seen by earlier code. Option (1) seems like a shame, as disabling this really limits the use of GENERATE. I assume that if someone wrote TEST_CASE("") {
SECTION("A") {
auto i = GENERATE(1, 2);
SUCCEED("A");
}
SECTION("B") {
SUCCEED("B");
}
} this would still only lead to 3 assertions? 2 in section |
This means that code such as ```cpp TEST_CASE() { SECTION("first") { SUCCEED(); } auto _ = GENERATE(1, 2); SECTION("second") { SUCCEED(); } } ``` will run and report 3 assertions, 1 from section "first" and 2 from section "second". This also applies for greater and potentially more confusing nesting, but fundamentally it is up to the user to avoid overly complex and confusing nestings, just as with `SECTION`s. The old behaviour of `GENERATE` as first thing in a `TEST_CASE`, `GENERATE` not followed by a `SECTION`, etc etc should be unchanged. Closes #1938
Describe the bug
Using
GENERATE
after aSECTION
causes an assertion failure ontracker.isOpen()
.Expected behavior
The following code:
runs cleanly.
Actual behavior
An assertion failure occurs during the
GENERATE
code:Commenting out the
SECTION("foo") {}
line causes the test to succeed.Reproduction steps
Platform information:
Additional context
Not sure if this is expected to work (would be nice if it did though!), but if not, it would be great if the message was friendlier!
The text was updated successfully, but these errors were encountered: