Listing is now in terms of interface (and calls to bool functions)

This commit is contained in:
Phil Nash 2013-05-29 07:59:01 +01:00
parent 6b8837bd93
commit f6892bfdf0
3 changed files with 31 additions and 34 deletions

View File

@ -24,8 +24,8 @@ namespace Catch {
class Runner2 { // This will become Runner when Runner becomes Context class Runner2 { // This will become Runner when Runner becomes Context
public: public:
Runner2( ConfigData const& config ) Runner2( Ptr<Config> const& config )
: m_config( new Config( config ) ) : m_config( config )
{ {
openStream(); openStream();
makeReporter(); makeReporter();
@ -110,15 +110,14 @@ namespace Catch {
std::set<TestCase> m_testsAlreadyRun; std::set<TestCase> m_testsAlreadyRun;
}; };
inline int Main( ConfigData const& configData ) { inline int Main( Ptr<Config> const& config ) {
int result = 0; int result = 0;
try try
{ {
Runner2 runner( configData ); Runner2 runner( config );
// Handle list request // Handle list request
if( configData.listSpec != List::None ) { if( list( config ) ) {
list( configData );
Catch::cleanUp(); Catch::cleanUp();
return 0; return 0;
} }
@ -195,8 +194,8 @@ namespace Catch {
Catch::cleanUp(); Catch::cleanUp();
return (std::numeric_limits<int>::max)(); return (std::numeric_limits<int>::max)();
} }
Ptr<Config> config = new Config( configData );
return Main( configData ); return Main( config );
} }
} // end namespace Catch } // end namespace Catch

View File

@ -101,21 +101,13 @@ namespace Catch {
m_data.outputFilename = filename; m_data.outputFilename = filename;
} }
List::What getListSpec( void ) const {
return m_data.listSpec;
}
std::string const& getFilename() const { std::string const& getFilename() const {
return m_data.outputFilename ; return m_data.outputFilename ;
} }
List::What listWhat() const { bool listTests() const { return m_data.listSpec & List::Tests; }
return static_cast<List::What>( m_data.listSpec & List::WhatMask ); bool listTags() const { return m_data.listSpec & List::Tags; }
} bool listReporters() const { return m_data.listSpec & List::Reports; }
List::What listAs() const {
return static_cast<List::What>( m_data.listSpec & List::AsMask );
}
std::string getName() const { std::string getName() const {
return m_data.name; return m_data.name;

View File

@ -25,8 +25,8 @@ namespace Catch {
return true; return true;
} }
inline void listTests( ConfigData const& config ) { inline void 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
std::cout << "Matching test cases:\n"; std::cout << "Matching test cases:\n";
@ -37,7 +37,7 @@ 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 ) {
if( matchesFilters( config.filters, *it ) ) { if( matchesFilters( config->filters(), *it ) ) {
maxTagLen = (std::max)( it->getTestCaseInfo().tagsAsString.size(), maxTagLen ); maxTagLen = (std::max)( it->getTestCaseInfo().tagsAsString.size(), maxTagLen );
maxNameLen = (std::max)( it->getTestCaseInfo().name.size(), maxNameLen ); maxNameLen = (std::max)( it->getTestCaseInfo().name.size(), maxNameLen );
} }
@ -54,7 +54,7 @@ namespace Catch {
std::size_t matchedTests = 0; std::size_t matchedTests = 0;
for( it = allTests.begin(); it != itEnd; ++it ) { for( it = allTests.begin(); it != itEnd; ++it ) {
if( matchesFilters( config.filters, *it ) ) { if( matchesFilters( config->filters(), *it ) ) {
matchedTests++; matchedTests++;
// !TBD: consider listAs() // !TBD: consider listAs()
Text nameWrapper( it->getTestCaseInfo().name, Text nameWrapper( it->getTestCaseInfo().name,
@ -94,14 +94,14 @@ namespace Catch {
} }
} }
} }
if( config.filters.empty() ) if( config->filters().empty() )
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;
} }
inline void listTags( ConfigData const& config ) { inline void 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
std::cout << "Matching tags:\n"; std::cout << "Matching tags:\n";
@ -113,7 +113,7 @@ namespace Catch {
std::size_t maxTagLen = 0; std::size_t maxTagLen = 0;
for(; it != itEnd; ++it ) { for(; it != itEnd; ++it ) {
if( matchesFilters( config.filters, *it ) ) { if( matchesFilters( config->filters(), *it ) ) {
for( std::set<std::string>::const_iterator tagIt = it->getTestCaseInfo().tags.begin(), for( std::set<std::string>::const_iterator tagIt = it->getTestCaseInfo().tags.begin(),
tagItEnd = it->getTestCaseInfo().tags.end(); tagItEnd = it->getTestCaseInfo().tags.end();
tagIt != tagItEnd; tagIt != tagItEnd;
@ -152,7 +152,7 @@ namespace Catch {
std::cout << pluralise( tagCounts.size(), "tag" ) << std::endl; std::cout << pluralise( tagCounts.size(), "tag" ) << std::endl;
} }
inline void listReporters( ConfigData const& /*config*/ ) { inline void 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();
@ -163,15 +163,21 @@ namespace Catch {
std::cout << std::endl; std::cout << std::endl;
} }
inline void list( ConfigData const& config ) { inline bool list( Ptr<Config> const& config ) {
if( config.listSpec & List::Tests ) bool listed = false;
if( config->listTests() ) {
listTests( config ); listTests( config );
if( config.listSpec & List::Tags ) listed = true;
}
if( config->listTags() ) {
listTags( config ); listTags( config );
if( config.listSpec & List::Reports ) listed = true;
}
if( config->listReporters() ) {
listReporters( config ); listReporters( config );
if( ( config.listSpec & List::All ) == 0 ) listed = true;
throw std::logic_error( "Unknown list type" ); }
return listed;
} }
} // end namespace Catch } // end namespace Catch