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

Removed circular dependency between SectionInfo and its parent

Commit
603002c644196f175efbc9c96c9adfaab28e1b25
Author
Phil Nash ·
Parents
67ccd8d74ab3

Files · Download .tar.gz

Changes

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

diff --git a/include/internal/catch_interfaces_reporter.h b/include/internal/catch_interfaces_reporter.h
index 85b82d1f..e6743f06 100644
--- a/include/internal/catch_interfaces_reporter.h
+++ b/include/internal/catch_interfaces_reporter.h
@@ -77,14 +77,14 @@ namespace Catch
     };
 
     struct ThreadedSectionInfo : SectionInfo, SharedImpl<> {
-        ThreadedSectionInfo( SectionInfo const& _sectionInfo, Ptr<ThreadedSectionInfo> const& _parent = Ptr<ThreadedSectionInfo>() )
+        ThreadedSectionInfo( SectionInfo const& _sectionInfo, ThreadedSectionInfo* _parent = NULL )
         :   SectionInfo( _sectionInfo ),
             parent( _parent )
         {}
         virtual ~ThreadedSectionInfo();
 
         std::vector<Ptr<ThreadedSectionInfo> > children;
-        Ptr<ThreadedSectionInfo> parent;
+        ThreadedSectionInfo* parent;
     };
 
     struct AssertionStats {
@@ -222,20 +222,19 @@ namespace Catch
         }
         virtual void sectionStarting( SectionInfo const& _sectionInfo ) {
             Ptr<ThreadedSectionInfo> sectionInfo = new ThreadedSectionInfo( _sectionInfo );
-            unusedSectionInfo = sectionInfo;
             if( !currentSectionInfo ) {
                 currentSectionInfo = sectionInfo;
+                m_rootSections.push_back( currentSectionInfo );
             }
             else {
                 currentSectionInfo->children.push_back( sectionInfo );
-                sectionInfo->parent = currentSectionInfo;
+                sectionInfo->parent = currentSectionInfo.get();
                 currentSectionInfo = sectionInfo;
             }
         }
 
         virtual void sectionEnded( SectionStats const& /* _sectionStats */ ) {
             currentSectionInfo = currentSectionInfo->parent;
-            unusedSectionInfo = currentSectionInfo;
         }
         virtual void testCaseEnded( TestCaseStats const& /* _testCaseStats */ ) {
             unusedTestCaseInfo.reset();
@@ -245,7 +244,6 @@ namespace Catch
         }
         virtual void testRunEnded( TestRunStats const& /* _testRunStats */ ) {
             currentSectionInfo.reset();
-            unusedSectionInfo.reset();
             unusedTestCaseInfo.reset();
             unusedGroupInfo.reset();
             testRunInfo.reset();
@@ -255,9 +253,11 @@ namespace Catch
         Option<TestRunInfo> testRunInfo;
         Option<GroupInfo> unusedGroupInfo;
         Option<TestCaseInfo> unusedTestCaseInfo;
-        Ptr<ThreadedSectionInfo> unusedSectionInfo;
         Ptr<ThreadedSectionInfo> currentSectionInfo;
         std::ostream& stream;
+        
+        // !TBD: This should really go in the TestCaseStats class
+        std::vector<Ptr<ThreadedSectionInfo> > m_rootSections;        
     };
 
     struct TestGroupNode : TestGroupStats {
@@ -303,7 +303,6 @@ namespace Catch
         }
         virtual void sectionStarting( SectionInfo const& _sectionInfo ) {
 //            Ptr<ThreadedSectionInfo> sectionInfo = new ThreadedSectionInfo( _sectionInfo );
-//            unusedSectionInfo = sectionInfo;
 //            if( !currentSectionInfo ) {
 //                currentSectionInfo = sectionInfo;
 //            }
@@ -316,7 +315,6 @@ namespace Catch
 
         virtual void sectionEnded( SectionStats const& /* _sectionStats */ ) {
 //            currentSectionInfo = currentSectionInfo->parent;
-//            unusedSectionInfo = currentSectionInfo;
         }
         virtual void testCaseEnded( TestCaseStats const& /* _testCaseStats */ ) {
 //            unusedTestCaseInfo.reset();
@@ -328,7 +326,6 @@ namespace Catch
         }
         virtual void testRunEnded( TestRunStats const& /* _testRunStats */ ) {
 //            currentSectionInfo.reset();
-//            unusedSectionInfo.reset();
 //            unusedTestCaseInfo.reset();
 //            unusedGroupInfo.reset();
 //            testRunInfo.reset();
@@ -338,7 +335,6 @@ namespace Catch
 //        Option<TestRunInfo> testRunInfo;
 //        Option<GroupInfo> unusedGroupInfo;
 //        Option<TestCaseInfo> unusedTestCaseInfo;
-//        Ptr<ThreadedSectionInfo> unusedSectionInfo;
 //        Ptr<ThreadedSectionInfo> currentSectionInfo;
 //        Ptr<TestGroupNode> testGroupNode;
         Option<TestGroupNode> testGroupNode;
diff --git a/include/reporters/catch_reporter_console.hpp b/include/reporters/catch_reporter_console.hpp
index 8deefd33..3101dab9 100644
--- a/include/reporters/catch_reporter_console.hpp
+++ b/include/reporters/catch_reporter_console.hpp
@@ -17,6 +17,7 @@ namespace Catch {
     struct ConsoleReporter : StreamingReporterBase {
         ConsoleReporter( ReporterConfig const& _config )
         :   StreamingReporterBase( _config ),
+            m_printedCurrentSection( false ),
             m_atLeastOneTestCasePrinted( false )
         {}
 
@@ -47,13 +48,18 @@ namespace Catch {
             printer.print();
             stream << std::endl;
         }
-                        
+
+        virtual void sectionStarting( SectionInfo const& _sectionInfo ) {
+            m_printedCurrentSection = false;
+            StreamingReporterBase::sectionStarting( _sectionInfo );
+        }
         virtual void sectionEnded( SectionStats const& _sectionStats ) {
             if( _sectionStats.missingAssertions ) {
                 lazyPrint();
                 TextColour colour( TextColour::ResultError );
                 stream << "\nNo assertions in section, '" << _sectionStats.sectionInfo.name << "'\n" << std::endl;
             }
+            m_printedCurrentSection = false;
             StreamingReporterBase::sectionEnded( _sectionStats );
         }
 
@@ -219,7 +225,7 @@ namespace Catch {
                 lazyPrintGroupInfo();
             if( unusedTestCaseInfo )
                 lazyPrintTestCaseInfo();
-            if( unusedSectionInfo)
+            if( currentSectionInfo && !m_printedCurrentSection )
                 lazyPrintSectionInfo();
             
             m_atLeastOneTestCasePrinted = true;
@@ -252,9 +258,9 @@ namespace Catch {
         void lazyPrintSectionInfo() {
             
             std::vector<ThreadedSectionInfo*> sections;
-            for(    ThreadedSectionInfo* section = unusedSectionInfo.get();
+            for(    ThreadedSectionInfo* section = currentSectionInfo.get();
                     section;
-                    section = section->parent.get() )
+                    section = section->parent )
                 sections.push_back( section );
             
             // Sections
@@ -265,8 +271,8 @@ namespace Catch {
                 for( It it = sections.rbegin(), itEnd = sections.rend(); it != itEnd; ++it )
                     stream << "  " << (*it)->name << "\n";
                 stream << getDots() << "\n" << std::endl;
-                unusedSectionInfo.reset();
             }
+            m_printedCurrentSection = true;
         }
 
         void printHeader( std::string const& _name, bool closed = true ) {
@@ -343,8 +349,8 @@ namespace Catch {
         }
         
     private:
+        bool m_printedCurrentSection;
         bool m_atLeastOneTestCasePrinted;
-
     };
 
     INTERNAL_CATCH_REGISTER_REPORTER( "console", ConsoleReporter )