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

Pass totals around instead of individual success/ fail counts

Commit
edd8f02becccbf459823e44ea9a42b43e0e80faa
Author
Phil Nash ·
Parents
9bbaeba3ae58

Files · Download .tar.gz

Changes

 include/catch_runner.hpp                     |  5 ++-
 include/internal/catch_interfaces_reporter.h | 13 +++----
 include/internal/catch_runner_impl.hpp       |  6 ++--
 include/internal/catch_totals.hpp            |  4 +++
 include/reporters/catch_reporter_basic.hpp   | 54 +++++++++++++++-------------
 include/reporters/catch_reporter_junit.hpp   | 10 +++---
 include/reporters/catch_reporter_xml.hpp     | 22 ++++++------
 7 files changed, 58 insertions(+), 56 deletions(-)

diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp
index 5d16784d..0821582f 100644
--- a/include/catch_runner.hpp
+++ b/include/catch_runner.hpp
@@ -57,7 +57,7 @@ namespace Catch
         {
             config.getReporter()->StartGroup( "" );
             runner.runAll();
-            config.getReporter()->EndGroup( "", runner.getTotals().assertions.passed, runner.getTotals().assertions.failed );
+            config.getReporter()->EndGroup( "", runner.getTotals() );
         }
         else
         {
@@ -74,8 +74,7 @@ namespace Catch
                     // Use reporter?
 //                    std::cerr << "\n[Unable to match any test cases with: " << *it << "]" << std::endl;
                 }
-                Totals diffTotals = runner.getTotals() - prevTotals;
-                config.getReporter()->EndGroup( *it, diffTotals.assertions.passed, diffTotals.assertions.failed );
+                config.getReporter()->EndGroup( *it, runner.getTotals() - prevTotals );
             }
         }
 
diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h
index 57ded854..baa16755 100644
--- a/include/internal/catch_interfaces_reporter.h
+++ b/include/internal/catch_interfaces_reporter.h
@@ -14,6 +14,7 @@
 #define TWOBLUECUBES_CATCH_IREPORTERREGISTRY_INCLUDED
 
 #include "catch_common.h"
+#include "catch_totals.hpp"
 
 #include <string>
 #include <ostream>
@@ -54,8 +55,7 @@ namespace Catch
             () = 0;
         
         virtual void EndTesting
-            (   std::size_t succeeded, 
-                std::size_t failed 
+            (   const Totals& totals
             ) = 0;
         
         virtual void StartGroup
@@ -64,8 +64,7 @@ namespace Catch
         
         virtual void EndGroup
             (   const std::string& groupName, 
-                std::size_t succeeded, 
-                std::size_t failed 
+                const Totals& totals
             ) = 0;
         
         virtual void StartSection
@@ -75,8 +74,7 @@ namespace Catch
         
         virtual void EndSection
             (   const std::string& sectionName, 
-                std::size_t succeeded, 
-                std::size_t failed 
+                const Counts& assertions 
             ) = 0;
         
         virtual void StartTestCase
@@ -85,8 +83,7 @@ namespace Catch
         
         virtual void EndTestCase
             (   const TestCaseInfo& testInfo, 
-                std::size_t succeeded, 
-                std::size_t failed,
+                const Totals& totals,
                 const std::string& stdOut, 
                 const std::string& stdErr 
             ) = 0;
diff --git a/include/internal/catch_runner_impl.hpp b/include/internal/catch_runner_impl.hpp
index 1bd24c14..e9ff4b4b 100644
--- a/include/internal/catch_runner_impl.hpp
+++ b/include/internal/catch_runner_impl.hpp
@@ -317,7 +317,7 @@ namespace Catch
         ~Runner
         ()
         {
-            m_reporter->EndTesting( m_totals.assertions.passed, m_totals.assertions.failed );
+            m_reporter->EndTesting( m_totals );
             Hub::setRunner( m_prevRunner );
             Hub::setResultCapture( m_prevResultCapture );
         }
@@ -387,7 +387,7 @@ namespace Catch
             delete m_runningTest;
             m_runningTest = NULL;
 
-            m_reporter->EndTestCase( testInfo, m_totals.assertions.passed - prevTotals.assertions.passed, m_totals.assertions.failed - prevTotals.assertions.failed, redirectedCout, redirectedCerr );
+            m_reporter->EndTestCase( testInfo, m_totals - prevTotals, redirectedCout, redirectedCerr );
         }
 
         ///////////////////////////////////////////////////////////////////////////
@@ -496,7 +496,7 @@ namespace Catch
         )
         {
             m_runningTest->endSection( name );
-            m_reporter->EndSection( name, m_totals.assertions.passed - prevAssertions.passed, m_totals.assertions.failed - prevAssertions.failed );
+            m_reporter->EndSection( name, m_totals.assertions - prevAssertions );
         }
 
         ///////////////////////////////////////////////////////////////////////////
