diff options
| author | Phil Nash | 2013-03-29 11:42:10 +0000 |
|---|---|---|
| committer | Phil Nash | 2013-03-29 11:42:10 +0000 |
| commit | e324d2829d632febf346d1df698da5557c99cf6c (patch) | |
| tree | 636ca2900c8aa1d82d53c06676b4921ee4c68e7f /include/internal | |
| parent | d0df295c25e1967b9bf94cf234a47a80c47b0369 (diff) | |
| download | catch3-e324d2829d632febf346d1df698da5557c99cf6c.tar.gz | |
Added -l tags
- which lists available tags.
- also improved formatting of -l for tests
Diffstat (limited to 'include/internal')
| -rw-r--r-- | include/internal/catch_commandline.hpp | 18 | ||||
| -rw-r--r-- | include/internal/catch_config.hpp | 5 | ||||
| -rw-r--r-- | include/internal/catch_line_wrap.h | 1 | ||||
| -rw-r--r-- | include/internal/catch_line_wrap.hpp | 2 | ||||
| -rw-r--r-- | include/internal/catch_list.hpp | 70 |
5 files changed, 78 insertions, 18 deletions
diff --git a/include/internal/catch_commandline.hpp b/include/internal/catch_commandline.hpp index 7558e257..4c32d7f3 100644 --- a/include/internal/catch_commandline.hpp +++ b/include/internal/catch_commandline.hpp @@ -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" ); } } }; diff --git a/include/internal/catch_config.hpp b/include/internal/catch_config.hpp index 1ef3fff6..0e5de388 100644 --- a/include/internal/catch_config.hpp +++ b/include/internal/catch_config.hpp @@ -34,9 +34,8 @@ namespace Catch { Reports = 1, Tests = 2, - All = 3, - - TestNames = 6, + Tags = 4, + All = Reports | Tests | Tags, WhatMask = 0xf, diff --git a/include/internal/catch_line_wrap.h b/include/internal/catch_line_wrap.h index 0ec49cdb..7cd08055 100644 --- a/include/internal/catch_line_wrap.h +++ b/include/internal/catch_line_wrap.h @@ -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]; } diff --git a/include/internal/catch_line_wrap.hpp b/include/internal/catch_line_wrap.hpp index a51e98a8..9c6f3019 100644 --- a/include/internal/catch_line_wrap.hpp +++ b/include/internal/catch_line_wrap.hpp @@ -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; } } diff --git a/include/internal/catch_list.hpp b/include/internal/catch_list.hpp index f7f0c657..458c3a21 100644 --- a/include/internal/catch_list.hpp +++ b/include/internal/catch_list.hpp @@ -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" ); } |