mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-22 21:36:11 +01:00
Added processConfig() method
This commit is contained in:
parent
2ed56c47a6
commit
1b47e11387
@ -131,7 +131,8 @@ namespace Catch {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void showHelp( Clara::CommandLine<ConfigData> const& cli, std::string const& processName ) {
|
inline void showHelp( std::string const& processName ) {
|
||||||
|
Clara::CommandLine<ConfigData> cli = makeCommandLineParser();
|
||||||
|
|
||||||
std::cout << "\nCatch v" << libraryVersion.majorVersion << "."
|
std::cout << "\nCatch v" << libraryVersion.majorVersion << "."
|
||||||
<< libraryVersion.minorVersion << " build "
|
<< libraryVersion.minorVersion << " build "
|
||||||
@ -143,16 +144,30 @@ 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() ) {
|
||||||
|
Clara::CommandLine<ConfigData> cli = makeCommandLineParser();
|
||||||
|
std::vector<Clara::Parser::Token> unused = cli.parseInto( argc, argv, configData );
|
||||||
|
if( !unused.empty() ) {
|
||||||
|
std::vector<Clara::Parser::Token>::const_iterator
|
||||||
|
it = unused.begin(),
|
||||||
|
itEnd = unused.end();
|
||||||
|
std::string msg;
|
||||||
|
for(; it != itEnd; ++it )
|
||||||
|
msg += " unrecognised option: " + it->data + "\n";
|
||||||
|
throw std::runtime_error( msg.substr( 0, msg.size()-1 ) );
|
||||||
|
}
|
||||||
|
Ptr<Config> config = new Config( configData );
|
||||||
|
return config;
|
||||||
|
}
|
||||||
|
|
||||||
inline int Main( int argc, char* const argv[], ConfigData configData = ConfigData() ) {
|
inline int Main( int argc, char* const argv[], ConfigData configData = ConfigData() ) {
|
||||||
|
|
||||||
Clara::CommandLine<ConfigData> cli = makeCommandLineParser();
|
Ptr<Config> config;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
cli.parseInto( argc, argv, configData );
|
config = processConfig( argc, argv, configData );
|
||||||
|
if( config->showHelp() ) {
|
||||||
if( configData.showHelp ) {
|
showHelp( argv[0] );
|
||||||
showHelp( cli, argv[0] );
|
|
||||||
Catch::cleanUp();
|
Catch::cleanUp();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -160,11 +175,10 @@ 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";
|
||||||
cli.usage( std::cout, argv[0] );
|
makeCommandLineParser().usage( std::cout, argv[0] );
|
||||||
Catch::cleanUp();
|
Catch::cleanUp();
|
||||||
return (std::numeric_limits<int>::max)();
|
return (std::numeric_limits<int>::max)();
|
||||||
}
|
}
|
||||||
Ptr<Config> config = new Config( configData );
|
|
||||||
return Main( config );
|
return Main( config );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -156,6 +156,8 @@ namespace Catch {
|
|||||||
std::vector<TestCaseFilters> const& filters() const {
|
std::vector<TestCaseFilters> const& filters() const {
|
||||||
return m_filterSets;
|
return m_filterSets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool showHelp() const { return m_data.showHelp; }
|
||||||
|
|
||||||
// IConfig interface
|
// IConfig interface
|
||||||
virtual bool allowThrows() const { return !m_data.noThrow; }
|
virtual bool allowThrows() const { return !m_data.noThrow; }
|
||||||
|
Loading…
Reference in New Issue
Block a user