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

Fitted new section tracking

Commit
52a417df7b3f5a52169004ad9138bc7fb5a1ddd2
Author
Phil Nash ·
Parents
0b523db6b927

Files · Download .tar.gz

Changes

 include/internal/catch_run_context.hpp       | 45 +++++++++++++++++++++-------
 include/internal/catch_test_case_tracker.hpp |  4 +++
 2 files changed, 38 insertions(+), 11 deletions(-)

diff --git a/include/internal/catch_run_context.hpp b/include/internal/catch_run_context.hpp
index 5e315f96..c607b432 100644
--- a/include/internal/catch_run_context.hpp
+++ b/include/internal/catch_run_context.hpp
@@ -70,6 +70,7 @@ namespace Catch {
             m_context.setConfig( m_config );
             m_context.setResultCapture( this );
             m_reporter->testRunStarting( m_runInfo );
+            m_trackerContext.startRun();
         }
 
         virtual ~RunContext() {
@@ -94,14 +95,17 @@ namespace Catch {
             m_reporter->testCaseStarting( testInfo );
 
             m_activeTestCase = &testCase;
-            m_testCaseTracker = TestCaseTracker( testInfo.name );
+            
 
             do {
                 do {
+                    m_trackerContext.startCycle();
+                    m_testCaseTracker = &SectionTracker::acquire( m_trackerContext, testInfo.name );
                     runCurrentTest( redirectedCout, redirectedCerr );
                 }
-                while( !m_testCaseTracker->isCompleted() && !aborting() );
+                while( !m_testCaseTracker->isSuccessfullyCompleted() && !aborting() );
             }
+            // !TBD: deprecated
             while( getCurrentContext().advanceGeneratorsForCurrentTest() && !aborting() );
 
             Totals deltaTotals = m_totals.delta( prevTotals );
@@ -113,7 +117,7 @@ namespace Catch {
                                                         aborting() ) );
 
             m_activeTestCase = CATCH_NULL;
-            m_testCaseTracker.reset();
+            m_testCaseTracker = CATCH_NULL;
 
             return deltaTotals;
         }
@@ -149,9 +153,11 @@ namespace Catch {
             std::ostringstream oss;
             oss << sectionInfo.name << "@" << sectionInfo.lineInfo;
 
-            if( !m_testCaseTracker->enterSection( oss.str() ) )
+            ITracker& sectionTracker = SectionTracker::acquire( m_trackerContext, oss.str() );
+            if( !sectionTracker.isOpen() )
                 return false;
-
+            m_activeSections.push_back( &sectionTracker );
+            
             m_lastAssertionInfo.lineInfo = sectionInfo.lineInfo;
 
             m_reporter->sectionStarting( sectionInfo );
@@ -161,9 +167,11 @@ namespace Catch {
             return true;
         }
         bool testForMissingAssertions( Counts& assertions ) {
-            if( assertions.total() != 0 ||
-                    !m_config->warnAboutMissingAssertions() ||
-                    m_testCaseTracker->currentSectionHasChildren() )
+            if( assertions.total() != 0 )
+                return false;
+            if( m_config->warnAboutMissingAssertions() )
+                return false;
+            if( m_trackerContext.currentTracker().hasChildren() )
                 return false;
             m_totals.assertions.failed++;
             assertions.failed++;
@@ -174,13 +182,22 @@ namespace Catch {
             Counts assertions = m_totals.assertions - endInfo.prevAssertions;
             bool missingAssertions = testForMissingAssertions( assertions );
             
-            m_testCaseTracker->leaveSection();
+            if( !m_activeSections.empty() ) {
+                m_activeSections.back()->close();
+                m_activeSections.pop_back();
+            }
             
             m_reporter->sectionEnded( SectionStats( endInfo.sectionInfo, assertions, endInfo.durationInSeconds, missingAssertions ) );
             m_messages.clear();
         }
 
         virtual void sectionEndedEarly( SectionEndInfo const& endInfo ) {
+            if( m_unfinishedSections.empty() )
+                m_activeSections.back()->fail();
+            else
+                m_activeSections.back()->close();
+            m_activeSections.pop_back();
+            
             m_unfinishedSections.push_back( endInfo );
         }
         
@@ -249,7 +266,7 @@ namespace Catch {
             double duration = 0;
             try {
                 m_lastAssertionInfo = AssertionInfo( "TEST_CASE", testCaseInfo.lineInfo, "", ResultDisposition::Normal );
-                TestCaseTracker::Guard guard( *m_testCaseTracker );
+//                TestCaseTracker::Guard guard( *m_testCaseTracker );
 
                 seedRng( *m_config );
                 
@@ -267,10 +284,13 @@ namespace Catch {
             }
             catch( TestFailureException& ) {
                 // This just means the test was aborted due to failure
+//                m_testCaseTracker->fail();
             }
             catch(...) {
                 makeUnexpectedResultBuilder().useActiveException();
+//                m_testCaseTracker->fail();
             }
+            m_testCaseTracker->close();
             handleUnfinishedSections();
             m_messages.clear();
 
@@ -316,7 +336,8 @@ namespace Catch {
         TestRunInfo m_runInfo;
         IMutableContext& m_context;
         TestCase const* m_activeTestCase;
-        Option<TestCaseTracker> m_testCaseTracker;
+        ITracker* m_testCaseTracker;
+        ITracker* m_currentSectionTracker;
         AssertionResult m_lastResult;
 
         Ptr<IConfig const> m_config;
@@ -325,6 +346,8 @@ namespace Catch {
         std::vector<MessageInfo> m_messages;
         AssertionInfo m_lastAssertionInfo;
         std::vector<SectionEndInfo> m_unfinishedSections;
+        std::vector<ITracker*> m_activeSections;
+        TrackerContext m_trackerContext;
     };
 
     IResultCapture& getResultCapture() {
diff --git a/include/internal/catch_test_case_tracker.hpp b/include/internal/catch_test_case_tracker.hpp
index 4f174fb6..0bb82dbf 100644
--- a/include/internal/catch_test_case_tracker.hpp
+++ b/include/internal/catch_test_case_tracker.hpp
@@ -29,6 +29,7 @@ namespace TestCaseTracking {
         virtual bool isComplete() const = 0; // Successfully completed or failed
         virtual bool isSuccessfullyCompleted() const = 0;
         virtual bool isOpen() const = 0; // Started but not complete
+        virtual bool hasChildren() const = 0;
         
         virtual ITracker& parent() = 0;
         
@@ -139,6 +140,9 @@ namespace TestCaseTracking {
         virtual bool isOpen() const CATCH_OVERRIDE {
             return m_runState != NotStarted && !isComplete();
         }
+        virtual bool hasChildren() const CATCH_OVERRIDE {
+            return !m_children.empty();
+        }
         
         
         virtual void addChild( Ptr<ITracker> const& child ) CATCH_OVERRIDE {