Moved command line lambdas out-of-line in an attempt to fix VS ICEs

This commit is contained in:
Phil Nash 2017-06-21 08:54:34 +01:00
parent d81c1eb006
commit c43d5f673f

View File

@ -19,10 +19,18 @@ namespace Catch {
inline clara::Parser makeCommandLineParser( ConfigData& config ) { inline clara::Parser makeCommandLineParser( ConfigData& config ) {
using namespace clara;
auto const setWarning = [&]( std::string const& warning ) {
if( warning != "NoAssertions" )
return ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" );
config.warnings = static_cast<WarnAbout::What>( config.warnings | WarnAbout::NoAssertions );
return ParserResult::ok( ParseResultType::Matched );
};
auto const loadTestNamesFromFile = [&]( std::string const& filename ) { auto const loadTestNamesFromFile = [&]( std::string const& filename ) {
std::ifstream f( filename.c_str() ); std::ifstream f( filename.c_str() );
if( !f.is_open() ) if( !f.is_open() )
return clara::ParserResult::runtimeError( "Unable to load input file: '" + filename + "'" ); return ParserResult::runtimeError( "Unable to load input file: '" + filename + "'" );
std::string line; std::string line;
while( std::getline( f, line ) ) { while( std::getline( f, line ) ) {
@ -33,11 +41,39 @@ namespace Catch {
config.testsOrTags.push_back( line + ',' ); config.testsOrTags.push_back( line + ',' );
} }
} }
return clara::ParserResult::ok( clara::ParseResultType::Matched ); return ParserResult::ok( ParseResultType::Matched );
};
auto const setTestOrder = [&]( std::string const& order ) {
if( startsWith( "declared", order ) )
config.runOrder = RunTests::InDeclarationOrder;
else if( startsWith( "lexical", order ) )
config.runOrder = RunTests::InLexicographicalOrder;
else if( startsWith( "random", order ) )
config.runOrder = RunTests::InRandomOrder;
else
return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" );
return ParserResult::ok( ParseResultType::Matched );
};
auto const setRngSeed = [&]( std::string const& seed ) {
if( seed != "time" )
return clara::detail::convertInto( seed, config.rngSeed );
config.rngSeed = static_cast<unsigned int>( std::time(0) );
return ParserResult::ok( ParseResultType::Matched );
};
auto const setColourUsage = [&]( std::string const& useColour ) {
auto mode = toLower( useColour );
if( mode == "yes" )
config.useColour = UseColour::Yes;
else if( mode == "no" )
config.useColour = UseColour::No;
else if( mode == "auto" )
config.useColour = UseColour::Auto;
else
return ParserResult::runtimeError( "colour mode must be one of: auto, yes or no. '" + useColour + "' not recognised" );
return ParserResult::ok( ParseResultType::Matched );
}; };
using namespace clara;
auto cli auto cli
= ExeName( config.processName ) = ExeName( config.processName )
+ Help( config.showHelp ) + Help( config.showHelp )
@ -74,12 +110,7 @@ namespace Catch {
+ Opt( [&]( int x ){ config.abortAfter = x; }, "no. failures" ) + Opt( [&]( int x ){ config.abortAfter = x; }, "no. failures" )
["-x"]["--abortx"] ["-x"]["--abortx"]
( "abort after x failures" ) ( "abort after x failures" )
+ Opt( [&]( std::string const& warning ) { + Opt( setWarning, "warning name" )
if( warning != "NoAssertions" )
return clara::ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" );
config.warnings = static_cast<WarnAbout::What>( config.warnings | WarnAbout::NoAssertions );
return clara::ParserResult::ok( ParseResultType::Matched );
}, "warning name" )
["-w"]["--warn"] ["-w"]["--warn"]
( "enable warnings" ) ( "enable warnings" )
+ Opt( [&]( bool ) { config.showDurations = ShowDurations::Always; } ) + Opt( [&]( bool ) { config.showDurations = ShowDurations::Always; } )
@ -100,40 +131,13 @@ namespace Catch {
+ Opt( config.listReporters ) + Opt( config.listReporters )
["--list-reporters"] ["--list-reporters"]
( "list all reporters" ) ( "list all reporters" )
+ Opt( [&]( std::string const& order ) { + Opt( setTestOrder, "decl|lex|rand" )
if( startsWith( "declared", order ) )
config.runOrder = RunTests::InDeclarationOrder;
else if( startsWith( "lexical", order ) )
config.runOrder = RunTests::InLexicographicalOrder;
else if( startsWith( "random", order ) )
config.runOrder = RunTests::InRandomOrder;
else
return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" );
return clara::ParserResult::ok( ParseResultType::Matched );
}, "decl|lex|rand" )
["--order"] ["--order"]
( "test case order (defaults to decl)" ) ( "test case order (defaults to decl)" )
+ Opt( [&]( std::string const& seed ) { + Opt( setRngSeed, "'time'|number" )
if( seed != "time" )
return clara::detail::convertInto( seed, config.rngSeed );
config.rngSeed = static_cast<unsigned int>( std::time(0) );
return clara::ParserResult::ok( ParseResultType::Matched );
}, "'time'|number" )
["--rng-seed"] ["--rng-seed"]
( "set a specific seed for random numbers" ) ( "set a specific seed for random numbers" )
+ Opt( [&]( std::string const& useColour ) { + Opt( setColourUsage, "yes|no" )
auto mode = toLower( useColour );
if( mode == "yes" )
config.useColour = UseColour::Yes;
else if( mode == "no" )
config.useColour = UseColour::No;
else if( mode == "auto" )
config.useColour = UseColour::Auto;
else
return clara::ParserResult::runtimeError( "colour mode must be one of: auto, yes or no. '" + useColour + "' not recognised" );
return clara::ParserResult::ok( ParseResultType::Matched );
}, "yes|no" )
["--use-colour"] ["--use-colour"]
( "should output be colourised" ) ( "should output be colourised" )