mirror of
				https://github.com/catchorg/Catch2.git
				synced 2025-11-03 21:49:32 +01:00 
			
		
		
		
	Further improved nested sections
This commit is contained in:
		@@ -26,7 +26,7 @@ TEST_CASE( "./succeeding/Misc/Sections", "random SECTION tests" )
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
    SECTION( "s2", "not equal" )
 | 
					    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" )
 | 
					        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);
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -72,7 +72,8 @@ namespace Catch
 | 
				
			|||||||
            const TestCaseInfo* info = NULL 
 | 
					            const TestCaseInfo* info = NULL 
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        :   m_info( info ),
 | 
					        :   m_info( info ),
 | 
				
			||||||
            m_sectionSeen( false )
 | 
					            m_sectionSeen( false ),
 | 
				
			||||||
 | 
					            m_isLeaf( true )
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
@@ -105,8 +106,11 @@ namespace Catch
 | 
				
			|||||||
            const std::string& name
 | 
					            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;
 | 
					                return false;
 | 
				
			||||||
 | 
					            m_sectionPath = qualifiedSection;
 | 
				
			||||||
            return true;
 | 
					            return true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -116,7 +120,10 @@ namespace Catch
 | 
				
			|||||||
            const std::string& name
 | 
					            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;
 | 
					            m_sectionSeen = true;
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
@@ -131,7 +138,9 @@ namespace Catch
 | 
				
			|||||||
    private:
 | 
					    private:
 | 
				
			||||||
        const TestCaseInfo* m_info;
 | 
					        const TestCaseInfo* m_info;
 | 
				
			||||||
        bool m_sectionSeen;
 | 
					        bool m_sectionSeen;
 | 
				
			||||||
 | 
					        std::string m_sectionPath;
 | 
				
			||||||
        std::set<std::string> m_sectionsSeen;
 | 
					        std::set<std::string> m_sectionsSeen;
 | 
				
			||||||
 | 
					        bool m_isLeaf;
 | 
				
			||||||
        
 | 
					        
 | 
				
			||||||
    };
 | 
					    };
 | 
				
			||||||
    
 | 
					    
 | 
				
			||||||
@@ -369,7 +378,7 @@ namespace Catch
 | 
				
			|||||||
        (
 | 
					        (
 | 
				
			||||||
            const std::string& name, 
 | 
					            const std::string& name, 
 | 
				
			||||||
            const std::string& description, 
 | 
					            const std::string& description, 
 | 
				
			||||||
            std::size_t& successes, \
 | 
					            std::size_t& successes,
 | 
				
			||||||
            std::size_t& failures 
 | 
					            std::size_t& failures 
 | 
				
			||||||
        )
 | 
					        )
 | 
				
			||||||
        {
 | 
					        {
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user