Fix case sensitivity when matching tags

(now insensitive again)
Also group case-different tags together when listing
This commit is contained in:
Phil Nash 2014-05-20 18:03:54 +01:00
parent e21d0b29cc
commit fbf3f6f879
4 changed files with 46 additions and 21 deletions

View File

@ -84,7 +84,24 @@ namespace Catch {
testSpec = TestSpecParser().parse( "*" ).testSpec(); 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; std::vector<TestCase> matchedTestCases;
getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, config, matchedTestCases ); getRegistryHub().getTestCaseRegistry().getFilteredTests( testSpec, config, matchedTestCases );
@ -96,21 +113,21 @@ namespace Catch {
tagIt != tagItEnd; tagIt != tagItEnd;
++tagIt ) { ++tagIt ) {
std::string tagName = *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() ) if( countIt == tagCounts.end() )
tagCounts.insert( std::make_pair( tagName, 1 ) ); countIt = tagCounts.insert( std::make_pair( lcaseTagName, TagInfo() ) ).first;
else countIt->second.add( tagName );
countIt->second++;
} }
} }
for( std::map<std::string, int>::const_iterator countIt = tagCounts.begin(), for( std::map<std::string, TagInfo>::const_iterator countIt = tagCounts.begin(),
countItEnd = tagCounts.end(); countItEnd = tagCounts.end();
countIt != countItEnd; countIt != countItEnd;
++countIt ) { ++countIt ) {
std::ostringstream oss; std::ostringstream oss;
oss << " " << countIt->second << " "; oss << " " << std::setw(2) << countIt->second.count << " ";
Text wrapper( "[" + countIt->first + "]", TextAttributes() Text wrapper( countIt->second.all(), TextAttributes()
.setInitialIndent( 0 ) .setInitialIndent( 0 )
.setIndent( oss.str().size() ) .setIndent( oss.str().size() )
.setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) ); .setWidth( CATCH_CONFIG_CONSOLE_WIDTH-10 ) );

View File

@ -37,6 +37,7 @@ namespace Catch {
std::string className; std::string className;
std::string description; std::string description;
std::set<std::string> tags; std::set<std::string> tags;
std::set<std::string> lcaseTags;
std::string tagsAsString; std::string tagsAsString;
SourceLineInfo lineInfo; SourceLineInfo lineInfo;
bool isHidden; bool isHidden;

View File

@ -102,6 +102,7 @@ namespace Catch {
oss << "[" << *it << "]"; oss << "[" << *it << "]";
if( *it == "!throws" ) if( *it == "!throws" )
throws = true; throws = true;
lcaseTags.insert( toLower( *it ) );
} }
tagsAsString = oss.str(); tagsAsString = oss.str();
} }
@ -111,6 +112,7 @@ namespace Catch {
className( other.className ), className( other.className ),
description( other.description ), description( other.description ),
tags( other.tags ), tags( other.tags ),
lcaseTags( other.lcaseTags ),
tagsAsString( other.tagsAsString ), tagsAsString( other.tagsAsString ),
lineInfo( other.lineInfo ), lineInfo( other.lineInfo ),
isHidden( other.isHidden ), isHidden( other.isHidden ),
@ -130,6 +132,19 @@ namespace Catch {
return other; 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 { void TestCase::invoke() const {
test->invoke(); test->invoke();
} }
@ -141,14 +156,6 @@ namespace Catch {
return TestCaseInfo::throws; 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 { bool TestCase::operator == ( TestCase const& other ) const {
return test.get() == other.test.get() && return test.get() == other.test.get() &&
name == other.name && name == other.name &&

View File

@ -75,7 +75,7 @@ namespace Catch {
TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {} TagPattern( std::string const& tag ) : m_tag( toLower( tag ) ) {}
virtual ~TagPattern(); virtual ~TagPattern();
virtual bool matches( TestCaseInfo const& testCase ) const { 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: private:
std::string m_tag; std::string m_tag;