mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 13:26:10 +01:00
Listing is now in terms of interface (and calls to bool functions)
This commit is contained in:
parent
6b8837bd93
commit
f6892bfdf0
@ -24,8 +24,8 @@ namespace Catch {
|
||||
class Runner2 { // This will become Runner when Runner becomes Context
|
||||
|
||||
public:
|
||||
Runner2( ConfigData const& config )
|
||||
: m_config( new Config( config ) )
|
||||
Runner2( Ptr<Config> const& config )
|
||||
: m_config( config )
|
||||
{
|
||||
openStream();
|
||||
makeReporter();
|
||||
@ -110,15 +110,14 @@ namespace Catch {
|
||||
std::set<TestCase> m_testsAlreadyRun;
|
||||
};
|
||||
|
||||
inline int Main( ConfigData const& configData ) {
|
||||
inline int Main( Ptr<Config> const& config ) {
|
||||
int result = 0;
|
||||
try
|
||||
{
|
||||
Runner2 runner( configData );
|
||||
Runner2 runner( config );
|
||||
|
||||
// Handle list request
|
||||
if( configData.listSpec != List::None ) {
|
||||
list( configData );
|
||||
if( list( config ) ) {
|
||||
Catch::cleanUp();
|
||||
return 0;
|
||||
}
|
||||
@ -195,8 +194,8 @@ namespace Catch {
|
||||
Catch::cleanUp();
|
||||
return (std::numeric_limits<int>::max)();
|
||||
}
|
||||
|
||||
return Main( configData );
|
||||
Ptr<Config> config = new Config( configData );
|
||||
return Main( config );
|
||||
}
|
||||
|
||||
} // end namespace Catch
|
||||
|
@ -101,22 +101,14 @@ namespace Catch {
|
||||
m_data.outputFilename = filename;
|
||||
}
|
||||
|
||||
List::What getListSpec( void ) const {
|
||||
return m_data.listSpec;
|
||||
}
|
||||
|
||||
std::string const& getFilename() const {
|
||||
return m_data.outputFilename ;
|
||||
}
|
||||
|
||||
List::What listWhat() const {
|
||||
return static_cast<List::What>( m_data.listSpec & List::WhatMask );
|
||||
}
|
||||
bool listTests() const { return m_data.listSpec & List::Tests; }
|
||||
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 {
|
||||
return m_data.name;
|
||||
}
|
||||
|
@ -25,8 +25,8 @@ namespace Catch {
|
||||
return true;
|
||||
}
|
||||
|
||||
inline void listTests( ConfigData const& config ) {
|
||||
if( config.filters.empty() )
|
||||
inline void listTests( Ptr<Config> const& config ) {
|
||||
if( config->filters().empty() )
|
||||
std::cout << "All available test cases:\n";
|
||||
else
|
||||
std::cout << "Matching test cases:\n";
|
||||
@ -37,7 +37,7 @@ namespace Catch {
|
||||
std::size_t maxTagLen = 0;
|
||||
std::size_t maxNameLen = 0;
|
||||
for(; it != itEnd; ++it ) {
|
||||
if( matchesFilters( config.filters, *it ) ) {
|
||||
if( matchesFilters( config->filters(), *it ) ) {
|
||||
maxTagLen = (std::max)( it->getTestCaseInfo().tagsAsString.size(), maxTagLen );
|
||||
maxNameLen = (std::max)( it->getTestCaseInfo().name.size(), maxNameLen );
|
||||
}
|
||||
@ -54,7 +54,7 @@ namespace Catch {
|
||||
|
||||
std::size_t matchedTests = 0;
|
||||
for( it = allTests.begin(); it != itEnd; ++it ) {
|
||||
if( matchesFilters( config.filters, *it ) ) {
|
||||
if( matchesFilters( config->filters(), *it ) ) {
|
||||
matchedTests++;
|
||||
// !TBD: consider listAs()
|
||||
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;
|
||||
else
|
||||
std::cout << pluralise( matchedTests, "matching test case" ) << std::endl;
|
||||
}
|
||||
|
||||
inline void listTags( ConfigData const& config ) {
|
||||
if( config.filters.empty() )
|
||||
inline void listTags( Ptr<Config> const& config ) {
|
||||
if( config->filters().empty() )
|
||||
std::cout << "All available tags:\n";
|
||||
else
|
||||
std::cout << "Matching tags:\n";
|
||||
@ -113,7 +113,7 @@ namespace Catch {
|
||||
std::size_t maxTagLen = 0;
|
||||
|
||||
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(),
|
||||
tagItEnd = it->getTestCaseInfo().tags.end();
|
||||
tagIt != tagItEnd;
|
||||
@ -152,7 +152,7 @@ namespace Catch {
|
||||
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";
|
||||
IReporterRegistry::FactoryMap const& factories = getRegistryHub().getReporterRegistry().getFactories();
|
||||
IReporterRegistry::FactoryMap::const_iterator it = factories.begin(), itEnd = factories.end();
|
||||
@ -163,15 +163,21 @@ namespace Catch {
|
||||
std::cout << std::endl;
|
||||
}
|
||||
|
||||
inline void list( ConfigData const& config ) {
|
||||
if( config.listSpec & List::Tests )
|
||||
inline bool list( Ptr<Config> const& config ) {
|
||||
bool listed = false;
|
||||
if( config->listTests() ) {
|
||||
listTests( config );
|
||||
if( config.listSpec & List::Tags )
|
||||
listed = true;
|
||||
}
|
||||
if( config->listTags() ) {
|
||||
listTags( config );
|
||||
if( config.listSpec & List::Reports )
|
||||
listed = true;
|
||||
}
|
||||
if( config->listReporters() ) {
|
||||
listReporters( config );
|
||||
if( ( config.listSpec & List::All ) == 0 )
|
||||
throw std::logic_error( "Unknown list type" );
|
||||
listed = true;
|
||||
}
|
||||
return listed;
|
||||
}
|
||||
|
||||
} // end namespace Catch
|
||||
|
Loading…
Reference in New Issue
Block a user