Improved generator tracking

* Successive executions of the same `GENERATE` macro (e.g. because
of a for loop) no longer lead to multiple nested generators.
* The same line can now contain multiple `GENERATE` macros without
issues.

Fixes #1913
This commit is contained in:
Martin Hořeňovský
2020-06-01 19:04:23 +02:00
parent 3ceaad7d66
commit 480f3f418b
18 changed files with 283 additions and 26 deletions

View File

@@ -255,6 +255,22 @@ TEST_CASE("Copy and then generate a range", "[generators]") {
}
}
TEST_CASE("#1913 - GENERATE inside a for loop should not keep recreating the generator", "[regression][generators]") {
static int counter = 0;
for (int i = 0; i < 3; ++i) {
int _ = GENERATE(1, 2);
(void)_;
++counter;
}
// There should be at most 6 (3 * 2) counter increments
REQUIRE(counter < 7);
}
TEST_CASE("#1913 - GENERATEs can share a line", "[regression][generators]") {
int i = GENERATE(1, 2); int j = GENERATE(3, 4);
REQUIRE(i != j);
}
#if defined(__clang__)
#pragma clang diagnostic pop
#endif