From fbf3f6f8794bbaf13d50e83d86a674879ec570d0 Mon Sep 17 00:00:00 2001 From: Phil Nash Date: Tue, 20 May 2014 18:03:54 +0100 Subject: [PATCH] Fix case sensitivity when matching tags (now insensitive again) Also group case-different tags together when listing --- 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 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::const_iterator it = spellings.begin(), itEnd = spellings.end(); + it != itEnd; + ++it ) + out += "[" + *it + "]"; + return out; + } + std::set spellings; + std::size_t count; + }; + std::map tagCounts; std::vector matchedTestCases; getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, config, matchedTestCases ); @@ -96,24 +113,24 @@ namespace Catch { tagIt != tagItEnd; ++tagIt ) { std::string tagName = *tagIt; - std::map::iterator countIt = tagCounts.find( tagName ); + std::string lcaseTagName = toLower( tagName ); + std::map::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::const_iterator countIt = tagCounts.begin(), - countItEnd = tagCounts.end(); + for( std::map::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 tags; + std::set 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( other ).isHidden ); + std::swap( TestCaseInfo::throws, static_cast( 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;