mirror of
https://github.com/catchorg/Catch2.git
synced 2024-11-26 07:16:10 +01:00
Got parseCommandLine ready to use new Clara (but not doing so yet)
This commit is contained in:
parent
f330fe7ef9
commit
0514fe4f38
@ -166,7 +166,7 @@ namespace Catch {
|
||||
showUsage( std::cout );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline int Main( int argc, char* const argv[], ConfigData configData = ConfigData() ) {
|
||||
|
||||
try {
|
||||
@ -181,9 +181,7 @@ namespace Catch {
|
||||
return 0;
|
||||
}
|
||||
|
||||
AllOptions options;
|
||||
|
||||
options.parseIntoConfig( parser, configData );
|
||||
parseCommandLine( argc, argv, configData );
|
||||
}
|
||||
catch( std::exception& ex ) {
|
||||
std::cerr << ex.what() << "\n\nUsage: ...\n\n";
|
||||
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "catch_config.hpp"
|
||||
#include "catch_common.h"
|
||||
#include "clara.h"
|
||||
|
||||
namespace Catch {
|
||||
|
||||
@ -341,6 +342,9 @@ namespace Catch {
|
||||
else
|
||||
cmd.raiseError( "Expected tests, reporters or tags" );
|
||||
}
|
||||
else {
|
||||
config.listTests = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -649,6 +653,114 @@ namespace Catch {
|
||||
Parsers m_parsers;
|
||||
|
||||
};
|
||||
|
||||
inline void abortAfterFirst( ConfigData& config ) { config.abortAfter = 1; }
|
||||
inline void abortAfterX( ConfigData& config, int x ) { config.abortAfter = x; }
|
||||
inline void addTestOrTags( ConfigData& config, std::string const& _testSpec ) { config.testsOrTags.push_back( _testSpec ); }
|
||||
|
||||
inline void addWarning( ConfigData& config, std::string const& _warning ) {
|
||||
if( _warning == "NoAssertions" )
|
||||
config.warnings = (ConfigData::WarnAbout::What)( config.warnings | ConfigData::WarnAbout::NoAssertions );
|
||||
else
|
||||
throw std::runtime_error( "Unrecognised warning: '" + _warning + "'" );
|
||||
|
||||
}
|
||||
inline void setVerbosity( ConfigData& config, int level ) {
|
||||
// !TBD: accept strings?
|
||||
config.verbosity = (ConfigData::Verbosity::Level)level;
|
||||
}
|
||||
|
||||
inline void parseCommandLine( int argc, char* const argv[], ConfigData& config ) {
|
||||
|
||||
Clara::CommandLine<ConfigData> cli;
|
||||
|
||||
cli.bind( &ConfigData::showHelp )
|
||||
.describe( "display usage information" )
|
||||
.shortOpt( "?")
|
||||
.shortOpt( "h")
|
||||
.longOpt( "help" );
|
||||
|
||||
cli.bind( &ConfigData::listTests )
|
||||
.describe( "list all (or matching) test cases" )
|
||||
.shortOpt( "l")
|
||||
.longOpt( "list-tests" );
|
||||
|
||||
cli.bind( &ConfigData::listTags )
|
||||
.describe( "list all (or matching) tags" )
|
||||
.shortOpt( "t")
|
||||
.longOpt( "list-tags" );
|
||||
|
||||
cli.bind( &ConfigData::listTags )
|
||||
.describe( "list all reporters" )
|
||||
.longOpt( "list-reporters" );
|
||||
|
||||
cli.bind( &ConfigData::showSuccessfulTests )
|
||||
.describe( "include successful tests in output" )
|
||||
.shortOpt( "s")
|
||||
.longOpt( "success" );
|
||||
|
||||
cli.bind( &ConfigData::shouldDebugBreak )
|
||||
.describe( "break into debugger on failure" )
|
||||
.shortOpt( "b")
|
||||
.longOpt( "break" );
|
||||
|
||||
cli.bind( &ConfigData::noThrow )
|
||||
.describe( "Skip exception tests" )
|
||||
.shortOpt( "e")
|
||||
.longOpt( "nothrow" );
|
||||
|
||||
cli.bind( &ConfigData::outputFilename )
|
||||
.describe( "output filename" )
|
||||
.shortOpt( "o")
|
||||
.longOpt( "out" )
|
||||
.argName( "filename" );
|
||||
|
||||
cli.bind( &ConfigData::reporterName )
|
||||
.describe( "reporter to use - defaults to console" )
|
||||
.shortOpt( "r")
|
||||
.longOpt( "reporter" )
|
||||
.argName( "name[:filename]" );
|
||||
|
||||
cli.bind( &ConfigData::name )
|
||||
.describe( "suite name" )
|
||||
.shortOpt( "n")
|
||||
.longOpt( "name" )
|
||||
.argName( "name" );
|
||||
|
||||
cli.bind( &abortAfterFirst )
|
||||
.describe( "abort at first failure" )
|
||||
.shortOpt( "a")
|
||||
.longOpt( "abort" );
|
||||
|
||||
cli.bind( &abortAfterX )
|
||||
.describe( "abort after x failures" )
|
||||
.shortOpt( "x")
|
||||
.longOpt( "abortx" )
|
||||
.argName( "number of failures" );
|
||||
|
||||
cli.bind( &addWarning )
|
||||
.describe( "enable warnings" )
|
||||
.shortOpt( "w")
|
||||
.longOpt( "warn" )
|
||||
.argName( "warning name" );
|
||||
|
||||
cli.bind( &setVerbosity )
|
||||
.describe( "level of verbosity (0=no output)" )
|
||||
.shortOpt( "v")
|
||||
.longOpt( "verbosity" )
|
||||
.argName( "level" );
|
||||
|
||||
cli.bind( &addTestOrTags )
|
||||
.describe( "which test or tests to use" )
|
||||
.argName( "test name, pattern or tags" );
|
||||
|
||||
// cli.parseInto( argc, argv, config );
|
||||
|
||||
// Legacy way
|
||||
CommandParser parser( argc, argv );
|
||||
AllOptions options;
|
||||
options.parseIntoConfig( parser, config );
|
||||
}
|
||||
|
||||
} // end namespace Catch
|
||||
|
||||
|
@ -197,7 +197,7 @@ namespace Clara {
|
||||
std::string data;
|
||||
};
|
||||
|
||||
void parseIntoTokens( int argc, char const* argv[], std::vector<Parser::Token>& tokens ) const {
|
||||
void parseIntoTokens( int argc, char const * const * argv, std::vector<Parser::Token>& tokens ) const {
|
||||
for( int i = 1; i < argc; ++i )
|
||||
parseIntoTokens( argv[i] , tokens);
|
||||
}
|
||||
@ -434,7 +434,7 @@ namespace Clara {
|
||||
return oss.str();
|
||||
}
|
||||
|
||||
std::vector<Parser::Token> parseInto( int argc, char const* argv[], ConfigT& config ) const {
|
||||
std::vector<Parser::Token> parseInto( int argc, char const * const * argv, ConfigT& config ) const {
|
||||
std::vector<Parser::Token> tokens;
|
||||
Parser parser;
|
||||
parser.parseIntoTokens( argc, argv, tokens );
|
||||
|
@ -16,7 +16,7 @@
|
||||
|
||||
// Helper to deduce size from array literals and pass on to parser
|
||||
template<size_t size, typename ConfigT>
|
||||
std::vector<Clara::Parser::Token> parseInto( Clara::CommandLine<ConfigT>& cli, char const* (&argv)[size], ConfigT& config ) {
|
||||
std::vector<Clara::Parser::Token> parseInto( Clara::CommandLine<ConfigT>& cli, char const * (&argv)[size], ConfigT& config ) {
|
||||
return cli.parseInto( size, argv, config );
|
||||
}
|
||||
|
||||
@ -56,7 +56,7 @@ TEST_CASE( "cmdline" ) {
|
||||
.argName( "filename" );
|
||||
|
||||
SECTION( "arg separated by spaces" ) {
|
||||
const char* argv[] = { "test", "-o filename.ext" };
|
||||
char const * argv[] = { "test", "-o filename.ext" };
|
||||
parseInto( cli, argv, config );
|
||||
|
||||
CHECK( config.fileName == "filename.ext" );
|
||||
|
Loading…
Reference in New Issue
Block a user