MCPcopy Create free account
hub / github.com/Profactor/cv-plot / makeCommandLineParser

Function makeCommandLineParser

CvPlot/ext/catch2/inc/catch.hpp:9618–9818  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9616namespace Catch {
9617
9618 clara::Parser makeCommandLineParser( ConfigData& config ) {
9619
9620 using namespace clara;
9621
9622 auto const setWarning = [&]( std::string const& warning ) {
9623 auto warningSet = [&]() {
9624 if( warning == "NoAssertions" )
9625 return WarnAbout::NoAssertions;
9626
9627 if ( warning == "NoTests" )
9628 return WarnAbout::NoTests;
9629
9630 return WarnAbout::Nothing;
9631 }();
9632
9633 if (warningSet == WarnAbout::Nothing)
9634 return ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" );
9635 config.warnings = static_cast<WarnAbout::What>( config.warnings | warningSet );
9636 return ParserResult::ok( ParseResultType::Matched );
9637 };
9638 auto const loadTestNamesFromFile = [&]( std::string const& filename ) {
9639 std::ifstream f( filename.c_str() );
9640 if( !f.is_open() )
9641 return ParserResult::runtimeError( "Unable to load input file: '" + filename + "'" );
9642
9643 std::string line;
9644 while( std::getline( f, line ) ) {
9645 line = trim(line);
9646 if( !line.empty() && !startsWith( line, '#' ) ) {
9647 if( !startsWith( line, '"' ) )
9648 line = '"' + line + '"';
9649 config.testsOrTags.push_back( line );
9650 config.testsOrTags.push_back( "," );
9651
9652 }
9653 }
9654 //Remove comma in the end
9655 if(!config.testsOrTags.empty())
9656 config.testsOrTags.erase( config.testsOrTags.end()-1 );
9657
9658 return ParserResult::ok( ParseResultType::Matched );
9659 };
9660 auto const setTestOrder = [&]( std::string const& order ) {
9661 if( startsWith( "declared", order ) )
9662 config.runOrder = RunTests::InDeclarationOrder;
9663 else if( startsWith( "lexical", order ) )
9664 config.runOrder = RunTests::InLexicographicalOrder;
9665 else if( startsWith( "random", order ) )
9666 config.runOrder = RunTests::InRandomOrder;
9667 else
9668 return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" );
9669 return ParserResult::ok( ParseResultType::Matched );
9670 };
9671 auto const setRngSeed = [&]( std::string const& seed ) {
9672 if( seed != "time" )
9673 return clara::detail::convertInto( seed, config.rngSeed );
9674 config.rngSeed = static_cast<unsigned int>( std::time(nullptr) );
9675 return ParserResult::ok( ParseResultType::Matched );

Callers 1

catch.hppFile · 0.85

Calls 12

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.80
emptyMethod · 0.45
endMethod · 0.45
findMethod · 0.45

Tested by

no test coverage detected