mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Added -l tags
- which lists available tags. - also improved formatting of -l for tests
This commit is contained in:
parent
d0df295c25
commit
e324d2829d
@ -322,7 +322,8 @@ namespace Catch {
|
|||||||
m_optionNames.push_back( "--list" );
|
m_optionNames.push_back( "--list" );
|
||||||
}
|
}
|
||||||
virtual std::string argsSynopsis() const {
|
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 {
|
virtual std::string optionSummary() const {
|
||||||
return "Lists available tests or reporters";
|
return "Lists available tests or reporters";
|
||||||
@ -331,29 +332,32 @@ namespace Catch {
|
|||||||
virtual std::string optionDescription() const {
|
virtual std::string optionDescription() const {
|
||||||
return
|
return
|
||||||
"With no arguments this option will list all registered tests - one per line.\n"
|
"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 "
|
// "Supplying the xml argument formats the list as an xml document (which may be useful for "
|
||||||
"consumption by other tools).\n"
|
// "consumption by other tools).\n"
|
||||||
"Supplying the tests or reporters lists tests or reporters respectively - with descriptions.\n"
|
"Supplying the tests or reporters lists tests or reporters respectively - with descriptions.\n"
|
||||||
"\n"
|
"\n"
|
||||||
"Examples:\n"
|
"Examples:\n"
|
||||||
"\n"
|
"\n"
|
||||||
" -l\n"
|
" -l\n"
|
||||||
" -l tests\n"
|
" -l tests\n"
|
||||||
|
" -l tags\n"
|
||||||
" -l reporters xml\n"
|
" -l reporters xml\n"
|
||||||
" -l xml";
|
;//" -l xml";
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) {
|
virtual void parseIntoConfig( const Command& cmd, ConfigData& config ) {
|
||||||
config.listSpec = List::TestNames;
|
config.listSpec = List::Tests;
|
||||||
if( cmd.argsCount() >= 1 ) {
|
if( cmd.argsCount() >= 1 ) {
|
||||||
if( cmd[0] == "all" )
|
if( cmd[0] == "all" )
|
||||||
config.listSpec = List::All;
|
config.listSpec = List::All;
|
||||||
else if( cmd[0] == "tests" )
|
else if( cmd[0] == "tests" )
|
||||||
config.listSpec = List::Tests;
|
config.listSpec = List::Tests;
|
||||||
|
else if( cmd[0] == "tags" )
|
||||||
|
config.listSpec = List::Tags;
|
||||||
else if( cmd[0] == "reporters" )
|
else if( cmd[0] == "reporters" )
|
||||||
config.listSpec = List::Reports;
|
config.listSpec = List::Reports;
|
||||||
else
|
else
|
||||||
cmd.raiseError( "Expected [tests] or [reporters]" );
|
cmd.raiseError( "Expected tests, reporters or tags" );
|
||||||
}
|
}
|
||||||
if( cmd.argsCount() >= 2 ) {
|
if( cmd.argsCount() >= 2 ) {
|
||||||
if( cmd[1] == "xml" )
|
if( cmd[1] == "xml" )
|
||||||
@ -361,7 +365,7 @@ namespace Catch {
|
|||||||
else if( cmd[1] == "text" )
|
else if( cmd[1] == "text" )
|
||||||
config.listSpec = static_cast<List::What>( config.listSpec | List::AsText );
|
config.listSpec = static_cast<List::What>( config.listSpec | List::AsText );
|
||||||
else
|
else
|
||||||
cmd.raiseError( "Expected [xml] or [text]" );
|
cmd.raiseError( "Expected xml or text" );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -34,9 +34,8 @@ namespace Catch {
|
|||||||
|
|
||||||
Reports = 1,
|
Reports = 1,
|
||||||
Tests = 2,
|
Tests = 2,
|
||||||
All = 3,
|
Tags = 4,
|
||||||
|
All = Reports | Tests | Tags,
|
||||||
TestNames = 6,
|
|
||||||
|
|
||||||
WhatMask = 0xf,
|
WhatMask = 0xf,
|
||||||
|
|
||||||
|
@ -28,6 +28,7 @@ namespace Catch {
|
|||||||
|
|
||||||
const_iterator begin() const { return lines.begin(); }
|
const_iterator begin() const { return lines.begin(); }
|
||||||
const_iterator end() const { return lines.end(); }
|
const_iterator end() const { return lines.end(); }
|
||||||
|
std::string const& last() const { return lines.back(); }
|
||||||
std::size_t size() const { return lines.size(); }
|
std::size_t size() const { return lines.size(); }
|
||||||
std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }
|
std::string const& operator[]( std::size_t _index ) const { return lines[_index]; }
|
||||||
|
|
||||||
|
@ -66,7 +66,7 @@ namespace Catch {
|
|||||||
std::string withoutTab = _str.substr( 0, nextTab ) + _str.substr( nextTab+1 );
|
std::string withoutTab = _str.substr( 0, nextTab ) + _str.substr( nextTab+1 );
|
||||||
return wrapInternal( withoutTab );
|
return wrapInternal( withoutTab );
|
||||||
}
|
}
|
||||||
else if( isWrapPoint( _str[pos] ) ) {
|
else if( pos > 0 && isWrapPoint( _str[pos] ) ) {
|
||||||
wrapPoint = pos;
|
wrapPoint = pos;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -36,8 +36,10 @@ namespace Catch {
|
|||||||
std::size_t maxTagLen = 0;
|
std::size_t maxTagLen = 0;
|
||||||
std::size_t maxNameLen = 0;
|
std::size_t maxNameLen = 0;
|
||||||
for(; it != itEnd; ++it ) {
|
for(; it != itEnd; ++it ) {
|
||||||
maxTagLen = (std::max)( it->getTestCaseInfo().tagsAsString.size(), maxTagLen );
|
if( matchesFilters( config.filters, *it ) ) {
|
||||||
maxNameLen = (std::max)( it->getTestCaseInfo().name.size(), maxNameLen );
|
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
|
// Try to fit everything in. If not shrink tag column first, down to 30
|
||||||
@ -66,9 +68,13 @@ namespace Catch {
|
|||||||
nameCol = nameWrapper[i];
|
nameCol = nameWrapper[i];
|
||||||
else
|
else
|
||||||
nameCol = " ...";
|
nameCol = " ...";
|
||||||
std::cout << nameCol << " " << std::string( maxNameLen - nameCol.size(), ' ' );
|
std::cout << nameCol;
|
||||||
if( i < tagsWrapper.size() )
|
if( i < tagsWrapper.size() && !tagsWrapper[i].empty() ) {
|
||||||
std::cout << tagsWrapper[i];
|
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";
|
std::cout << "\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -79,6 +85,54 @@ namespace Catch {
|
|||||||
std::cout << pluralise( matchedTests, "matching test case" ) << std::endl;
|
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*/ ) {
|
inline void listReporters( const ConfigData& /*config*/ ) {
|
||||||
std::cout << "Available reports:\n";
|
std::cout << "Available reports:\n";
|
||||||
IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
|
IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
|
||||||
@ -93,9 +147,11 @@ namespace Catch {
|
|||||||
inline void list( const ConfigData& config ) {
|
inline void list( const ConfigData& config ) {
|
||||||
if( config.listSpec & List::Tests )
|
if( config.listSpec & List::Tests )
|
||||||
listTests( config );
|
listTests( config );
|
||||||
else if( config.listSpec & List::Reports )
|
if( config.listSpec & List::Tags )
|
||||||
|
listTags( config );
|
||||||
|
if( config.listSpec & List::Reports )
|
||||||
listReporters( config );
|
listReporters( config );
|
||||||
else
|
if( ( config.listSpec & List::All ) == 0 )
|
||||||
throw std::logic_error( "Unknown list type" );
|
throw std::logic_error( "Unknown list type" );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -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]" ) {
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user