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

Fix case sensitivity when matching tags

(now insensitive again)
Also group case-different tags together when listing
Commit
fbf3f6f8794bbaf13d50e83d86a674879ec570d0
Author
Phil Nash ·
Parents
e21d0b29cc19

Files · Download .tar.gz

Changes

 include/internal/catch_list.hpp           | 41 ++++++++++++++++++++++---------
 include/internal/catch_test_case_info.h   |  1 +
 include/internal/catch_test_case_info.hpp | 23 +++++++++++------
 include/internal/catch_test_spec.hpp      |  2 +-
 4 files changed, 46 insertions(+), 21 deletions(-)

diff --git a/include/internal/catch_list.hpp b/include/internal/catch_list.hpp
index f05d58c1..6a54f1c1 100644
--- a/include/internal/catch_list.hpp
+++ b/include/internal/catch_list.hpp
@@ -84,7 +84,24 @@ namespace Catch {
             testSpec = TestSpecParser().parse( "*" ).testSpec();
         }
 
-        std::map<std::string, int> tagCounts;
+        struct TagInfo {
+            TagInfo() : count ( 0 ) {}
+            void add( std::string const& spelling ) {
+                ++count;
+                spellings.insert( spelling );
+            }
+            std::string all() const {
+                std::string out;
+                for( std::set<std::string>::const_iterator it = spellings.begin(), itEnd = spellings.end();
+                            it != itEnd;
+                            ++it )
+                    out += "[" + *it + "]";
+                return out;
+            }
+            std::set<std::string> spellings;
+            std::size_t count;
+        };
+        std::map<std::string, TagInfo> tagCounts;
 
         std::vector<TestCase> matchedTestCases;
         getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, config, matchedTestCases );
@@ -96,24 +113,24 @@ namespace Catch {
                     tagIt != tagItEnd;
                     ++tagIt ) {
                 std::string tagName = *tagIt;
-                std::map<std::string, int>::iterator countIt = tagCounts.find( tagName );
+                std::string lcaseTagName = toLower( tagName );
+                std::map<std::string, TagInfo>::iterator countIt = tagCounts.find( lcaseTagName );
                 if( countIt == tagCounts.end() )
-                    tagCounts.insert( std::make_pair( tagName, 1 ) );
-                else
-                    countIt->second++;
+                    countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first;
+                countIt->second.add( tagName );
             }
         }
 
-        for( std::map<std::string, int>::const_iterator countIt = tagCounts.begin(),
-                                                        countItEnd = tagCounts.end();
+        for( std::map<std::string, TagInfo>::const_iterator countIt = tagCounts.begin(),
+                                                            countItEnd = tagCounts.end();
                 countIt != countItEnd;
                 ++countIt ) {
             std::ostringstream oss;
-            oss << "  " << countIt->second << "  ";
-            Text wrapper( "[" + countIt->first + "]", TextAttributes()
-                                                        .setInitialIndent( 0 )
-                                                        .setIndent( oss.str().size() )
-                                                        .setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) );
+            oss << "  " << std::setw(2) << countIt->second.count << "  ";
+            Text wrapper( countIt->second.all(), TextAttributes()
+                                                    .setInitialIndent( 0 )
+                                                    .setIndent( oss.str().size() )
+                                                    .setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) );
             std::cout << oss.str() << wrapper << "\n";
         }
         std::cout << pluralise( tagCounts.size(), "tag" ) << "\n" << std::endl;
diff --git a/include/internal/catch_test_case_info.h b/include/internal/catch_test_case_info.h
index d671a9a4..284aceee 100644
--- a/include/internal/catch_test_case_info.h
+++ b/include/internal/catch_test_case_info.h
@@ -37,6 +37,7 @@ namespace Catch {
         std::string className;
         std::string description;
         std::set<std::string> tags;
+        std::set<std::string> lcaseTags;
         std::string tagsAsString;
         SourceLineInfo lineInfo;
         bool isHidden;
diff --git a/include/internal/catch_test_case_info.hpp b/include/internal/catch_test_case_info.hpp
index 39eb2a39..d5e80753 100644
--- a/include/internal/catch_test_case_info.hpp
+++ b/include/internal/catch_test_case_info.hpp
@@ -102,6 +102,7 @@ namespace Catch {
             oss << "[" << *it << "]";
             if( *it == "!throws" )
                 throws = true;
+            lcaseTags.insert( toLower( *it ) );
         }
         tagsAsString = oss.str();
     }
@@ -111,6 +112,7 @@ namespace Catch {
         className( other.className ),
         description( other.description ),
         tags( other.tags ),
+        lcaseTags( other.lcaseTags ),
         tagsAsString( other.tagsAsString ),
         lineInfo( other.lineInfo ),
         isHidden( other.isHidden ),
@@ -130,6 +132,19 @@ namespace Catch {
         return other;
     }
 
+    void TestCase::swap( TestCase& other ) {
+        test.swap( other.test );
+        name.swap( other.name );
+        className.swap( other.className );
+        description.swap( other.description );
+        tags.swap( other.tags );
+        lcaseTags.swap( other.lcaseTags );
+        tagsAsString.swap( other.tagsAsString );
+        std::swap( TestCaseInfo::isHidden, static_cast<TestCaseInfo&>( other ).isHidden );
+        std::swap( TestCaseInfo::throws, static_cast<TestCaseInfo&>( other ).throws );
+        std::swap( lineInfo, other.lineInfo );
+    }
+
     void TestCase::invoke() const {
         test->invoke();
     }
@@ -141,14 +156,6 @@ namespace Catch {
         return TestCaseInfo::throws;
     }
 
-    void TestCase::swap( TestCase& other ) {
-        test.swap( other.test );
-        className.swap( other.className );
-        name.swap( other.name );
-        description.swap( other.description );
-        std::swap( lineInfo, other.lineInfo );
-    }
-
     bool TestCase::operator == ( TestCase const& other ) const {
         return  test.get() == other.test.get() &&
                 name == other.name &&
diff --git a/include/internal/catch_test_spec.hpp b/include/internal/catch_test_spec.hpp
index 268ed808..2edf5443 100644
--- a/include/internal/catch_test_spec.hpp
+++ b/include/internal/catch_test_spec.hpp
@@ -75,7 +75,7 @@ namespace Catch {
             TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {}
             virtual ~TagPattern();
             virtual bool matches( TestCaseInfo const& testCase ) const {
-                return testCase.tags.find( m_tag ) != testCase.tags.end();
+                return testCase.lcaseTags.find( m_tag ) != testCase.lcaseTags.end();
             }
         private:
             std::string m_tag;