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

Remove <set> include from the common test path

Commit
287cc92b2ce605fd4ca7809667581d820f448330
Author
Martin Hořeňovský ·
Parents
446bad752f7b

Files · Download .tar.gz

Changes

 include/catch_session.hpp                  |  4 +--
 include/internal/catch_list.cpp            |  2 +-
 include/internal/catch_list.h              |  2 ++
 include/internal/catch_test_case_info.cpp  | 40 +++++++++++++++++++++---------
 include/internal/catch_test_case_info.h    | 13 +++++-----
 include/internal/catch_test_spec.cpp       |  5 +++-
 include/reporters/catch_reporter_junit.cpp | 16 ++++++------
 include/reporters/catch_reporter_xml.cpp   |  2 +-
 8 files changed, 54 insertions(+), 30 deletions(-)

diff --git a/include/catch_session.hpp b/include/catch_session.hpp
index f95de1c5..7bbd34b2 100644
--- a/include/catch_session.hpp
+++ b/include/catch_session.hpp
@@ -78,7 +78,7 @@ namespace Catch {
     void applyFilenamesAsTags( IConfig const& config ) {
         auto& tests = const_cast<std::vector<TestCase>&>( getAllTestCasesSorted( config ) );
         for( auto& testCase : tests ) {
-            std::set<std::string> tags = testCase.tags;
+            auto tags = testCase.tags;
 
             std::string filename = testCase.lineInfo.file;
             std::string::size_type lastSlash = filename.find_last_of( "\\/" );
@@ -89,7 +89,7 @@ namespace Catch {
             if( lastDot != std::string::npos )
                 filename = filename.substr( 0, lastDot );
 
-            tags.insert( "#" + filename );
+            tags.push_back( "#" + filename );
             setTags( testCase, tags );
         }
     }
diff --git a/include/internal/catch_list.cpp b/include/internal/catch_list.cpp
index 36cd0545..fa1b8793 100644
--- a/include/internal/catch_list.cpp
+++ b/include/internal/catch_list.cpp
@@ -50,7 +50,7 @@ namespace Catch {
                 Catch::cout() << Column( description ).indent(4) << std::endl;
             }
             if( !testCaseInfo.tags.empty() )
-                Catch::cout() << Column( testCaseInfo.tagsAsString ).indent( 6 ) << "\n";
+                Catch::cout() << Column( testCaseInfo.tagsAsString() ).indent( 6 ) << "\n";
         }
 
         if( !config.testSpec().hasFilters() )
diff --git a/include/internal/catch_list.h b/include/internal/catch_list.h
index daf158d0..4bc96ec5 100644
--- a/include/internal/catch_list.h
+++ b/include/internal/catch_list.h
@@ -11,6 +11,8 @@
 #include "catch_option.hpp"
 #include "catch_config.hpp"
 
+#include <set>
+
 namespace Catch {
 
     std::size_t listTests( Config const& config );
diff --git a/include/internal/catch_test_case_info.cpp b/include/internal/catch_test_case_info.cpp
index 6f6b141d..4a392da6 100644
--- a/include/internal/catch_test_case_info.cpp
+++ b/include/internal/catch_test_case_info.cpp
@@ -13,6 +13,7 @@
 
 #include <cctype>
 #include <exception>
+#include <algorithm>
 
 namespace Catch {
 
@@ -51,7 +52,7 @@ namespace Catch {
         bool isHidden( startsWith( _name, "./" ) ); // Legacy support
 
         // Parse out tags
-        std::set<std::string> tags;
+        std::vector<std::string> tags;
         std::string desc, tag;
         bool inTag = false;
         for( std::size_t i = 0; i < _descOrTags.size(); ++i ) {
@@ -70,7 +71,7 @@ namespace Catch {
                     else if( prop == TestCaseInfo::None )
                         enforceNotReservedTag( tag, _lineInfo );
 
-                    tags.insert( tag );
+                    tags.push_back( tag );
                     tag.clear();
                     inTag = false;
                 }
@@ -79,33 +80,31 @@ namespace Catch {
             }
         }
         if( isHidden ) {
-            tags.insert( "hide" );
-            tags.insert( "." );
+            tags.push_back( "hide" );
+            tags.push_back( "." );
         }
 
         TestCaseInfo info( _name, _className, desc, tags, _lineInfo );
         return TestCase( _testCase, info );
     }
 
-    void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags )
-    {
-        testCaseInfo.tags = tags;
+    void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> tags ) {
+        std::sort(begin(tags), end(tags));
+        tags.erase(std::unique(begin(tags), end(tags)), end(tags));
         testCaseInfo.lcaseTags.clear();
 
-        std::ostringstream oss;
         for( auto const& tag : tags ) {
-            oss << '[' << tag << ']';
             std::string lcaseTag = toLower( tag );
             testCaseInfo.properties = static_cast<TestCaseInfo::SpecialProperties>( testCaseInfo.properties | parseSpecialTag( lcaseTag ) );
-            testCaseInfo.lcaseTags.insert( lcaseTag );
+            testCaseInfo.lcaseTags.push_back( lcaseTag );
         }
-        testCaseInfo.tagsAsString = oss.str();
+        testCaseInfo.tags = std::move(tags);
     }
 
     TestCaseInfo::TestCaseInfo( std::string const& _name,
                                 std::string const& _className,
                                 std::string const& _description,
-                                std::set<std::string> const& _tags,
+                                std::vector<std::string> const& _tags,
                                 SourceLineInfo const& _lineInfo )
     :   name( _name ),
         className( _className ),
@@ -129,6 +128,23 @@ namespace Catch {
         return ( properties & (ShouldFail ) ) != 0;
     }
 
+    std::string TestCaseInfo::tagsAsString() const {
+        std::string ret;
+        // '[' and ']' per tag
+        size_t full_size = 2 * tags.size();
+        for (const auto& tag : tags) {
+            full_size += tag.size();
+        }
+        ret.reserve(full_size);
+        for (const auto& tag : tags) {
+            ret.push_back('[');
+            ret.append(tag);
+            ret.push_back(']');
+        }
+
+        return ret;
+    }
+
 
     TestCase::TestCase( ITestInvoker* testCase, TestCaseInfo const& info ) : TestCaseInfo( info ), test( testCase ) {}
 
diff --git a/include/internal/catch_test_case_info.h b/include/internal/catch_test_case_info.h
index ebb1f406..44b9fa38 100644
--- a/include/internal/catch_test_case_info.h
+++ b/include/internal/catch_test_case_info.h
@@ -9,7 +9,7 @@
 #define TWOBLUECUBES_CATCH_TEST_CASE_INFO_H_INCLUDED
 
 #include <string>
-#include <set>
+#include <vector>
 #include <memory>
 
 #ifdef __clang__
@@ -34,22 +34,23 @@ namespace Catch {
         TestCaseInfo(   std::string const& _name,
                         std::string const& _className,
                         std::string const& _description,
-                        std::set<std::string> const& _tags,
+                        std::vector<std::string> const& _tags,
                         SourceLineInfo const& _lineInfo );
 
-        friend void setTags( TestCaseInfo& testCaseInfo, std::set<std::string> const& tags );
+        friend void setTags( TestCaseInfo& testCaseInfo, std::vector<std::string> tags );
 
         bool isHidden() const;
         bool throws() const;
         bool okToFail() const;
         bool expectedToFail() const;
 
+        std::string tagsAsString() const;
+
         std::string name;
         std::string className;
         std::string description;
-        std::set<std::string> tags;
-        std::set<std::string> lcaseTags;
-        std::string tagsAsString;
+        std::vector<std::string> tags;
+        std::vector<std::string> lcaseTags;
         SourceLineInfo lineInfo;
         SpecialProperties properties;
     };
diff --git a/include/internal/catch_test_spec.cpp b/include/internal/catch_test_spec.cpp
index 0809fc5b..c7f64f30 100644
--- a/include/internal/catch_test_spec.cpp
+++ b/include/internal/catch_test_spec.cpp
@@ -8,6 +8,7 @@
 #include "catch_test_spec.hpp"
 #include "catch_string_manip.h"
 
+#include <algorithm>
 #include <string>
 #include <vector>
 #include <memory>
@@ -23,7 +24,9 @@ namespace Catch {
 
     TestSpec::TagPattern::TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {}
     bool TestSpec::TagPattern::matches( TestCaseInfo const& testCase ) const {
-        return testCase.lcaseTags.find( m_tag ) != testCase.lcaseTags.end();
+        return std::find(begin(testCase.lcaseTags),
+                         end(testCase.lcaseTags),
+                         m_tag) != end(testCase.lcaseTags);
     }
 
     TestSpec::ExcludedPattern::ExcludedPattern( PatternPtr const& underlyingPattern ) : m_underlyingPattern( underlyingPattern ) {}
diff --git a/include/reporters/catch_reporter_junit.cpp b/include/reporters/catch_reporter_junit.cpp
index 1235281a..ae3ea384 100644
--- a/include/reporters/catch_reporter_junit.cpp
+++ b/include/reporters/catch_reporter_junit.cpp
@@ -16,6 +16,7 @@
 #include <assert.h>
 
 #include <ctime>
+#include <algorithm>
 
 namespace Catch {
 
@@ -46,6 +47,14 @@ namespace Catch {
             return std::string(timeStamp);
         }
 
+        std::string fileNameTag(const std::vector<std::string> &tags) {
+            auto it = std::find_if(begin(tags),
+                                   end(tags),
+                                   [] (std::string const& tag) {return tag.front() == '#'; });
+            if (it != tags.end())
+                return it->substr(1);
+            return std::string();
+        }
     }
 
     class JunitReporter : public CumulativeReporterBase<JunitReporter> {
@@ -125,13 +134,6 @@ namespace Catch {
             xml.scopedElement( "system-err" ).writeText( trim( stdErrForSuite.str() ), false );
         }
 
-        static std::string fileNameTag( const std::set<std::string> &tags ) {
-            std::set<std::string>::const_iterator it = tags.lower_bound("#");
-            if( it != tags.end() && !it->empty() && it->front() == '#' )
-                return it->substr(1);
-            return std::string();
-        }
-
         void writeTestCase( TestCaseNode const& testCaseNode ) {
             TestCaseStats const& stats = testCaseNode.value;
 
diff --git a/include/reporters/catch_reporter_xml.cpp b/include/reporters/catch_reporter_xml.cpp
index 9e2ed08b..128899a9 100644
--- a/include/reporters/catch_reporter_xml.cpp
+++ b/include/reporters/catch_reporter_xml.cpp
@@ -66,7 +66,7 @@ namespace Catch {
             m_xml.startElement( "TestCase" )
                 .writeAttribute( "name", trim( testInfo.name ) )
                 .writeAttribute( "description", testInfo.description )
-                .writeAttribute( "tags", testInfo.tagsAsString );
+                .writeAttribute( "tags", testInfo.tagsAsString() );
 
             writeSourceInfo( testInfo.lineInfo );