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

Sections use vector instead of a map

Uses brute-force search, but only ever for small vectors
Commit
6f2343bf644175228df02f411cbbd271fbf866e4
Author
Phil Nash ·
Parents
c4ba6757d917

Files · Download .tar.gz

Changes

 include/internal/catch_common.h         |  4 ----
 include/internal/catch_section_info.hpp | 26 ++++++++++++++------------
 2 files changed, 14 insertions(+), 16 deletions(-)

diff --git a/include/internal/catch_common.h b/include/internal/catch_common.h
index 58fbe0ff..ec8cd2e9 100644
--- a/include/internal/catch_common.h
+++ b/include/internal/catch_common.h
@@ -51,18 +51,14 @@ namespace Catch {
         typename ContainerT::const_iterator it = container.begin();
         typename ContainerT::const_iterator itEnd = container.end();
         for(; it != itEnd; ++it )
-        {
             delete *it;
-        }
     }
     template<typename AssociativeContainerT>
     inline void deleteAllValues( AssociativeContainerT& container ) {
         typename AssociativeContainerT::const_iterator it = container.begin();
         typename AssociativeContainerT::const_iterator itEnd = container.end();
         for(; it != itEnd; ++it )
-        {
             delete it->second;
-        }
     }
     
     template<typename ContainerT, typename Function>
diff --git a/include/internal/catch_section_info.hpp b/include/internal/catch_section_info.hpp
index 9cdcd679..e28f3147 100644
--- a/include/internal/catch_section_info.hpp
+++ b/include/internal/catch_section_info.hpp
@@ -24,6 +24,8 @@ namespace Catch {
 
     class SectionInfo : ISectionInfo {
     public:
+
+        typedef std::vector<SectionInfo*> SubSections;
     
         enum State {
             Root,
@@ -46,7 +48,7 @@ namespace Catch {
         {}
         
         ~SectionInfo() {
-            deleteAllValues( m_subSections );
+            deleteAll( m_subSections );
         }
 
         virtual std::string getName() const {
@@ -68,13 +70,11 @@ namespace Catch {
         bool hasUntestedSections() const {
             if( m_state == Unknown )
                 return true;
-            
-            std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.begin();
-            std::map<std::string, SectionInfo*>::const_iterator itEnd = m_subSections.end();
-            for(; it != itEnd; ++it ) {
-                if( it->second->hasUntestedSections() )
+            for(    SubSections::const_iterator it = m_subSections.begin();
+                    it != m_subSections.end();
+                    ++it)
+                if( (*it)->hasUntestedSections() )
                     return true;
-            }
             return false;
         }
 
@@ -85,11 +85,13 @@ namespace Catch {
         }
 
         SectionInfo* findOrAddSubSection( const std::string& name, bool& changed ) {
-            std::map<std::string, SectionInfo*>::const_iterator it = m_subSections.find( name );
-            if( it != m_subSections.end() )
-                return it->second;
+            for(    SubSections::const_iterator it = m_subSections.begin();
+                    it != m_subSections.end();
+                    ++it)
+                if( (*it)->getName() == name )
+                    return *it;
             SectionInfo* subSection = new SectionInfo( this, name );
-            m_subSections.insert( std::make_pair( name, subSection ) );
+            m_subSections.push_back( subSection );
             m_state = Branch;
             changed = true;
             return subSection;
@@ -112,7 +114,7 @@ namespace Catch {
         State m_state;
         SectionInfo* m_parent;
         std::string m_name;
-        std::map<std::string, SectionInfo*> m_subSections;
+        SubSections m_subSections;
     };
 }