Added -l tags

- which lists available tags.
- also improved formatting of -l for tests
This commit is contained in:
Phil Nash 2013-03-29 11:42:10 +00:00
parent d0df295c25
commit e324d2829d
7 changed files with 710 additions and 147 deletions

View File

@ -322,7 +322,8 @@ namespace Catch {
m_optionNames.push_back( "--list" );
}
virtual std::string argsSynopsis() const {
return "[all | tests | reporters [xml]]";
// return "[all | tests | reporters | tags [xml]]";
return "[all | tests | reporters | tags]";
}
virtual std::string optionSummary() const {
return "Lists available tests or reporters";
@ -331,29 +332,32 @@ namespace Catch {
virtual std::string optionDescription() const {
return
"With no arguments this option will list all registered tests - one per line.\n"
"Supplying the xml argument formats the list as an xml document (which may be useful for "
"consumption by other tools).\n"
// "Supplying the xml argument formats the list as an xml document (which may be useful for "
// "consumption by other tools).\n"
"Supplying the tests or reporters lists tests or reporters respectively - with descriptions.\n"
"\n"
"Examples:\n"
"\n"
" -l\n"
" -l tests\n"
" -l tags\n"
" -l reporters xml\n"
" -l xml";
;//" -l xml";
}
virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) {
config.listSpec = List::TestNames;
config.listSpec = List::Tests;
if( cmd.argsCount() >= 1 ) {
if( cmd[0] == "all" )
config.listSpec = List::All;
else if( cmd[0] == "tests" )
config.listSpec = List::Tests;
else if( cmd[0] == "tags" )
config.listSpec = List::Tags;
else if( cmd[0] == "reporters" )
config.listSpec = List::Reports;
else
cmd.raiseError( "Expected [tests] or [reporters]" );
cmd.raiseError( "Expected tests, reporters or tags" );
}
if( cmd.argsCount() >= 2 ) {
if( cmd[1] == "xml" )
@ -361,7 +365,7 @@ namespace Catch {
else if( cmd[1] == "text" )
config.listSpec = static_cast<List::What>( config.listSpec | List::AsText );
else
cmd.raiseError( "Expected [xml] or [text]" );
cmd.raiseError( "Expected xml or text" );
}
}
};

View File

@ -34,9 +34,8 @@ namespace Catch {
Reports = 1,
Tests = 2,
All = 3,
TestNames = 6,
Tags = 4,
All = Reports | Tests | Tags,
WhatMask = 0xf,

View File

@ -28,6 +28,7 @@ namespace Catch {
const_iterator begin() const { return lines.begin(); }
const_iterator end() const { return lines.end(); }
std::string const& last() const { return lines.back(); }
std::size_t size() const { return lines.size(); }
std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }

View File

@ -66,7 +66,7 @@ namespace Catch {
std::string withoutTab = _str.substr( 0, nextTab ) + _str.substr( nextTab+1 );
return wrapInternal( withoutTab );
}
else if( isWrapPoint( _str[pos] ) ) {
else if( pos > 0 && isWrapPoint( _str[pos] ) ) {
wrapPoint = pos;
}
}

View File

@ -36,8 +36,10 @@ namespace Catch {
std::size_t maxTagLen = 0;
std::size_t maxNameLen = 0;
for(; it != itEnd; ++it ) {
maxTagLen = (std::max)( it->getTestCaseInfo().tagsAsString.size(), maxTagLen );
maxNameLen = (std::max)( it->getTestCaseInfo().name.size(), maxNameLen );
if( matchesFilters( config.filters, *it ) ) {
maxTagLen = (std::max)( it->getTestCaseInfo().tagsAsString.size(), maxTagLen );
maxNameLen = (std::max)( it->getTestCaseInfo().name.size(), maxNameLen );
}
}
// Try to fit everything in. If not shrink tag column first, down to 30
@ -66,9 +68,13 @@ namespace Catch {
nameCol = nameWrapper[i];
else
nameCol = " ...";
std::cout << nameCol << " " << std::string( maxNameLen - nameCol.size(), ' ' );
if( i < tagsWrapper.size() )
std::cout << tagsWrapper[i];
std::cout << nameCol;
if( i < tagsWrapper.size() && !tagsWrapper[i].empty() ) {
if( i == 0 )
std::cout << " " << std::string( maxNameLen - nameCol.size(), '.' ) << " " << tagsWrapper[i];
else
std::cout << std::string( maxNameLen - nameCol.size(), ' ' ) << " " << tagsWrapper[i];
}
std::cout << "\n";
}
}
@ -78,6 +84,54 @@ namespace Catch {
else
std::cout << pluralise( matchedTests, "matching test case" ) << std::endl;
}
inline void listTags( const ConfigData& config ) {
if( config.filters.empty() )
std::cout << "All available tags:\n";
else
std::cout << "Matching tags:\n";
std::vector<TestCase> const& allTests = getRegistryHub().getTestCaseRegistry().getAllTests();
std::vector<TestCase>::const_iterator it = allTests.begin(), itEnd = allTests.end();
std::map<std::string, int> tagCounts;
std::size_t maxTagLen = 0;
for(; it != itEnd; ++it ) {
if( matchesFilters( config.filters, *it ) ) {
for( std::set<std::string>::const_iterator tagIt = it->getTestCaseInfo().tags.begin(),
tagItEnd = it->getTestCaseInfo().tags.end();
tagIt != tagItEnd;
++tagIt ) {
std::string tagName = "[" + *tagIt + "]";
maxTagLen = (std::max)( maxTagLen, tagName.size() );
std::map<std::string, int>::iterator countIt = tagCounts.find( tagName );
if( countIt == tagCounts.end() )
tagCounts.insert( std::make_pair( tagName, 1 ) );
else
countIt->second++;
}
}
}
maxTagLen +=2;
if( maxTagLen > CATCH_CONFIG_CONSOLE_WIDTH-10 )
maxTagLen = CATCH_CONFIG_CONSOLE_WIDTH-10;
for( std::map<std::string, int>::const_iterator countIt = tagCounts.begin(), countItEnd = tagCounts.end();
countIt != countItEnd;
++countIt ) {
LineWrapper wrapper;
wrapper.setIndent(2).setRight( maxTagLen ).wrap( countIt->first );
std::cout << wrapper;
if( maxTagLen > wrapper.last().size() )
std::cout << std::string( maxTagLen - wrapper.last().size(), '.' );
std::cout << ".. "
<< countIt->second
<< "\n";
}
std::cout << pluralise( tagCounts.size(), "tag" ) << std::endl;
}
inline void listReporters( const ConfigData& /*config*/ ) {
std::cout << "Available reports:\n";
@ -93,9 +147,11 @@ namespace Catch {
inline void list( const ConfigData& config ) {
if( config.listSpec & List::Tests )
listTests( config );
else if( config.listSpec & List::Reports )
if( config.listSpec & List::Tags )
listTags( config );
if( config.listSpec & List::Reports )
listReporters( config );
else
if( ( config.listSpec & List::All ) == 0 )
throw std::logic_error( "Unknown list type" );
}

File diff suppressed because it is too large Load Diff

View File

@ -57,5 +57,8 @@ SCENARIO( "Vector resizing affects size and capacity", "[vector][bdd][size][capa
}
}
SCENARIO( "This is a really long scenario name to see how the list command deals with wrapping", "[very long tags][lots][long][tags][verbose]" ) {
SCENARIO( "This is a really long scenario name to see how the list command deals with wrapping",
"[very long tags][lots][long][tags][verbose]"
"[one very long tag name that should cause line wrapping writing out using the list command]"
"[anotherReallyLongTagNameButThisOneHasNoObviousWrapPointsSoShouldSplitWithinAWordUsingADashCharacter]" ) {
}