Progmasoft Git

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

Add another test for FilterGenerator

Commit
ef5fd8d42f1f61ee3bd5eb1595f517c34bb2b038
Author
Martin Hořeňovský ·
Parents
693647c43f79

Files · Download .tar.gz

Changes

 .../SelfTest/Baselines/compact.sw.approved.txt     |  1 +
 .../SelfTest/Baselines/console.std.approved.txt    |  2 +-
 .../SelfTest/Baselines/console.sw.approved.txt     | 16 ++++-
 projects/SelfTest/Baselines/junit.sw.approved.txt  |  5 +-
 projects/SelfTest/Baselines/xml.sw.approved.txt    | 75 ++++++++++++++--------
 projects/SelfTest/UsageTests/Generators.tests.cpp  | 12 +++-
 6 files changed, 78 insertions(+), 33 deletions(-)

diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt
index a25cf485..824c4a6b 100644
--- a/projects/SelfTest/Baselines/compact.sw.approved.txt
+++ b/projects/SelfTest/Baselines/compact.sw.approved.txt
@@ -402,6 +402,7 @@ Matchers.tests.cpp:<line number>: passed: WithinULP(1.f, -1), std::domain_error
 Generators.tests.cpp:<line number>: passed: i % 2 == 0 for: 0 == 0
 Generators.tests.cpp:<line number>: passed: i % 2 == 0 for: 0 == 0
 Generators.tests.cpp:<line number>: passed: i % 2 == 0 for: 0 == 0
+Generators.tests.cpp:<line number>: passed: filter([] (int) {return false; }, value(1)), Catch::GeneratorException
 Generators.tests.cpp:<line number>: passed: i < 4 for: 1 < 4
 Generators.tests.cpp:<line number>: passed: i < 4 for: 2 < 4
 Generators.tests.cpp:<line number>: passed: i < 4 for: 3 < 4
diff --git a/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt
index 72baaa26..d936ba03 100644
--- a/projects/SelfTest/Baselines/console.std.approved.txt
+++ b/projects/SelfTest/Baselines/console.std.approved.txt
@@ -1175,5 +1175,5 @@ due to unexpected exception with message:
 
 ===============================================================================
 test cases:  245 |  185 passed |  56 failed |  4 failed as expected
-assertions: 1378 | 1242 passed | 115 failed | 21 failed as expected
+assertions: 1379 | 1243 passed | 115 failed | 21 failed as expected
 
diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt
index f0edbd6a..6205211a 100644
--- a/projects/SelfTest/Baselines/console.sw.approved.txt
+++ b/projects/SelfTest/Baselines/console.sw.approved.txt
@@ -2861,6 +2861,7 @@ Matchers.tests.cpp:<line number>: PASSED:
 -------------------------------------------------------------------------------
 Generators -- adapters
   Filtering by predicate
+  Basic usage
 -------------------------------------------------------------------------------
 Generators.tests.cpp:<line number>
 ...............................................................................
@@ -2873,6 +2874,7 @@ with expansion:
 -------------------------------------------------------------------------------
 Generators -- adapters
   Filtering by predicate
+  Basic usage
 -------------------------------------------------------------------------------
 Generators.tests.cpp:<line number>
 ...............................................................................
@@ -2885,6 +2887,7 @@ with expansion:
 -------------------------------------------------------------------------------
 Generators -- adapters
   Filtering by predicate
+  Basic usage
 -------------------------------------------------------------------------------
 Generators.tests.cpp:<line number>
 ...............................................................................
@@ -2894,6 +2897,17 @@ Generators.tests.cpp:<line number>: PASSED:
 with expansion:
   0 == 0
 
+-------------------------------------------------------------------------------
+Generators -- adapters
+  Filtering by predicate
+  Throws if there are no matching values
+-------------------------------------------------------------------------------
+Generators.tests.cpp:<line number>
+...............................................................................
+
+Generators.tests.cpp:<line number>: PASSED:
+  REQUIRE_THROWS_AS( filter([] (int) {return false; }, value(1)), Catch::GeneratorException )
+
 -------------------------------------------------------------------------------
 Generators -- adapters
   Shortening a range
@@ -10685,5 +10699,5 @@ Misc.tests.cpp:<line number>: PASSED:
 
 ===============================================================================
 test cases:  245 |  172 passed |  69 failed |  4 failed as expected
-assertions: 1392 | 1242 passed | 129 failed | 21 failed as expected
+assertions: 1393 | 1243 passed | 129 failed | 21 failed as expected
 
diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt
index 08a64c33..e477c29c 100644
--- a/projects/SelfTest/Baselines/junit.sw.approved.txt
+++ b/projects/SelfTest/Baselines/junit.sw.approved.txt
@@ -4,7 +4,7 @@
     <property name="random-seed" value="1"/>
   </properties>
 loose text artifact
