MCPcopy Create free account
hub / github.com/InteractiveComputerGraphics/SPlisHSPlasH / makeCommandLineParser

Function makeCommandLineParser

extern/Catch2/catch.hpp:9702–9909  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

9700namespace Catch {
9701
9702 clara::Parser makeCommandLineParser( ConfigData& config ) {
9703
9704 using namespace clara;
9705
9706 auto const setWarning = [&]( std::string const& warning ) {
9707 auto warningSet = [&]() {
9708 if( warning == "NoAssertions" )
9709 return WarnAbout::NoAssertions;
9710
9711 if ( warning == "NoTests" )
9712 return WarnAbout::NoTests;
9713
9714 return WarnAbout::Nothing;
9715 }();
9716
9717 if (warningSet == WarnAbout::Nothing)
9718 return ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" );
9719 config.warnings = static_cast<WarnAbout::What>( config.warnings | warningSet );
9720 return ParserResult::ok( ParseResultType::Matched );
9721 };
9722 auto const loadTestNamesFromFile = [&]( std::string const& filename ) {
9723 std::ifstream f( filename.c_str() );
9724 if( !f.is_open() )
9725 return ParserResult::runtimeError( "Unable to load input file: '" + filename + "'" );
9726
9727 std::string line;
9728 while( std::getline( f, line ) ) {
9729 line = trim(line);
9730 if( !line.empty() && !startsWith( line, '#' ) ) {
9731 if( !startsWith( line, '"' ) )
9732 line = '"' + line + '"';
9733 config.testsOrTags.push_back( line );
9734 config.testsOrTags.emplace_back( "," );
9735 }
9736 }
9737 //Remove comma in the end
9738 if(!config.testsOrTags.empty())
9739 config.testsOrTags.erase( config.testsOrTags.end()-1 );
9740
9741 return ParserResult::ok( ParseResultType::Matched );
9742 };
9743 auto const setTestOrder = [&]( std::string const& order ) {
9744 if( startsWith( "declared", order ) )
9745 config.runOrder = RunTests::InDeclarationOrder;
9746 else if( startsWith( "lexical", order ) )
9747 config.runOrder = RunTests::InLexicographicalOrder;
9748 else if( startsWith( "random", order ) )
9749 config.runOrder = RunTests::InRandomOrder;
9750 else
9751 return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" );
9752 return ParserResult::ok( ParseResultType::Matched );
9753 };
9754 auto const setRngSeed = [&]( std::string const& seed ) {
9755 if( seed != "time" )
9756 return clara::detail::convertInto( seed, config.rngSeed );
9757 config.rngSeed = static_cast<unsigned int>( std::time(nullptr) );
9758 return ParserResult::ok( ParseResultType::Matched );
9759 };

Callers 1

catch.hppFile · 0.85

Calls 13

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

Tested by

no test coverage detected