diff --git a/include/internal/catch_totals.hpp b/include/internal/catch_totals.hpp
index 1a0c68b9..69815274 100644
--- a/include/internal/catch_totals.hpp
+++ b/include/internal/catch_totals.hpp
@@ -30,6 +30,10 @@ namespace Catch
             return diff;
         }
         
+        std::size_t total() const
+        {
+            return passed + failed;
+        }
         std::size_t passed;
         std::size_t failed;
     };
diff --git a/include/reporters/catch_reporter_basic.hpp b/include/reporters/catch_reporter_basic.hpp
index facb51a8..98c8e6eb 100644
--- a/include/reporters/catch_reporter_basic.hpp
+++ b/include/reporters/catch_reporter_basic.hpp
@@ -63,38 +63,46 @@ namespace Catch
         ///////////////////////////////////////////////////////////////////////////
         void ReportCounts
         (
-            std::size_t succeeded, 
-            std::size_t failed
+            const Counts& assertions
         )
         {
-            if( failed + succeeded == 0 )
+            if( assertions.failed + assertions.passed == 0 )
                 m_config.stream() << "No tests ran";
-            else if( failed == 0 )
+            else if( assertions.failed == 0 )
             {
-                if( succeeded == 1 )
+                if( assertions.passed == 1 )
                     m_config.stream() << "1 test succeeded";
                 else
-                    m_config.stream() << "All " << succeeded << " tests succeeded";
+                    m_config.stream() << "All " << assertions.passed << " tests succeeded";
             }
-            else if( succeeded == 0 )
+            else if( assertions.passed == 0 )
             {
-                if( failed == 1 )                    
+                if( assertions.failed == 1 )                    
                     m_config.stream() << "1 test failed";
                 else
-                    m_config.stream() << "All " << failed << " tests failed";
+                    m_config.stream() << "All " << assertions.failed << " tests failed";
             }
             else
             {
-                m_config.stream() << succeeded << " test";
-                if( succeeded > 1 )
+                m_config.stream() << assertions.passed << " test";
+                if( assertions.passed > 1 )
                     m_config.stream() << "s";
 
-                m_config.stream() << " passed but " << failed << " test";
-                if( failed > 1 )
+                m_config.stream() << " passed but " << assertions.failed << " test";
+                if( assertions.failed > 1 )
                     m_config.stream() << "s";
                 m_config.stream() << " failed";
             }
         }
+
+        ///////////////////////////////////////////////////////////////////////////
+        void ReportCounts
+        (
+            const Totals& totals
+        )
+        {
+            ReportCounts( totals.assertions );
+        }
         
     private: // IReporter
 
@@ -116,13 +124,12 @@ namespace Catch
         ///////////////////////////////////////////////////////////////////////////
         virtual void EndTesting
         (
-            std::size_t succeeded, 
-            std::size_t failed
+            const Totals& totals
         )
         {
             // Output the overall test results even if "Started Testing" was not emitted
             m_config.stream() << "\n[Testing completed. ";
-            ReportCounts( succeeded, failed );
+            ReportCounts( totals);
             m_config.stream() << "]\n" << std::endl;
         }
         
@@ -139,14 +146,13 @@ namespace Catch
         virtual void EndGroup
         (
             const std::string& groupName, 
-            std::size_t succeeded, 
-            std::size_t failed 
+            const Totals& totals
         )
         {
             if( m_groupSpan.emitted && !groupName.empty() )
             {
                 m_config.stream() << "[End of group: '" << groupName << "'. ";
-                ReportCounts( succeeded, failed );
+                ReportCounts( totals );
                 m_config.stream() << "]\n" << std::endl;
                 m_groupSpan = SpanInfo();
             }
@@ -175,15 +181,14 @@ namespace Catch
         virtual void EndSection
         (
             const std::string& sectionName, 
-            std::size_t succeeded, 
-            std::size_t failed
+            const Counts& assertions
         )
         {
             SpanInfo& sectionSpan = m_sectionSpans.back();
             if( sectionSpan.emitted && !sectionSpan.name.empty() )
             {
                 m_config.stream() << "[End of section: '" << sectionName << "'. ";
-                ReportCounts( succeeded, failed );
+                ReportCounts( assertions);
                 m_config.stream() << "]\n" << std::endl;
             }
             m_sectionSpans.pop_back();
@@ -262,8 +267,7 @@ namespace Catch
         virtual void EndTestCase
         (
             const TestCaseInfo& testInfo, 
-            std::size_t succeeded, 
-            std::size_t failed, 
+            const Totals& totals,
             const std::string& stdOut, 
             const std::string& stdErr
         )
@@ -283,7 +287,7 @@ namespace Catch
             if( m_testSpan.emitted )
             {
                 m_config.stream() << "[Finished: " << testInfo.getName() << " ";
-                ReportCounts( succeeded, failed );
+                ReportCounts( totals );
                 m_config.stream() << "]" << std::endl;
             }
         }    
diff --git a/include/reporters/catch_reporter_junit.hpp b/include/reporters/catch_reporter_junit.hpp
index c317ef92..e2238d73 100644
--- a/include/reporters/catch_reporter_junit.hpp
+++ b/include/reporters/catch_reporter_junit.hpp
@@ -104,9 +104,9 @@ namespace Catch
         }
 
         ///////////////////////////////////////////////////////////////////////////