-  <testsuite name="<exe-name>" errors="17" failures="113" tests="1393" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+  <testsuite name="<exe-name>" errors="17" failures="113" tests="1394" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
     <testcase classname="<exe-name>.global" name="# A test name that starts with a #" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="#1005: Comparing pointer to int and long (NULL can be either on various systems)" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="#1027" time="{duration}"/>
@@ -342,7 +342,8 @@ Message.tests.cpp:<line number>
     <testcase classname="<exe-name>.global" name="Floating point matchers: float/ULPs" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="Floating point matchers: float/Composed" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="Floating point matchers: float/Constructor validation" time="{duration}"/>
-    <testcase classname="<exe-name>.global" name="Generators -- adapters/Filtering by predicate" time="{duration}"/>
+    <testcase classname="<exe-name>.global" name="Generators -- adapters/Filtering by predicate/Basic usage" time="{duration}"/>
+    <testcase classname="<exe-name>.global" name="Generators -- adapters/Filtering by predicate/Throws if there are no matching values" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="Generators -- adapters/Shortening a range" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="Generators -- adapters/Transforming elements/Same type" time="{duration}"/>
     <testcase classname="<exe-name>.global" name="Generators -- adapters/Transforming elements/Different type" time="{duration}"/>
diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt
index 989c17f3..31ba5800 100644
--- a/projects/SelfTest/Baselines/xml.sw.approved.txt
+++ b/projects/SelfTest/Baselines/xml.sw.approved.txt
@@ -3540,36 +3540,59 @@
     </TestCase>
     <TestCase name="Generators -- adapters" tags="[generators][generic]" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
       <Section name="Filtering by predicate" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
-        <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
-          <Original>
-            i % 2 == 0
-          </Original>
-          <Expanded>
-            0 == 0
-          </Expanded>
-        </Expression>
+        <Section name="Basic usage" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
+          <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
+            <Original>
+              i % 2 == 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="Filtering by predicate" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
-        <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
-          <Original>
-            i % 2 == 0
-          </Original>
-          <Expanded>
-            0 == 0
-          </Expanded>
-        </Expression>
+        <Section name="Basic usage" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
+          <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
+            <Original>
+              i % 2 == 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="Filtering by predicate" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
-        <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
-          <Original>
-            i % 2 == 0
-          </Original>
-          <Expanded>
-            0 == 0
-          </Expanded>
-        </Expression>
+        <Section name="Basic usage" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
+          <Expression success="true" type="REQUIRE" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
+            <Original>
+              i % 2 == 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="Filtering by predicate" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
+        <Section name="Throws if there are no matching values" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
+          <Expression success="true" type="REQUIRE_THROWS_AS" filename="projects/<exe-name>/UsageTests/Generators.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="1" failures="0" expectedFailures="0"/>
+        </Section>
         <OverallResults successes="1" failures="0" expectedFailures="0"/>
       </Section>
       <Section name="Shortening a range" filename="projects/<exe-name>/UsageTests/Generators.tests.cpp" >
@@ -12925,7 +12948,7 @@ loose text artifact
       </Section>
       <OverallResult success="true"/>
     </TestCase>
-    <OverallResults successes="1242" failures="130" expectedFailures="21"/>
+    <OverallResults successes="1243" failures="130" expectedFailures="21"/>
   </Group>
-  <OverallResults successes="1242" failures="129" expectedFailures="21"/>
+  <OverallResults successes="1243" failures="129" expectedFailures="21"/>
 </Catch>
diff --git a/projects/SelfTest/UsageTests/Generators.tests.cpp b/projects/SelfTest/UsageTests/Generators.tests.cpp
index 8171e864..0cf1ce6e 100644
--- a/projects/SelfTest/UsageTests/Generators.tests.cpp
+++ b/projects/SelfTest/UsageTests/Generators.tests.cpp
@@ -118,9 +118,15 @@ TEST_CASE("Generators -- adapters", "[generators][generic]") {
     // TODO: This won't work yet, introduce GENERATE_VAR?
     //auto numbers = Catch::Generators::values({ 1, 2, 3, 4, 5, 6 });
     SECTION("Filtering by predicate") {
-        // This filters out all odd (false) numbers, giving [2, 4, 6]
-        auto i = GENERATE(filter([] (int val) { return val % 2 == 0; }, values({ 1, 2, 3, 4, 5, 6 })));
-        REQUIRE(i % 2 == 0);
+        SECTION("Basic usage") {
+            // This filters out all odd (false) numbers, giving [2, 4, 6]
+            auto i = GENERATE(filter([] (int val) { return val % 2 == 0; }, values({ 1, 2, 3, 4, 5, 6 })));
+            REQUIRE(i % 2 == 0);
+        }
+        SECTION("Throws if there are no matching values") {
+            using namespace Catch::Generators;
+            REQUIRE_THROWS_AS(filter([] (int) {return false; }, value(1)), Catch::GeneratorException);
+        }
     }
     SECTION("Shortening a range") {
         // This takes the first 3 elements from the values, giving back [1, 2, 3]