list options return number listed

This commit is contained in:
Phil Nash 2013-06-06 22:54:42 +01:00
parent e035e2835d
commit f438e04b5d
3 changed files with 23 additions and 25 deletions

View File

@ -194,8 +194,8 @@ namespace Catch {
Runner runner( config ); Runner runner( config );
// Handle list request // Handle list request
if( list( config ) ) if( Option<std::size_t> listed = list( config ) )
return 0; return static_cast<int>( *listed );
return static_cast<int>( runner.runTests().assertions.failed ); return static_cast<int>( runner.runTests().assertions.failed );
} }

View File

@ -25,7 +25,7 @@ namespace Catch {
return true; return true;
} }
inline void listTests( Ptr<Config> const& config ) { inline std::size_t listTests( Ptr<Config> const& config ) {
if( config->filters().empty() ) if( config->filters().empty() )
std::cout << "All available test cases:\n"; std::cout << "All available test cases:\n";
else else
@ -98,9 +98,10 @@ namespace Catch {
std::cout << pluralise( matchedTests, "test case" ) << std::endl; std::cout << pluralise( matchedTests, "test case" ) << std::endl;
else else
std::cout << pluralise( matchedTests, "matching test case" ) << std::endl; std::cout << pluralise( matchedTests, "matching test case" ) << std::endl;
return matchedTests;
} }
inline void listTags( Ptr<Config> const& config ) { inline std::size_t listTags( Ptr<Config> const& config ) {
if( config->filters().empty() ) if( config->filters().empty() )
std::cout << "All available tags:\n"; std::cout << "All available tags:\n";
else else
@ -150,34 +151,28 @@ namespace Catch {
<< "\n"; << "\n";
} }
std::cout << pluralise( tagCounts.size(), "tag" ) << std::endl; std::cout << pluralise( tagCounts.size(), "tag" ) << std::endl;
return tagCounts.size();
} }
inline void listReporters( Ptr<Config> const& /*config*/ ) { inline std::size_t listReporters( Ptr<Config> const& /*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();
IReporterRegistry::FactoryMap::const_iterator it = factories.begin(), itEnd = factories.end(); IReporterRegistry::FactoryMap::const_iterator it = factories.begin(), itEnd = factories.end();
for(; it != itEnd; ++it ) { for(; it != itEnd; ++it )
// !TBD: consider listAs()
std::cout << "\t" << it->first << "\n\t\t'" << it->second->getDescription() << "'\n"; std::cout << "\t" << it->first << "\n\t\t'" << it->second->getDescription() << "'\n";
}
std::cout << std::endl; std::cout << std::endl;
return factories.size();
} }
inline bool list( Ptr<Config> const& config ) { inline Option<std::size_t> list( Ptr<Config> const& config ) {
bool listed = false; Option<std::size_t> listedCount;
if( config->listTests() ) { if( config->listTests() )
listTests( config ); listedCount = listedCount.valueOr(0) + listTests( config );
listed = true; if( config->listTags() )
} listedCount = listedCount.valueOr(0) + listTags( config );
if( config->listTags() ) { if( config->listReporters() )
listTags( config ); listedCount = listedCount.valueOr(0) + listReporters( config );
listed = true; return listedCount;
}
if( config->listReporters() ) {
listReporters( config );
listed = true;
}
return listed;
} }
} // end namespace Catch } // end namespace Catch

View File

@ -45,9 +45,13 @@ namespace Catch {
T* operator->() { return nullableValue; } T* operator->() { return nullableValue; }
const T* operator->() const { 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 some() const { return nullableValue != NULL; }
bool none() const { return nullableValue == NULL; } bool none() const { return nullableValue == NULL; }
bool operator !() const { return nullableValue == NULL; } bool operator !() const { return nullableValue == NULL; }
operator SafeBool::type() const { operator SafeBool::type() const {
return SafeBool::makeSafe( some() ); return SafeBool::makeSafe( some() );
@ -58,7 +62,6 @@ namespace Catch {
char storage[sizeof(T)]; char storage[sizeof(T)];
}; };
} // end namespace Catch } // end namespace Catch
#endif // TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED #endif // TWOBLUECUBES_CATCH_OPTION_HPP_INCLUDED