-        virtual void EndGroup( const std::string&, std::size_t succeeded, std::size_t failed )
+        virtual void EndGroup( const std::string&, const Totals& totals )
         {
-            m_currentStats->m_testsCount = failed+succeeded;
+            m_currentStats->m_testsCount = totals.assertions.total();
             m_currentStats = &m_testSuiteStats;
         }
         
@@ -114,7 +114,7 @@ namespace Catch
         {
         }
 
-        virtual void EndSection( const std::string& /*sectionName*/, std::size_t /*succeeded*/, std::size_t /*failed*/ )
+        virtual void EndSection( const std::string& /*sectionName*/, const Counts& /* assertions */ )
         {
         }
         
@@ -178,7 +178,7 @@ namespace Catch
         }
         
         ///////////////////////////////////////////////////////////////////////////
-        virtual void EndTestCase( const Catch::TestCaseInfo&, std::size_t /* succeeded */, std::size_t /* failed */, const std::string& stdOut, const std::string& stdErr )
+        virtual void EndTestCase( const Catch::TestCaseInfo&, const Totals& /* totals */, const std::string& stdOut, const std::string& stdErr )
         {
             if( !stdOut.empty() )
                 m_stdOut << stdOut << "\n";
@@ -187,7 +187,7 @@ namespace Catch
         }    
 
         ///////////////////////////////////////////////////////////////////////////
-        virtual void EndTesting( std::size_t /* succeeded */, std::size_t /* failed */ )
+        virtual void EndTesting( const Totals& /* totals */ )
         {
             std::ostream& str = m_config.stream();
             {
diff --git a/include/reporters/catch_reporter_xml.hpp b/include/reporters/catch_reporter_xml.hpp
index a57b7fe3..910932c7 100644
--- a/include/reporters/catch_reporter_xml.hpp
+++ b/include/reporters/catch_reporter_xml.hpp
@@ -61,13 +61,12 @@ namespace Catch
         ///////////////////////////////////////////////////////////////////////////
         virtual void EndTesting
         (
-            std::size_t succeeded, 
-            std::size_t failed
+            const Totals& totals
         )
         {
             m_xml.scopedElement( "OverallResults" )
-                .writeAttribute( "successes", succeeded )
-                .writeAttribute( "failures", failed );
+                .writeAttribute( "successes", totals.assertions.passed )
+                .writeAttribute( "failures", totals.assertions.failed );
             m_xml.endElement();
         }
         
@@ -85,13 +84,12 @@ namespace Catch
         virtual void EndGroup
         (
             const std::string& /*groupName*/, 
-            std::size_t succeeded, 
-            std::size_t failed 
+            const Totals& totals
         )
         {
             m_xml.scopedElement( "OverallResults" )
-                .writeAttribute( "successes", succeeded )
-                .writeAttribute( "failures", failed );            
+                .writeAttribute( "successes", totals.assertions.passed )
+                .writeAttribute( "failures", totals.assertions.failed );
             m_xml.endElement();
         }
         
@@ -104,11 +102,11 @@ namespace Catch
         }
 
         ///////////////////////////////////////////////////////////////////////////
-        virtual void EndSection( const std::string& /*sectionName*/, std::size_t succeeded, std::size_t failed )
+        virtual void EndSection( const std::string& /*sectionName*/, const Counts& assertions )
         {
             m_xml.scopedElement( "OverallResults" )
-                .writeAttribute( "successes", succeeded )
-                .writeAttribute( "failures", failed );            
+                .writeAttribute( "successes", assertions.passed )
+                .writeAttribute( "failures", assertions.failed );
             m_xml.endElement();
         }
         
@@ -175,7 +173,7 @@ namespace Catch
         }
         
         ///////////////////////////////////////////////////////////////////////////
-        virtual void EndTestCase( const Catch::TestCaseInfo&, std::size_t /* succeeded */, std::size_t /* failed */, const std::string& /*stdOut*/, const std::string& /*stdErr*/ )
+        virtual void EndTestCase( const Catch::TestCaseInfo&, const Totals& /* totals */, const std::string& /*stdOut*/, const std::string& /*stdErr*/ )
         {
             m_xml.scopedElement( "OverallResult" ).writeAttribute( "success", m_currentTestSuccess );
             m_xml.endElement();