Read-only mirrors. Development, issues and pull requests are on GitHub.

summaryrefslogtreecommitdiffhomepage
path: root/include
diff options
context:
space:
mode:
authorPhil Nash2013-06-06 22:54:42 +0100
committerPhil Nash2013-06-06 22:54:42 +0100
commitf438e04b5d434ba7ca26a18d68ca0f8756aa542d (patch)
treed9f0bc60384c679082150f39682ca1edc9095dfa /include
parente035e2835dd24c5bc679aa05b63fdf870c91ef15 (diff)
downloadcatch3-f438e04b5d434ba7ca26a18d68ca0f8756aa542d.tar.gz
list options return number listed
Diffstat (limited to 'include')
-rw-r--r--include/catch_runner.hpp4
-rw-r--r--include/internal/catch_list.hpp37
-rw-r--r--include/internal/catch_option.hpp7
3 files changed, 23 insertions, 25 deletions
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<std::size_t> listed = list( config ) )
+ return static_cast<int>( *listed );
return static_cast<int>( 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<Config> const& config ) {
+ inline std::size_t listTests( Ptr<Config> 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<Config> const& config ) {
+ inline std::size_t listTags( Ptr<Config> 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<Config> const& /*config*/ ) {
+ inline std::size_t listReporters( Ptr<Config> 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<Config> 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<std::size_t> list( Ptr<Config> const& config ) {
+ Option<std::size_t> 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