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

Fix clang analyzer warning about FilterGenerator

Refactor FilterGenerator to remove ctor call to overridden method next()
in order to address clang static analyzer diagnostic:

catch2-src/single_include/catch2/catch.hpp:4166:42: note: Call to virtual method 'FilterGenerator::next' during construction bypasses virtual dispatch
                auto has_initial_value = next();
                                         ^~~~~~
Commit
33794a204c00158b15eeda38bd2e30a5a57533fc
Author
Xo Wang ·
Committer
Martin Hořeňovský
Parents
f45dac8fc182

Files · Download .tar.gz

Changes

 include/internal/catch_generators_generic.hpp        |  7 ++++++-
 projects/SelfTest/Baselines/compact.sw.approved.txt  |  1 +
 projects/SelfTest/Baselines/console.std.approved.txt |  2 +-
 projects/SelfTest/Baselines/console.sw.approved.txt  |  5 ++++-
 projects/SelfTest/Baselines/junit.sw.approved.txt    |  2 +-
 projects/SelfTest/Baselines/xml.sw.approved.txt      | 14 +++++++++++---
 6 files changed, 24 insertions(+), 7 deletions(-)

diff --git a/include/internal/catch_generators_generic.hpp b/include/internal/catch_generators_generic.hpp
index c3410147..b2a0af5e 100644
--- a/include/internal/catch_generators_generic.hpp
+++ b/include/internal/catch_generators_generic.hpp
@@ -63,7 +63,7 @@ namespace Generators {
             if (!m_predicate(m_generator.get())) {
                 // It might happen that there are no values that pass the
                 // filter. In that case we throw an exception.
-                auto has_initial_value = next();
+                auto has_initial_value = nextImpl();
                 if (!has_initial_value) {
                     Catch::throw_exception(GeneratorException("No valid value found in filtered generator"));
                 }
@@ -75,6 +75,11 @@ namespace Generators {
         }
 
         bool next() override {
+            return nextImpl();
+        }
+
+    private:
+        bool nextImpl() {
             bool success = m_generator.next();
             if (!success) {
                 return false;
diff --git a/projects/SelfTest/Baselines/compact.sw.approved.txt b/projects/SelfTest/Baselines/compact.sw.approved.txt
index 0d12ebb9..d66cb98e 100644
--- a/projects/SelfTest/Baselines/compact.sw.approved.txt
+++ b/projects/SelfTest/Baselines/compact.sw.approved.txt
@@ -628,6 +628,7 @@ 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/projects/SelfTest/Baselines/console.std.approved.txt b/projects/SelfTest/Baselines/console.std.approved.txt
index 9de49d9a..c29715f0 100644
--- a/projects/SelfTest/Baselines/console.std.approved.txt
+++ b/projects/SelfTest/Baselines/console.std.approved.txt
@@ -1421,5 +1421,5 @@ due to unexpected exception with message:
 
 ===============================================================================
 test cases:  323 |  248 passed |  70 failed |  5 failed as expected
-assertions: 1763 | 1607 passed | 131 failed | 25 failed as expected
+assertions: 1764 | 1608 passed | 131 failed | 25 failed as expected
 
diff --git a/projects/SelfTest/Baselines/console.sw.approved.txt b/projects/SelfTest/Baselines/console.sw.approved.txt
index 7f663129..2318ebea 100644
--- a/projects/SelfTest/Baselines/console.sw.approved.txt
+++ b/projects/SelfTest/Baselines/console.sw.approved.txt
@@ -4968,6 +4968,9 @@ with expansion:
 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; }, values( { 1, 2, 3 } ) ), Catch::GeneratorException )
+
 -------------------------------------------------------------------------------
 Generators internals
   Take generator
@@ -14179,5 +14182,5 @@ Misc.tests.cpp:<line number>: PASSED:
 
 ===============================================================================
 test cases:  323 |  232 passed |  86 failed |  5 failed as expected
-assertions: 1780 | 1607 passed | 148 failed | 25 failed as expected
+assertions: 1781 | 1608 passed | 148 failed | 25 failed as expected
 
diff --git a/projects/SelfTest/Baselines/junit.sw.approved.txt b/projects/SelfTest/Baselines/junit.sw.approved.txt
index b7e55e04..e2a504f5 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="1781" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
+  <testsuite name="<exe-name>" errors="17" failures="132" tests="1782" hostname="tbd" time="{duration}" timestamp="{iso8601-timestamp}">
     <properties>
       <property name="filters" value="~[!nonportable]~[!benchmark]~[approvals]"/>
       <property name="random-seed" value="1"/>
diff --git a/projects/SelfTest/Baselines/xml.sw.approved.txt b/projects/SelfTest/Baselines/xml.sw.approved.txt
index 0a2d3377..30856484 100644
--- a/projects/SelfTest/Baselines/xml.sw.approved.txt
+++ b/projects/SelfTest/Baselines/xml.sw.approved.txt
@@ -5720,7 +5720,15 @@ Nor would this
             filter([] (int) { return false; }, value(1)), Catch::GeneratorException
           </Expanded>
         </Expression>
-        <OverallResults successes="5" failures="0" expectedFailures="0"/>
+        <Expression success="true" type="REQUIRE_THROWS_AS" filename="projects/<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="6" failures="0" expectedFailures="0"/>
       </Section>
       <Section name="Take generator" filename="projects/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
         <Section name="Take less" filename="projects/<exe-name>/IntrospectiveTests/GeneratorsImpl.tests.cpp" >
@@ -16759,9 +16767,9 @@ loose text artifact
       </Section>
       <OverallResult success="true"/>
     </TestCase>
-    <OverallResults successes="1607" failures="149" expectedFailures="25"/>
+    <OverallResults successes="1608" failures="149" expectedFailures="25"/>
     <OverallResultsCases successes="232" failures="86" expectedFailures="5"/>
   </Group>
-  <OverallResults successes="1607" failures="148" expectedFailures="25"/>
+  <OverallResults successes="1608" failures="148" expectedFailures="25"/>
   <OverallResultsCases successes="232" failures="86" expectedFailures="5"/>
 </Catch>