MCPcopy Create free account
hub / github.com/ChaiScript/ChaiScript / makeCommandLineParser

Function makeCommandLineParser

unittests/catch.hpp:6480–6654  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

6478namespace Catch {
6479
6480 clara::Parser makeCommandLineParser( ConfigData& config ) {
6481
6482 using namespace clara;
6483
6484 auto const setWarning = [&]( std::string const& warning ) {
6485 auto warningSet = [&]() {
6486 if( warning == "NoAssertions" )
6487 return WarnAbout::NoAssertions;
6488
6489 if ( warning == "NoTests" )
6490 return WarnAbout::NoTests;
6491
6492 return WarnAbout::Nothing;
6493 }();
6494
6495 if (warningSet == WarnAbout::Nothing)
6496 return ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" );
6497 config.warnings = static_cast<WarnAbout::What>( config.warnings | warningSet );
6498 return ParserResult::ok( ParseResultType::Matched );
6499 };
6500 auto const loadTestNamesFromFile = [&]( std::string const& filename ) {
6501 std::ifstream f( filename.c_str() );
6502 if( !f.is_open() )
6503 return ParserResult::runtimeError( "Unable to load input file: '" + filename + "'" );
6504
6505 std::string line;
6506 while( std::getline( f, line ) ) {
6507 line = trim(line);
6508 if( !line.empty() && !startsWith( line, '#' ) ) {
6509 if( !startsWith( line, '"' ) )
6510 line = '"' + line + '"';
6511 config.testsOrTags.push_back( line + ',' );
6512 }
6513 }
6514 return ParserResult::ok( ParseResultType::Matched );
6515 };
6516 auto const setTestOrder = [&]( std::string const& order ) {
6517 if( startsWith( "declared", order ) )
6518 config.runOrder = RunTests::InDeclarationOrder;
6519 else if( startsWith( "lexical", order ) )
6520 config.runOrder = RunTests::InLexicographicalOrder;
6521 else if( startsWith( "random", order ) )
6522 config.runOrder = RunTests::InRandomOrder;
6523 else
6524 return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" );
6525 return ParserResult::ok( ParseResultType::Matched );
6526 };
6527 auto const setRngSeed = [&]( std::string const& seed ) {
6528 if( seed != "time" )
6529 return clara::detail::convertInto( seed, config.rngSeed );
6530 config.rngSeed = static_cast<unsigned int>( std::time(nullptr) );
6531 return ParserResult::ok( ParseResultType::Matched );
6532 };
6533 auto const setColourUsage = [&]( std::string const& useColour ) {
6534 auto mode = toLower( useColour );
6535
6536 if( mode == "yes" )
6537 config.useColour = UseColour::Yes;

Callers 1

SessionMethod · 0.85

Calls 10

trimFunction · 0.85
startsWithFunction · 0.85
convertIntoFunction · 0.85
toLowerFunction · 0.85
ExeNameClass · 0.85
HelpClass · 0.85
OptClass · 0.85
ArgClass · 0.85
c_strMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected