diff options
| author | Martin Hořeňovský | 2021-10-28 11:26:34 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2021-10-28 11:26:53 +0200 |
| commit | 3c5c86a4e417b2b39585c9990928e44490b6c54c (patch) | |
| tree | 01f31eed890edc4adb98b080674788c9c95463cb | |
| parent | 514206df36510755a49bd5beb037c2ec1cc8e7f3 (diff) | |
| download | catch3-3c5c86a4e417b2b39585c9990928e44490b6c54c.tar.gz | |
Add test for filtering out multiple initial values in filter gen
| -rw-r--r-- | tests/SelfTest/Baselines/compact.sw.approved.txt | 7 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/console.std.approved.txt | 2 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/console.sw.approved.txt | 44 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/junit.sw.approved.txt | 6 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/sonarqube.sw.approved.txt | 4 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/tap.sw.approved.txt | 14 | ||||
| -rw-r--r-- | tests/SelfTest/Baselines/xml.sw.approved.txt | 139 | ||||
| -rw-r--r-- | tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp | 27 |
8 files changed, 185 insertions, 58 deletions
diff --git a/tests/SelfTest/Baselines/compact.sw.approved.txt b/tests/SelfTest/Baselines/compact.sw.approved.txt index b3bd849e..dabd078b 100644 --- a/tests/SelfTest/Baselines/compact.sw.approved.txt +++ b/tests/SelfTest/Baselines/compact.sw.approved.txt @@ -695,7 +695,12 @@ GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 1 for: 1 == 1 GeneratorsImpl.tests.cpp:<line number>: passed: gen.next() for: true GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 3 for: 3 == 3 GeneratorsImpl.tests.cpp:<line number>: passed: !(gen.next()) for: !false -GeneratorsImpl.tests.cpp:<line number>: passed: filter([] (int) { return false; }, value(1)), Catch::GeneratorException +GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 1 for: 1 == 1 +GeneratorsImpl.tests.cpp:<line number>: passed: gen.next() for: true +GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 3 for: 3 == 3 +GeneratorsImpl.tests.cpp:<line number>: passed: !(gen.next()) for: !false +GeneratorsImpl.tests.cpp:<line number>: passed: filter([](int) { return false; }, value(1)), Catch::GeneratorException +GeneratorsImpl.tests.cpp:<line number>: passed: filter([](int) { return false; }, values({ 1, 2, 3 })), Catch::GeneratorException GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 1 for: 1 == 1 GeneratorsImpl.tests.cpp:<line number>: passed: gen.next() for: true GeneratorsImpl.tests.cpp:<line number>: passed: gen.get() == 2 for: 2 == 2 diff --git a/tests/SelfTest/Baselines/console.std.approved.txt b/tests/SelfTest/Baselines/console.std.approved.txt index dcc2a39a..db80f75d 100644 --- a/tests/SelfTest/Baselines/console.std.approved.txt +++ b/tests/SelfTest/Baselines/console.std.approved.txt @@ -1427,5 +1427,5 @@ due to unexpected exception with message: =============================================================================== test cases: 376 | 299 passed | 70 failed | 7 failed as expected -assertions: 2142 | 1986 passed | 129 failed | 27 failed as expected +assertions: 2147 | 1991 passed | 129 failed | 27 failed as expected diff --git a/tests/SelfTest/Baselines/console.sw.approved.txt b/tests/SelfTest/Baselines/console.sw.approved.txt index f64110e5..ed5e317a 100644 --- a/tests/SelfTest/Baselines/console.sw.approved.txt +++ b/tests/SelfTest/Baselines/console.sw.approved.txt @@ -5440,6 +5440,7 @@ with expansion: ------------------------------------------------------------------------------- Generators internals Filter generator + Simple filtering ------------------------------------------------------------------------------- GeneratorsImpl.tests.cpp:<line number> ............................................................................... @@ -5464,8 +5465,47 @@ GeneratorsImpl.tests.cpp:<line number>: PASSED: with expansion: !false +------------------------------------------------------------------------------- +Generators internals + Filter generator + Filter out multiple elements at the start and end +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp:<line number> +............................................................................... + +GeneratorsImpl.tests.cpp:<line number>: PASSED: + REQUIRE( gen.get() == 1 ) +with expansion: + 1 == 1 + +GeneratorsImpl.tests.cpp:<line number>: PASSED: + REQUIRE( gen.next() ) +with expansion: + true + +GeneratorsImpl.tests.cpp:<line number>: PASSED: + REQUIRE( gen.get() == 3 ) +with expansion: + 3 == 3 + +GeneratorsImpl.tests.cpp:<line number>: PASSED: + REQUIRE_FALSE( gen.next() ) +with expansion: + !false + +------------------------------------------------------------------------------- +Generators internals + Filter generator + Throws on construction if it can't get initial element +------------------------------------------------------------------------------- +GeneratorsImpl.tests.cpp:<line number> +............................................................................... + +GeneratorsImpl.tests.cpp:<line number>: PASSED: + REQUIRE_THROWS_AS( filter([](int) { return false; }, value(1)), Catch::GeneratorException ) + GeneratorsImpl.tests.cpp:<line number>: PASSED: - REQUIRE_THROWS_AS( filter([] (int) { return false; }, value(1)), Catch::GeneratorException ) + REQUIRE_THROWS_AS( filter([](int) { return false; }, values({ 1, 2, 3 })), Catch::GeneratorException ) ------------------------------------------------------------------------------- Generators internals @@ -17228,5 +17268,5 @@ Misc.tests.cpp:<line number>: PASSED: =============================================================================== test cases: 376 | 283 passed | 86 failed | 7 failed as expected -assertions: 2159 | 1986 passed | 146 failed | 27 failed as expected +assertions: 2164 | 1991 passed | 146 failed | 27 failed as expected diff --git a/tests/SelfTest/Baselines/junit.sw.approved.txt b/tests/SelfTest/Baselines/junit.sw.approved.txt index dd6a6e92..95670382 100644 --- a/tests/SelfTest/Baselines/junit.sw.approved.txt +++ b/tests/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="129" tests="2159" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> + <testsuite name="<exe-name>" errors="17" failures="129" tests="2164" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}"> <properties> <property name="random-seed" value="1"/> <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals] *"/> @@ -698,7 +698,9 @@ Message.tests.cpp:<line number> <testcase classname="<exe-name>.global" name="Generators internals/Preset values" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Generators internals/Generator combinator" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Generators internals/Explicitly typed generator sequence" time="{duration}" status="run"/> - <testcase classname="<exe-name>.global" name="Generators internals/Filter generator" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="Generators internals/Filter generator/Simple filtering" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="Generators internals/Filter generator/Filter out multiple elements at the start and end" time="{duration}" status="run"/> + <testcase classname="<exe-name>.global" name="Generators internals/Filter generator/Throws on construction if it can't get initial element" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Generators internals/Take generator/Take less" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Generators internals/Take generator/Take more" time="{duration}" status="run"/> <testcase classname="<exe-name>.global" name="Generators internals/Map with explicit return type" time="{duration}" status="run"/> diff --git a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt index aaa3493f..bbec9854 100644 --- a/tests/SelfTest/Baselines/sonarqube.sw.approved.txt +++ b/tests/SelfTest/Baselines/sonarqube.sw.approved.txt @@ -94,7 +94,9 @@ <testCase name="Generators internals/Preset values" duration="{duration}"/> <testCase name="Generators internals/Generator combinator" duration="{duration}"/> <testCase name="Generators internals/Explicitly typed generator sequence" duration="{duration}"/> - <testCase name="Generators internals/Filter generator" duration="{duration}"/> + <testCase name="Generators internals/Filter generator/Simple filtering" duration="{duration}"/> + <testCase name="Generators internals/Filter generator/Filter out multiple elements at the start and end" duration="{duration}"/> + <testCase name="Generators internals/Filter generator/Throws on construction if it can't get initial element" duration="{duration}"/> <testCase name="Generators internals/Take generator/Take less" duration="{duration}"/> <testCase name="Generators internals/Take generator/Take more" duration="{duration}"/> <testCase name="Generators internals/Map with explicit return type" duration="{duration}"/> diff --git a/tests/SelfTest/Baselines/tap.sw.approved.txt b/tests/SelfTest/Baselines/tap.sw.approved.txt index 1e4e6b34..7d60d6d6 100644 --- a/tests/SelfTest/Baselines/tap.sw.approved.txt +++ b/tests/SelfTest/Baselines/tap.sw.approved.txt @@ -1373,7 +1373,17 @@ ok {test-number} - gen.get() == 3 for: 3 == 3 # Generators internals ok {test-number} - !(gen.next()) for: !false # Generators internals -ok {test-number} - filter([] (int) { return false; }, value(1)), Catch::GeneratorException +ok {test-number} - gen.get() == 1 for: 1 == 1 +# Generators internals +ok {test-number} - gen.next() for: true +# Generators internals +ok {test-number} - gen.get() == 3 for: 3 == 3 +# Generators internals +ok {test-number} - !(gen.next()) for: !false +# Generators internals +ok {test-number} - filter([](int) { return false; }, value(1)), Catch::GeneratorException +# Generators internals +ok {test-number} - filter([](int) { return false; }, values({ 1, 2, 3 })), Catch::GeneratorException # Generators internals ok {test-number} - gen.get() == 1 for: 1 == 1 # Generators internals @@ -4320,5 +4330,5 @@ ok {test-number} - q3 == 23. for: 23.0 == 23.0 ok {test-number} - # xmlentitycheck ok {test-number} - -1..2159 +1..2164 diff --git a/tests/SelfTest/Baselines/xml.sw.approved.txt b/tests/SelfTest/Baselines/xml.sw.approved.txt index b922d3b5..696ea472 100644 --- a/tests/SelfTest/Baselines/xml.sw.approved.txt +++ b/tests/SelfTest/Baselines/xml.sw.approved.txt @@ -6183,47 +6183,102 @@ Nor would this <OverallResults successes="7" failures="0" expectedFailures="0"/> </Section> <Section name="Filter generator" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > - <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > - <Original> - gen.get() == 1 - </Original> - <Expanded> - 1 == 1 - </Expanded> - </Expression> - <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > - <Original> - gen.next() - </Original> - <Expanded> - true - </Expanded> - </Expression> - <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > - <Original> - gen.get() == 3 - </Original> - <Expanded> - 3 == 3 - </Expanded> - </Expression> - <Expression success="true" type="REQUIRE_FALSE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > - <Original> - !(gen.next()) - </Original> - <Expanded> - !false - </Expanded> - </Expression> - <Expression success="true" type="REQUIRE_THROWS_AS" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > - <Original> - filter([] (int) { return false; }, value(1)), Catch::GeneratorException - </Original> - <Expanded> - filter([] (int) { return false; }, value(1)), Catch::GeneratorException - </Expanded> - </Expression> - <OverallResults successes="5" failures="0" expectedFailures="0"/> + <Section name="Simple filtering" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > + <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > + <Original> + gen.get() == 1 + </Original> + <Expanded> + 1 == 1 + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > + <Original> + gen.next() + </Original> + <Expanded> + true + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > + <Original> + gen.get() == 3 + </Original> + <Expanded> + 3 == 3 + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_FALSE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > + <Original> + !(gen.next()) + </Original> + <Expanded> + !false + </Expanded> + </Expression> + <OverallResults successes="4" failures="0" expectedFailures="0"/> + </Section> + <OverallResults successes="4" failures="0" expectedFailures="0"/> + </Section> + <Section name="Filter generator" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > + <Section name="Filter out multiple elements at the start and end" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > + <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > + <Original> + gen.get() == 1 + </Original> + <Expanded> + 1 == 1 + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > + <Original> + gen.next() + </Original> + <Expanded> + true + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > + <Original> + gen.get() == 3 + </Original> + <Expanded> + 3 == 3 + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_FALSE" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > + <Original> + !(gen.next()) + </Original> + <Expanded> + !false + </Expanded> + </Expression> + <OverallResults successes="4" failures="0" expectedFailures="0"/> + </Section> + <OverallResults successes="4" failures="0" expectedFailures="0"/> + </Section> + <Section name="Filter generator" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > + <Section name="Throws on construction if it can't get initial element" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > + <Expression success="true" type="REQUIRE_THROWS_AS" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > + <Original> + filter([](int) { return false; }, value(1)), Catch::GeneratorException + </Original> + <Expanded> + filter([](int) { return false; }, value(1)), Catch::GeneratorException + </Expanded> + </Expression> + <Expression success="true" type="REQUIRE_THROWS_AS" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > + <Original> + filter([](int) { return false; }, values({ 1, 2, 3 })), Catch::GeneratorException + </Original> + <Expanded> + filter([](int) { return false; }, values({ 1, 2, 3 })), Catch::GeneratorException + </Expanded> + </Expression> + <OverallResults successes="2" failures="0" expectedFailures="0"/> + </Section> + <OverallResults successes="2" failures="0" expectedFailures="0"/> </Section> <Section name="Take generator" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > <Section name="Take less" filename="tests/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" > @@ -20183,6 +20238,6 @@ loose text artifact </Section> <OverallResult success="true"/> </TestCase> - <OverallResults successes="1986" failures="146" expectedFailures="27"/> + <OverallResults successes="1991" failures="146" expectedFailures="27"/> <OverallResultsCases successes="283" failures="86" expectedFailures="7"/> </Catch2TestRun> diff --git a/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp b/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp index 848bb1d9..ac60525e 100644 --- a/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp +++ b/tests/SelfTest/IntrospectiveTests/GeneratorsImpl.tests.cpp @@ -50,14 +50,27 @@ TEST_CASE("Generators internals", "[generators][internals]") { } SECTION("Filter generator") { // Normal usage - auto gen = filter([] (int i) { return i != 2; }, values({ 2, 1, 2, 3, 2, 2 })); - REQUIRE(gen.get() == 1); - REQUIRE(gen.next()); - REQUIRE(gen.get() == 3); - REQUIRE_FALSE(gen.next()); + SECTION("Simple filtering") { + auto gen = filter([](int i) { return i != 2; }, values({ 2, 1, 2, 3, 2, 2 })); + REQUIRE(gen.get() == 1); + REQUIRE(gen.next()); + REQUIRE(gen.get() == 3); + REQUIRE_FALSE(gen.next()); + } + SECTION("Filter out multiple elements at the start and end") { + auto gen = filter([](int i) { return i != 2; }, values({ 2, 2, 1, 3, 2, 2 })); + REQUIRE(gen.get() == 1); + REQUIRE(gen.next()); + REQUIRE(gen.get() == 3); + REQUIRE_FALSE(gen.next()); + } - // Completely filtered-out generator should throw on construction - REQUIRE_THROWS_AS(filter([] (int) { return false; }, value(1)), Catch::GeneratorException); + SECTION("Throws on construction if it can't get initial element") { + REQUIRE_THROWS_AS(filter([](int) { return false; }, value(1)), Catch::GeneratorException); + REQUIRE_THROWS_AS( + filter([](int) { return false; }, values({ 1, 2, 3 })), + Catch::GeneratorException); + } } SECTION("Take generator") { SECTION("Take less") { |