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

Further improved nested sections

Commit
70e7d7f16b1753978feb20620cabd239d834fd31
Author
Phil Nash ·
Parents
a8c31c725daf

Files · Download .tar.gz

Changes

 Test/MiscTests.cpp             | 26 ++++++++++++++++++++++++--
 internal/catch_runner_impl.hpp | 17 +++++++++++++----
 2 files changed, 37 insertions(+), 6 deletions(-)

diff --git a/Test/MiscTests.cpp b/Test/MiscTests.cpp
index 7f0da4f8..70fa948d 100644
--- a/Test/MiscTests.cpp
+++ b/Test/MiscTests.cpp
@@ -26,7 +26,7 @@ TEST_CASE( "./succeeding/Misc/Sections", "random SECTION tests" )
 
     SECTION( "s2", "not equal" )
     {
-        REQUIRE_FALSE( a == b);
+        REQUIRE( a != b);
     }
 }
 
@@ -42,7 +42,29 @@ TEST_CASE( "./succeeding/Misc/Sections/nested", "nested SECTION tests" )
 
         SECTION( "s2", "not equal" )
         {
-            REQUIRE_FALSE( a == b);
+            REQUIRE( a != b);
+        }
+    }
+}
+
+TEST_CASE( "./succeeding/Misc/Sections/nested2", "nested SECTION tests" )
+{
+    int a = 1;
+    int b = 2;
+    
+    SECTION( "s1", "doesn't equal" )
+    {
+        REQUIRE( a != b );
+        REQUIRE( b != a );
+        
+        SECTION( "s2", "equal" )
+        {
+            REQUIRE( a == b);
+        }
+
+        SECTION( "s3", "not equal" )
+        {
+            REQUIRE( a != b);
         }
     }
 }
diff --git a/internal/catch_runner_impl.hpp b/internal/catch_runner_impl.hpp
index 06ac82cc..a34d6900 100644
--- a/internal/catch_runner_impl.hpp
+++ b/internal/catch_runner_impl.hpp
@@ -72,7 +72,8 @@ namespace Catch
             const TestCaseInfo* info = NULL 
         )
         :   m_info( info ),
-            m_sectionSeen( false )
+            m_sectionSeen( false ),
+            m_isLeaf( true )
         {
         }
         
@@ -105,8 +106,11 @@ namespace Catch
             const std::string& name
         )
         {
-            if( m_sectionsSeen.find( name ) != m_sectionsSeen.end() )
+            m_isLeaf = true;
+            std::string qualifiedSection = m_sectionPath + "\\" + name;
+            if( m_sectionsSeen.find( qualifiedSection ) != m_sectionsSeen.end() )
                 return false;
+            m_sectionPath = qualifiedSection;
             return true;
         }
 
@@ -116,7 +120,10 @@ namespace Catch
             const std::string& name
         )
         {
-            m_sectionsSeen.insert( name );
+            if( m_isLeaf )
+                m_sectionsSeen.insert( m_sectionPath );
+            m_isLeaf = false;
+            m_sectionPath = m_sectionPath.substr( 0, m_sectionPath.length()-name.length()-1 );
             m_sectionSeen = true;
         }
 
@@ -131,7 +138,9 @@ namespace Catch
     private:
         const TestCaseInfo* m_info;
         bool m_sectionSeen;
+        std::string m_sectionPath;
         std::set<std::string> m_sectionsSeen;
+        bool m_isLeaf;
         
     };
     
@@ -369,7 +378,7 @@ namespace Catch
         (
             const std::string& name, 
             const std::string& description, 
-            std::size_t& successes, \
+            std::size_t& successes,
             std::size_t& failures 
         )
         {