catch3
Progmasoft Catch3: an independently maintained C++17 test framework with a parallel runner, property checks, snapshots and structured results.
Clonegit clone https://git.progmasoft.com/catch3
Fix ChunkGenerator with chunk-size 0
- Commit
9cf5897a11154bab4d561c80ab66ef33ecc91838- Author
- David Sommerich ·
- Parents
6f32c67ea763
Changes
include/internal/catch_generators_generic.hpp | 12 +++--- .../SelfTest/Baselines/compact.sw.approved.txt | 3 ++ .../SelfTest/Baselines/console.std.approved.txt | 2 +- .../SelfTest/Baselines/console.sw.approved.txt | 41 ++++++++++++++++++- projects/SelfTest/Baselines/junit.sw.approved.txt | 3 +- projects/SelfTest/Baselines/xml.sw.approved.txt | 46 +++++++++++++++++++++- projects/SelfTest/UsageTests/Generators.tests.cpp | 4 ++ 7 files changed, 101 insertions(+), 10 deletions(-) diff --git a/include/internal/catch_generators_generic.hpp b/include/internal/catch_generators_generic.hpp index 2903ba69..fa3749c3 100644 --- a/include/internal/catch_generators_generic.hpp +++ b/include/internal/catch_generators_generic.hpp @@ -205,12 +205,14 @@ namespace Generators { m_chunk_size(size), m_generator(std::move(generator)) { m_chunk.reserve(m_chunk_size); - m_chunk.push_back(m_generator.get()); - for (size_t i = 1; i < m_chunk_size; ++i) { - if (!m_generator.next()) { - Catch::throw_exception(GeneratorException("Not enough values to initialize the first chunk")); - } + if (m_chunk_size != 0) { m_chunk.push_back(m_generator.get()); + for (size_t i = 1; i < m_chunk_size; ++i) { + if (!m_generator.next()) { + Catch::throw_exception(GeneratorException("Not enough values to initialize the first chunk")); + } + m_chunk.push_back(m_generator.get()); + } } } std::vector<T> const& get() const override { diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt index b7163c1f..ebf3560a 100644 --- a/projects/SelfTest/Baselines/compact.sw.approved.txt +++ b/projects/SelfTest/Baselines/compact.sw.approved.txt @@ -467,6 +467,9 @@ Generators.tests.cpp:<line number>: passed: chunk2.front() < 3 for: 1 < 3 Generators.tests.cpp:<line number>: passed: chunk2.size() == 2 for: 2 == 2 Generators.tests.cpp:<line number>: passed: chunk2.front() == chunk2.back() for: 2 == 2 Generators.tests.cpp:<line number>: passed: chunk2.front() < 3 for: 2 < 3 +Generators.tests.cpp:<line number>: passed: chunk2.size() == 0 for: 0 == 0 +Generators.tests.cpp:<line number>: passed: chunk2.size() == 0 for: 0 == 0 +Generators.tests.cpp:<line number>: passed: chunk2.size() == 0 for: 0 == 0 Generators.tests.cpp:<line number>: passed: chunk(2, value(1)), Catch::GeneratorException Generators.tests.cpp:<line number>: passed: j < i for: -3 < 1 Generators.tests.cpp:<line number>: passed: j < i for: -2 < 1 diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt index 8cfd4beb..0f859df3 100644 --- a/projects/SelfTest/Baselines/console.std.approved.txt +++ b/projects/SelfTest/Baselines/console.std.approved.txt @@ -1381,5 +1381,5 @@ due to unexpected exception with message: =============================================================================== test cases: 295 | 221 passed | 70 failed | 4 failed as expected -assertions: 1547 | 1395 passed | 131 failed | 21 failed as expected +assertions: 1550 | 1398 passed | 131 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt index 501c76f8..a14034f7 100644 --- a/projects/SelfTest/Baselines/console.sw.approved.txt +++ b/projects/SelfTest/Baselines/console.sw.approved.txt @@ -3547,6 +3547,45 @@ Generators.tests.cpp:<line number>: PASSED: with expansion: 2 < 3 +------------------------------------------------------------------------------- +Generators -- adapters + Chunking a generator into sized pieces + Chunk size of zero +------------------------------------------------------------------------------- +Generators.tests.cpp:<line number> +............................................................................... + +Generators.tests.cpp:<line number>: PASSED: + REQUIRE( chunk2.size() == 0 ) +with expansion: + 0 == 0 + +------------------------------------------------------------------------------- +Generators -- adapters + Chunking a generator into sized pieces + Chunk size of zero +------------------------------------------------------------------------------- +Generators.tests.cpp:<line number> +............................................................................... + +Generators.tests.cpp:<line number>: PASSED: + REQUIRE( chunk2.size() == 0 ) +with expansion: + 0 == 0 + +------------------------------------------------------------------------------- +Generators -- adapters + Chunking a generator into sized pieces + Chunk size of zero +------------------------------------------------------------------------------- +Generators.tests.cpp:<line number> +............................................................................... + +Generators.tests.cpp:<line number>: PASSED: + REQUIRE( chunk2.size() == 0 ) +with expansion: + 0 == 0 + ------------------------------------------------------------------------------- Generators -- adapters Chunking a generator into sized pieces @@ -12335,5 +12374,5 @@ Misc.tests.cpp:<line number>: PASSED: =============================================================================== test cases: 295 | 205 passed | 86 failed | 4 failed as expected -assertions: 1564 | 1395 passed | 148 failed | 21 failed as expected +assertions: 1567 | 1398 passed | 148 failed | 21 failed as expected diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt index 7892601f..abfb0a99 100644 --- a/projects/SelfTest/Baselines/junit.sw.approved.txt +++ b/projects/SelfTest/Baselines/junit.sw.approved.txt @@ -1,7 +1,7 @@ <?xml version="1.0" encoding="UTF-8"?> <testsuitesloose text artifact > - <testsuite name="<exe-name>" errors="17" failures="132" tests="1565" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> + <testsuite name="<exe-name>" errors="17" failures="132" tests="1568" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <properties> <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/> <property name="random-seed" value="1"/> @@ -416,6 +416,7 @@ Message.tests.cpp:<line number> <testcase classname="<exe-name>.global" name="Generators -- adapters/Repeating a generator" time="{duration}"/> <testcase classname="<exe-name>.global" name="Generators -- adapters/Chunking a generator into sized pieces/Number of elements in source is divisible by chunk size" time="{duration}"/> <testcase classname="<exe-name>.global" name="Generators -- adapters/Chunking a generator into sized pieces/Number of elements in source is not divisible by chunk size" time="{duration}"/> + <testcase classname="<exe-name>.global" name="Generators -- adapters/Chunking a generator into sized pieces/Chunk size of zero" time="{duration}"/> <testcase classname="<exe-name>.global" name="Generators -- adapters/Chunking a generator into sized pieces/Throws on too small generators" time="{duration}"/> <testcase classname="<exe-name>.global" name="Generators -- simple/one" time="{duration}"/> <testcase classname="<exe-name>.global" name="Generators -- simple/two" time="{duration}"/> diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt index 04f42837..57de31fb 100644 --- a/projects/SelfTest/Baselines/xml.sw.approved.txt +++ b/projects/SelfTest/Baselines/xml.sw.approved.txt @@ -4260,6 +4260,48 @@ Nor would this </Section> <OverallResults successes="3" failures="0" expectedFailures="0"/> </Section> + <Section name="Chunking a generator into sized pieces" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > + <Section name="Chunk size of zero" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > + <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > + <Original> + chunk2.size() == 0 + </Original> + <Expanded> + 0 == 0 + </Expanded> + </Expression> + <OverallResults successes="1" failures="0" expectedFailures="0"/> + </Section> + <OverallResults successes="1" failures="0" expectedFailures="0"/> + </Section> + <Section name="Chunking a generator into sized pieces" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > + <Section name="Chunk size of zero" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > + <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > + <Original> + chunk2.size() == 0 + </Original> + <Expanded> + 0 == 0 + </Expanded> + </Expression> + <OverallResults successes="1" failures="0" expectedFailures="0"/> + </Section> + <OverallResults successes="1" failures="0" expectedFailures="0"/> + </Section> + <Section name="Chunking a generator into sized pieces" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > + <Section name="Chunk size of zero" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > + <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > + <Original> + chunk2.size() == 0 + </Original> + <Expanded> + 0 == 0 + </Expanded> + </Expression> + <OverallResults successes="1" failures="0" expectedFailures="0"/> + </Section> + <OverallResults successes="1" failures="0" expectedFailures="0"/> + </Section> <Section name="Chunking a generator into sized pieces" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > <Section name="Throws on too small generators" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > <Expression success="true" type="REQUIRE_THROWS_AS" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" > @@ -14692,7 +14734,7 @@ loose text artifact </Section> <OverallResult success="true"/> </TestCase> - <OverallResults successes="1395" failures="149" expectedFailures="21"/> + <OverallResults successes="1398" failures="149" expectedFailures="21"/> </Group> - <OverallResults successes="1395" failures="148" expectedFailures="21"/> + <OverallResults successes="1398" failures="148" expectedFailures="21"/> </Catch> diff --git a/projects/SelfTest/UsageTests/Generators.tests.cpp b/projects/SelfTest/UsageTests/Generators.tests.cpp index f5e3f6a5..903f6a03 100644 --- a/projects/SelfTest/UsageTests/Generators.tests.cpp +++ b/projects/SelfTest/UsageTests/Generators.tests.cpp @@ -167,6 +167,10 @@ TEST_CASE("Generators -- adapters", "[generators][generic]") { REQUIRE(chunk2.front() == chunk2.back()); REQUIRE(chunk2.front() < 3); } + SECTION("Chunk size of zero") { + auto chunk2 = GENERATE(take(3, chunk(0, value(1)))); + REQUIRE(chunk2.size() == 0); + } SECTION("Throws on too small generators") { using namespace Catch::Generators; REQUIRE_THROWS_AS(chunk(2, value(1)), Catch::GeneratorException);