Split Main impl into layered functions to offer more customisation points

This commit is contained in:
Phil Nash 2011-03-21 12:21:25 +00:00
parent 18553e09fd
commit 0571f797c0
1 changed files with 57 additions and 32 deletions

View File

@ -27,38 +27,12 @@
namespace Catch namespace Catch
{ {
inline int Main( int argc, char * const argv[] ) //////////////////////////////////////////////////////////////////////////
{ inline int Main
Config config; (
ArgParser( argc, argv, config ); Config& config
)
if( !config.getMessage().empty() ) {
{
std::cerr << config.getMessage() << std::endl;
return (std::numeric_limits<int>::max)();
}
// Handle help
if( config.showHelp() )
{
std::string exeName( argv[0] );
std::string::size_type pos = exeName.find_last_of( "/\\" );
if( pos != std::string::npos )
{
exeName = exeName.substr( pos+1 );
}
std::cout << exeName << " is a CATCH host application. Options are as follows:\n\n"
<< "\t-l, --list <tests | reporters> [xml]\n"
<< "\t-t, --test <testspec> [<testspec>...]\n"
<< "\t-r, --reporter <reporter name>\n"
<< "\t-o, --out <file name>|<%stream name>\n"
<< "\t-s, --success\n"
<< "\t-b, --break\n\n"
<< "For more detail usage please see: https://github.com/philsquared/Catch/wiki/Command-line" << std::endl;
return 0;
}
// Handle list request // Handle list request
if( config.listWhat() != Config::List::None ) if( config.listWhat() != Config::List::None )
return List( config ); return List( config );
@ -107,6 +81,57 @@ namespace Catch
return static_cast<int>( runner.getFailureCount() ); return static_cast<int>( runner.getFailureCount() );
} }
//////////////////////////////////////////////////////////////////////////
inline int Main
(
int argc,
char* const argv[],
Config& config
)
{
ArgParser( argc, argv, config );
if( !config.getMessage().empty() )
{
std::cerr << config.getMessage() << std::endl;
return (std::numeric_limits<int>::max)();
}
// Handle help
if( config.showHelp() )
{
std::string exeName( argv[0] );
std::string::size_type pos = exeName.find_last_of( "/\\" );
if( pos != std::string::npos )
{
exeName = exeName.substr( pos+1 );
}
std::cout << exeName << " is a CATCH host application. Options are as follows:\n\n"
<< "\t-l, --list <tests | reporters> [xml]\n"
<< "\t-t, --test <testspec> [<testspec>...]\n"
<< "\t-r, --reporter <reporter name>\n"
<< "\t-o, --out <file name>|<%stream name>\n"
<< "\t-s, --success\n"
<< "\t-b, --break\n\n"
<< "For more detail usage please see: https://github.com/philsquared/Catch/wiki/Command-line" << std::endl;
return 0;
}
return Main( config );
}
//////////////////////////////////////////////////////////////////////////
inline int Main
(
int argc,
char* const argv[]
)
{
Config config;
return Main( argc, argv, config );
}
} // end namespace Catch } // end namespace Catch
#endif // TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED #endif // TWOBLUECUBES_CATCH_RUNNER_HPP_INCLUDED