MCPcopy Create free account
hub / github.com/catchorg/Catch2 / makeCommandLineParser

Function makeCommandLineParser

src/catch2/internal/catch_commandline.cpp:24–374  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22namespace Catch {
23
24 Clara::Parser makeCommandLineParser( ConfigData& config ) {
25
26 using namespace Clara;
27
28 auto const setWarning = [&]( std::string const& warning ) {
29 if ( warning == "NoAssertions" ) {
30 config.warnings = static_cast<WarnAbout::What>(config.warnings | WarnAbout::NoAssertions);
31 return ParserResult::ok( ParseResultType::Matched );
32 } else if ( warning == "UnmatchedTestSpec" ) {
33 config.warnings = static_cast<WarnAbout::What>(config.warnings | WarnAbout::UnmatchedTestSpec);
34 return ParserResult::ok( ParseResultType::Matched );
35 } else if ( warning == "InfiniteGenerators" ) {
36 config.warnings = static_cast<WarnAbout::What>(config.warnings | WarnAbout::InfiniteGenerator);
37 return ParserResult::ok( ParseResultType::Matched );
38 }
39
40 return ParserResult ::runtimeError(
41 "Unrecognised warning option: '" + warning + '\'' );
42 };
43 auto const loadTestNamesFromFile = [&]( std::string const& filename ) {
44 std::ifstream f( filename.c_str() );
45 if( !f.is_open() )
46 return ParserResult::runtimeError( "Unable to load input file: '" + filename + '\'' );
47
48 std::string line;
49 while( std::getline( f, line ) ) {
50 line = trim(line);
51 if( !line.empty() && !startsWith( line, '#' ) ) {
52 if( !startsWith( line, '"' ) )
53 line = '"' + CATCH_MOVE(line) + '"';
54 config.testsOrTags.push_back( line );
55 config.testsOrTags.emplace_back( "," );
56 }
57 }
58 //Remove comma in the end
59 if(!config.testsOrTags.empty())
60 config.testsOrTags.erase( config.testsOrTags.end()-1 );
61
62 return ParserResult::ok( ParseResultType::Matched );
63 };
64 auto const setTestOrder = [&]( std::string const& order ) {
65 if( startsWith( "declared", order ) )
66 config.runOrder = TestRunOrder::Declared;
67 else if( startsWith( "lexical", order ) )
68 config.runOrder = TestRunOrder::LexicographicallySorted;
69 else if( startsWith( "random", order ) )
70 config.runOrder = TestRunOrder::Randomized;
71 else
72 return ParserResult::runtimeError( "Unrecognised ordering: '" + order + '\'' );
73 return ParserResult::ok( ParseResultType::Matched );
74 };
75 auto const setRngSeed = [&]( std::string const& seed ) {
76 if( seed == "time" ) {
77 config.rngSeed = generateRandomSeed(GenerateFrom::Time);
78 return ParserResult::ok(ParseResultType::Matched);
79 } else if (seed == "random-device") {
80 config.rngSeed = generateRandomSeed(GenerateFrom::RandomDevice);
81 return ParserResult::ok(ParseResultType::Matched);

Callers 1

catch_session.cppFile · 0.50

Calls 15

trimFunction · 0.70
startsWithFunction · 0.70
generateRandomSeedFunction · 0.70
parseUIntFunction · 0.70
stringToColourModeFunction · 0.70
toLowerFunction · 0.70
isColourImplAvailableFunction · 0.70
parseReporterSpecFunction · 0.70
ExeNameClass · 0.70
HelpClass · 0.70
OptClass · 0.70
ArgClass · 0.70

Tested by

no test coverage detected