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();
}
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;

View File

@ -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;

View File

@ -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 &&

View File

@ -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;