mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Runner -> RunContext, Runner2 -> Runner and fixed issue with processName
This commit is contained in:
parent
1b47e11387
commit
cb60d130f8
@ -21,10 +21,10 @@
|
|||||||
|
|
||||||
namespace Catch {
|
namespace Catch {
|
||||||
|
|
||||||
class Runner2 { // This will become Runner when Runner becomes Context
|
class Runner {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Runner2( Ptr<Config> const& config )
|
Runner( Ptr<Config> const& config )
|
||||||
: m_config( config )
|
: m_config( config )
|
||||||
{
|
{
|
||||||
openStream();
|
openStream();
|
||||||
@ -39,7 +39,8 @@ namespace Catch {
|
|||||||
filterGroups.push_back( filterGroup );
|
filterGroups.push_back( filterGroup );
|
||||||
}
|
}
|
||||||
|
|
||||||
Runner context( m_config.get(), m_reporter ); // This Runner will be renamed Context
|
RunContext context( m_config.get(), m_reporter );
|
||||||
|
|
||||||
Totals totals;
|
Totals totals;
|
||||||
|
|
||||||
for( std::size_t i=0; i < filterGroups.size() && !context.aborting(); ++i ) {
|
for( std::size_t i=0; i < filterGroups.size() && !context.aborting(); ++i ) {
|
||||||
@ -50,7 +51,7 @@ namespace Catch {
|
|||||||
return totals;
|
return totals;
|
||||||
}
|
}
|
||||||
|
|
||||||
Totals runTestsForGroup( Runner& context, const TestCaseFilters& filterGroup ) {
|
Totals runTestsForGroup( RunContext& context, const TestCaseFilters& filterGroup ) {
|
||||||
Totals totals;
|
Totals totals;
|
||||||
std::vector<TestCase>::const_iterator it = getRegistryHub().getTestCaseRegistry().getAllTests().begin();
|
std::vector<TestCase>::const_iterator it = getRegistryHub().getTestCaseRegistry().getAllTests().begin();
|
||||||
std::vector<TestCase>::const_iterator itEnd = getRegistryHub().getTestCaseRegistry().getAllTests().end();
|
std::vector<TestCase>::const_iterator itEnd = getRegistryHub().getTestCaseRegistry().getAllTests().end();
|
||||||
@ -111,7 +112,7 @@ namespace Catch {
|
|||||||
int result = 0;
|
int result = 0;
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
Runner2 runner( config );
|
Runner runner( config );
|
||||||
|
|
||||||
// Handle list request
|
// Handle list request
|
||||||
if( list( config ) ) {
|
if( list( config ) ) {
|
||||||
@ -144,7 +145,7 @@ namespace Catch {
|
|||||||
cli.usage( std::cout, processName );
|
cli.usage( std::cout, processName );
|
||||||
std::cout << "\nFor more detail usage please see: https://github.com/philsquared/Catch/wiki/Command-line\n" << std::endl;
|
std::cout << "\nFor more detail usage please see: https://github.com/philsquared/Catch/wiki/Command-line\n" << std::endl;
|
||||||
}
|
}
|
||||||
inline Ptr<Config> processConfig( int argc, char* const argv[], ConfigData configData = ConfigData() ) {
|
inline Ptr<Config> processConfig( int argc, char* const argv[], ConfigData& configData ) {
|
||||||
Clara::CommandLine<ConfigData> cli = makeCommandLineParser();
|
Clara::CommandLine<ConfigData> cli = makeCommandLineParser();
|
||||||
std::vector<Clara::Parser::Token> unused = cli.parseInto( argc, argv, configData );
|
std::vector<Clara::Parser::Token> unused = cli.parseInto( argc, argv, configData );
|
||||||
if( !unused.empty() ) {
|
if( !unused.empty() ) {
|
||||||
@ -159,6 +160,10 @@ namespace Catch {
|
|||||||
Ptr<Config> config = new Config( configData );
|
Ptr<Config> config = new Config( configData );
|
||||||
return config;
|
return config;
|
||||||
}
|
}
|
||||||
|
inline Ptr<Config> processConfig( int argc, char* const argv[] ) {
|
||||||
|
ConfigData configData;
|
||||||
|
return processConfig( argc, argv, configData );
|
||||||
|
}
|
||||||
|
|
||||||
inline int Main( int argc, char* const argv[], ConfigData configData = ConfigData() ) {
|
inline int Main( int argc, char* const argv[], ConfigData configData = ConfigData() ) {
|
||||||
|
|
||||||
@ -167,7 +172,7 @@ namespace Catch {
|
|||||||
try {
|
try {
|
||||||
config = processConfig( argc, argv, configData );
|
config = processConfig( argc, argv, configData );
|
||||||
if( config->showHelp() ) {
|
if( config->showHelp() ) {
|
||||||
showHelp( argv[0] );
|
showHelp( config->getProcessName() );
|
||||||
Catch::cleanUp();
|
Catch::cleanUp();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -175,7 +180,7 @@ namespace Catch {
|
|||||||
catch( std::exception& ex ) {
|
catch( std::exception& ex ) {
|
||||||
std::cerr << "\nError in input:\n"
|
std::cerr << "\nError in input:\n"
|
||||||
<< " " << ex.what() << "\n\n";
|
<< " " << ex.what() << "\n\n";
|
||||||
makeCommandLineParser().usage( std::cout, argv[0] );
|
makeCommandLineParser().usage( std::cout, configData.processName );
|
||||||
Catch::cleanUp();
|
Catch::cleanUp();
|
||||||
return (std::numeric_limits<int>::max)();
|
return (std::numeric_limits<int>::max)();
|
||||||
}
|
}
|
||||||
|
@ -122,10 +122,10 @@ namespace Catch {
|
|||||||
bool listTags() const { return m_data.listTags; }
|
bool listTags() const { return m_data.listTags; }
|
||||||
bool listReporters() const { return m_data.listReporters; }
|
bool listReporters() const { return m_data.listReporters; }
|
||||||
|
|
||||||
std::string getName() const {
|
std::string getProcessName() const {
|
||||||
return m_data.name;
|
return m_data.processName;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool shouldDebugBreak() const {
|
bool shouldDebugBreak() const {
|
||||||
return m_data.shouldDebugBreak;
|
return m_data.shouldDebugBreak;
|
||||||
}
|
}
|
||||||
@ -162,7 +162,7 @@ namespace Catch {
|
|||||||
// IConfig interface
|
// IConfig interface
|
||||||
virtual bool allowThrows() const { return !m_data.noThrow; }
|
virtual bool allowThrows() const { return !m_data.noThrow; }
|
||||||
virtual std::ostream& stream() const { return m_os; }
|
virtual std::ostream& stream() const { return m_os; }
|
||||||
virtual std::string name() const { return m_data.name; }
|
virtual std::string name() const { return m_data.name.empty() ? m_data.processName : m_data.name; }
|
||||||
virtual bool includeSuccessfulResults() const { return m_data.showSuccessfulTests; }
|
virtual bool includeSuccessfulResults() const { return m_data.showSuccessfulTests; }
|
||||||
virtual bool warnAboutMissingAssertions() const { return m_data.warnings & ConfigData::WarnAbout::NoAssertions; }
|
virtual bool warnAboutMissingAssertions() const { return m_data.warnings & ConfigData::WarnAbout::NoAssertions; }
|
||||||
|
|
||||||
|
@ -49,14 +49,14 @@ namespace Catch {
|
|||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
class Runner : public IResultCapture, public IRunner {
|
class RunContext : public IResultCapture, public IRunner {
|
||||||
|
|
||||||
Runner( Runner const& );
|
RunContext( RunContext const& );
|
||||||
void operator =( Runner const& );
|
void operator =( RunContext const& );
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
explicit Runner( Ptr<IConfig const> const& config, Ptr<IStreamingReporter> const& reporter )
|
explicit RunContext( Ptr<IConfig const> const& config, Ptr<IStreamingReporter> const& reporter )
|
||||||
: m_runInfo( config->name() ),
|
: m_runInfo( config->name() ),
|
||||||
m_context( getCurrentMutableContext() ),
|
m_context( getCurrentMutableContext() ),
|
||||||
m_runningTest( NULL ),
|
m_runningTest( NULL ),
|
||||||
@ -72,7 +72,7 @@ namespace Catch {
|
|||||||
m_reporter->testRunStarting( m_runInfo );
|
m_reporter->testRunStarting( m_runInfo );
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual ~Runner() {
|
virtual ~RunContext() {
|
||||||
m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) );
|
m_reporter->testRunEnded( TestRunStats( m_runInfo, m_totals, aborting() ) );
|
||||||
m_context.setRunner( m_prevRunner );
|
m_context.setRunner( m_prevRunner );
|
||||||
m_context.setConfig( NULL );
|
m_context.setConfig( NULL );
|
||||||
|
@ -458,7 +458,11 @@ namespace Clara {
|
|||||||
}
|
}
|
||||||
|
|
||||||
std::vector<Parser::Token> parseInto( int argc, char const * const * argv, ConfigT& config ) const {
|
std::vector<Parser::Token> parseInto( int argc, char const * const * argv, ConfigT& config ) const {
|
||||||
m_boundProcessName.set( config, argv[0] );
|
std::string processName = argv[0];
|
||||||
|
std::size_t lastSlash = processName.find_last_of( "/\\" );
|
||||||
|
if( lastSlash != std::string::npos )
|
||||||
|
processName = processName.substr( lastSlash+1 );
|
||||||
|
m_boundProcessName.set( config, processName );
|
||||||
std::vector<Parser::Token> tokens;
|
std::vector<Parser::Token> tokens;
|
||||||
Parser parser;
|
Parser parser;
|
||||||
parser.parseIntoTokens( argc, argv, tokens );
|
parser.parseIntoTokens( argc, argv, tokens );
|
||||||
|
@ -243,7 +243,7 @@ namespace Catch {
|
|||||||
stream << "\n" << getTildes() << "\n";
|
stream << "\n" << getTildes() << "\n";
|
||||||
Colour colour( Colour::SecondaryText );
|
Colour colour( Colour::SecondaryText );
|
||||||
stream << testRunInfo->name
|
stream << testRunInfo->name
|
||||||
<< " is a CATCH v" << libraryVersion.majorVersion << "."
|
<< " is a Catch v" << libraryVersion.majorVersion << "."
|
||||||
<< libraryVersion.minorVersion << " b"
|
<< libraryVersion.minorVersion << " b"
|
||||||
<< libraryVersion.buildNumber;
|
<< libraryVersion.buildNumber;
|
||||||
if( libraryVersion.branchName != "master" )
|
if( libraryVersion.branchName != "master" )
|
||||||
|
@ -20,9 +20,9 @@ namespace Catch{
|
|||||||
|
|
||||||
Totals totals;
|
Totals totals;
|
||||||
|
|
||||||
// Scoped because Runner doesn't report EndTesting until its destructor
|
// Scoped because RunContext doesn't report EndTesting until its destructor
|
||||||
{
|
{
|
||||||
Runner runner( config.get(), m_reporter.get() );
|
RunContext runner( config.get(), m_reporter.get() );
|
||||||
totals = runner.runMatching( rawTestSpec, groupIndex, groupsCount );
|
totals = runner.runMatching( rawTestSpec, groupIndex, groupsCount );
|
||||||
}
|
}
|
||||||
return totals;
|
return totals;
|
||||||
|
Loading…
Reference in New Issue
Block a user