diff --git a/include/catch_runner.hpp b/include/catch_runner.hpp index 37a8ed2e..cd6d87e9 100644 --- a/include/catch_runner.hpp +++ b/include/catch_runner.hpp @@ -194,8 +194,8 @@ namespace Catch { Runner runner( config ); // Handle list request - if( list( config ) ) - return 0; + if( Option listed = list( config ) ) + return static_cast( *listed ); return static_cast( runner.runTests().assertions.failed ); } diff --git a/include/internal/catch_list.hpp b/include/internal/catch_list.hpp index e583bb87..263cd515 100644 --- a/include/internal/catch_list.hpp +++ b/include/internal/catch_list.hpp @@ -25,7 +25,7 @@ namespace Catch { return true; } - inline void listTests( Ptr const& config ) { + inline std::size_t listTests( Ptr const& config ) { if( config->filters().empty() ) std::cout << "All available test cases:\n"; else @@ -98,9 +98,10 @@ namespace Catch { std::cout << pluralise( matchedTests, "test case" ) << std::endl; else std::cout << pluralise( matchedTests, "matching test case" ) << std::endl; + return matchedTests; } - inline void listTags( Ptr const& config ) { + inline std::size_t listTags( Ptr const& config ) { if( config->filters().empty() ) std::cout << "All available tags:\n"; else @@ -150,34 +151,28 @@ namespace Catch { << "\n"; } std::cout << pluralise( tagCounts.size(), "tag" ) << std::endl; + return tagCounts.size(); } - inline void listReporters( Ptr const& /*config*/ ) { + inline std::size_t listReporters( Ptr const& /*config*/ ) { std::cout << "Available reports:\n"; IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories(); IReporterRegistry::FactoryMap::const_iterator it = factories.begin(), itEnd = factories.end(); - for(; it != itEnd; ++it ) { - // !TBD: consider listAs() + for(; it != itEnd; ++it ) std::cout << "\t" << it->first << "\n\t\t'" << it->second->getDescription() << "'\n"; - } std::cout << std::endl; + return factories.size(); } - inline bool list( Ptr const& config ) { - bool listed = false; - if( config->listTests() ) { - listTests( config ); - listed = true; - } - if( config->listTags() ) { - listTags( config ); - listed = true; - } - if( config->listReporters() ) { - listReporters( config ); - listed = true; - } - return listed; + inline Option list( Ptr const& config ) { + Option listedCount; + if( config->listTests() ) + listedCount = listedCount.valueOr(0) + listTests( config ); + if( config->listTags() ) + listedCount = listedCount.valueOr(0) + listTags( config ); + if( config->listReporters() ) + listedCount = listedCount.valueOr(0) + listReporters( config ); + return listedCount; } } // end namespace Catch diff --git a/include/internal/catch_option.hpp b/include/internal/catch_option.hpp index 9d6dec15..c56e1582 100644 --- a/include/internal/catch_option.hpp +++ b/include/internal/catch_option.hpp @@ -45,9 +45,13 @@ namespace Catch { T* operator->() { return nullableValue; } const T* operator->() const { return nullableValue; } + T valueOr( T const& defaultValue ) const { + return nullableValue ? *nullableValue : defaultValue; + } + bool some() const { return nullableValue != NULL; } bool none() const { return nullableValue == NULL; } - + bool operator !() const { return nullableValue == NULL; } operator SafeBool::type() const { return SafeBool::makeSafe( some() ); @@ -58,7 +62,6 @@ namespace Catch { char storage[sizeof(T)]; }; - } // end namespace Catch #endif // TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED