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

Added LazyStat wrapper

Commit
1f519dd8566991cca071cf810acafc0782f39720
Author
Phil Nash ·
Parents
29ccaa67ad7d

Files · Download .tar.gz

Changes

 include/internal/catch_interfaces_reporter.h | 37 +++++++++++++++++++---------
 include/reporters/catch_reporter_console.hpp | 18 +++++++-------
 2 files changed, 35 insertions(+), 20 deletions(-)

diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h
index 488397a2..866f62ee 100644
--- a/include/internal/catch_interfaces_reporter.h
+++ b/include/internal/catch_interfaces_reporter.h
@@ -60,6 +60,21 @@ namespace Catch
         Node* parent;
     };
 
+    template<typename T>
+    struct LazyStat : Option<T> {
+        LazyStat() : used( false ) {}
+        LazyStat& operator=( T const& _value ) {
+            Option<T>::operator=( _value );
+            used = false;
+            return *this;
+        }
+        void reset() {
+            Option<T>::reset();
+            used = false;
+        }
+        bool used;
+    };
+
     struct TestRunInfo {
         TestRunInfo( std::string const& _name ) : name( _name ) {}
         std::string name;
@@ -235,14 +250,14 @@ namespace Catch
         virtual void noMatchingTestCases( std::string const& ) {}
 
         virtual void testRunStarting( TestRunInfo const& _testRunInfo ) {
-            testRunInfo = _testRunInfo;
+            currentTestRunInfo = _testRunInfo;
         }
         virtual void testGroupStarting( GroupInfo const& _groupInfo ) {
-            unusedGroupInfo = _groupInfo;
+            currentGroupInfo = _groupInfo;
         }
 
         virtual void testCaseStarting( TestCaseInfo const& _testInfo ) {
-            unusedTestCaseInfo = _testInfo;
+            currentTestCaseInfo = _testInfo;
         }
         virtual void sectionStarting( SectionInfo const& _sectionInfo ) {
             Ptr<Node<SectionInfo> > sectionInfo = new Node<SectionInfo>( _sectionInfo );
@@ -253,22 +268,22 @@ namespace Catch
             m_sectionStack.pop_back();
         }
         virtual void testCaseEnded( TestCaseStats const& /* _testCaseStats */ ) {
-            unusedTestCaseInfo.reset();
+            currentTestCaseInfo.reset();
             assert( m_sectionStack.empty() );
         }
         virtual void testGroupEnded( TestGroupStats const& /* _testGroupStats */ ) {
-            unusedGroupInfo.reset();
+            currentGroupInfo.reset();
         }
         virtual void testRunEnded( TestRunStats const& /* _testRunStats */ ) {
-            unusedTestCaseInfo.reset();
-            unusedGroupInfo.reset();
-            testRunInfo.reset();
+            currentTestCaseInfo.reset();
+            currentGroupInfo.reset();
+            currentTestRunInfo.reset();
         }
 
         Ptr<IConfig> m_config;
-        Option<TestRunInfo> testRunInfo;
-        Option<GroupInfo> unusedGroupInfo;
-        Option<TestCaseInfo> unusedTestCaseInfo;
+        LazyStat<TestRunInfo> currentTestRunInfo;
+        LazyStat<GroupInfo> currentGroupInfo;
+        LazyStat<TestCaseInfo> currentTestCaseInfo;
         std::ostream& stream;
 
         std::vector<SectionInfoNode> m_sectionStack;
diff --git a/include/reporters/catch_reporter_console.hpp b/include/reporters/catch_reporter_console.hpp
index 2bb93e42..2d52d705 100644
--- a/include/reporters/catch_reporter_console.hpp
+++ b/include/reporters/catch_reporter_console.hpp
@@ -79,7 +79,7 @@ namespace Catch {
             m_headerPrinted = false;
         }
         virtual void testGroupEnded( TestGroupStats const& _testGroupStats ) {
-            if( !unusedGroupInfo ) {
+            if( currentGroupInfo.used ) {
                 printSummaryDivider();
                 stream << "Summary for group '" << _testGroupStats.groupInfo.name << "':\n";
                 printTotals( _testGroupStats.totals );
@@ -229,9 +229,9 @@ namespace Catch {
 
         void lazyPrint() {
 
-            if( testRunInfo )
+            if( !currentTestRunInfo.used )
                 lazyPrintRunInfo();
-            if( unusedGroupInfo )
+            if( !currentGroupInfo.used )
                 lazyPrintGroupInfo();
 
             if( !m_headerPrinted ) {
@@ -243,7 +243,7 @@ namespace Catch {
         void lazyPrintRunInfo() {
             stream  << "\n" << getTildes() << "\n";
             Colour colour( Colour::SecondaryText );
-            stream  << testRunInfo->name
+            stream  << currentTestRunInfo->name
                     << " is a Catch v"  << libraryVersion.majorVersion << "."
                     << libraryVersion.minorVersion << " b"
                     << libraryVersion.buildNumber;
@@ -252,17 +252,17 @@ namespace Catch {
             stream  << " host application.\n"
                     << "Run with -? for options\n\n";
 
-            testRunInfo.reset();
+            currentTestRunInfo.used = true;
         }
         void lazyPrintGroupInfo() {
-            if( !unusedGroupInfo->name.empty() && unusedGroupInfo->groupsCounts > 1 ) {
-                printClosedHeader( "Group: " + unusedGroupInfo->name );
-                unusedGroupInfo.reset();
+            if( !currentGroupInfo->name.empty() && currentGroupInfo->groupsCounts > 1 ) {
+                printClosedHeader( "Group: " + currentGroupInfo->name );
+                currentGroupInfo.used = true;
             }
         }
         void printTestCaseAndSectionHeader() {
             assert( !m_sectionStack.empty() );
-            printOpenHeader( unusedTestCaseInfo->name );
+            printOpenHeader( currentTestCaseInfo->name );
 
             if( m_sectionStack.size() > 1 ) {
                 Colour colourGuard( Colour::Headers );