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

Refactored missing assertions handling

Commit
e8cf726a23483083dcf534e70704cb860d6e1ffd
Author
Phil Nash ·
Parents
b80280f42889

Files · Download .tar.gz

Changes

 include/internal/catch_runner_impl.hpp | 29 +++++++++++------------------
 1 file changed, 11 insertions(+), 18 deletions(-)

diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp
index 589003c7..ed51757c 100644
--- a/include/internal/catch_runner_impl.hpp
+++ b/include/internal/catch_runner_impl.hpp
@@ -194,6 +194,15 @@ namespace Catch {
 
             return true;
         }
+        bool testForMissingAssertions( Counts& assertions ) {
+            if( assertions.total() != 0 ||
+                    !m_config->warnAboutMissingAssertions() ||
+                    m_testCaseTracker->currentSectionHasChildren() )
+                return false;
+            m_totals.assertions.failed++;
+            assertions.failed++;
+            return true;
+        }
 
         virtual void sectionEnded( SectionInfo const& info, Counts const& prevAssertions ) {
             if( std::uncaught_exception() ) {
@@ -202,15 +211,8 @@ namespace Catch {
             }
 
             Counts assertions = m_totals.assertions - prevAssertions;
-            bool missingAssertions = false;
-            if( assertions.total() == 0 &&
-                    m_config->warnAboutMissingAssertions() &&
-                    !m_testCaseTracker->currentSectionHasChildren() ) {
-                m_totals.assertions.failed++;
-                assertions.failed++;
-                missingAssertions = true;
+            bool missingAssertions = testForMissingAssertions( assertions );
 
-            }
             m_testCaseTracker->leaveSection();
 
             m_reporter->sectionEnded( SectionStats( info, assertions, missingAssertions ) );
@@ -300,16 +302,7 @@ namespace Catch {
             m_messages.clear();
 
             Counts assertions = m_totals.assertions - prevAssertions;
-// !TBD?
-            bool missingAssertions = false;
-            if( assertions.total() == 0 &&
-                    m_config->warnAboutMissingAssertions() &&
-                    !m_testCaseTracker->currentSectionHasChildren() ) {
-                m_totals.assertions.failed++;
-                assertions.failed++;
-                missingAssertions = true;
-
-            }
+            bool missingAssertions = testForMissingAssertions( assertions );
 
             SectionStats testCaseSectionStats( testCaseSection, assertions, missingAssertions );
             m_reporter->sectionEnded( testCaseSectionStats );