| 3244 | namespace Catch { |
| 3245 | |
| 3246 | Clara::Parser makeCommandLineParser( ConfigData& config ) { |
| 3247 | |
| 3248 | using namespace Clara; |
| 3249 | |
| 3250 | auto const setWarning = [&]( std::string const& warning ) { |
| 3251 | if ( warning == "NoAssertions" ) { |
| 3252 | config.warnings = static_cast<WarnAbout::What>(config.warnings | WarnAbout::NoAssertions); |
| 3253 | return ParserResult::ok( ParseResultType::Matched ); |
| 3254 | } else if ( warning == "UnmatchedTestSpec" ) { |
| 3255 | config.warnings = static_cast<WarnAbout::What>(config.warnings | WarnAbout::UnmatchedTestSpec); |
| 3256 | return ParserResult::ok( ParseResultType::Matched ); |
| 3257 | } else if ( warning == "InfiniteGenerators" ) { |
| 3258 | config.warnings = static_cast<WarnAbout::What>(config.warnings | WarnAbout::InfiniteGenerator); |
| 3259 | return ParserResult::ok( ParseResultType::Matched ); |
| 3260 | } |
| 3261 | |
| 3262 | return ParserResult ::runtimeError( |
| 3263 | "Unrecognised warning option: '" + warning + '\'' ); |
| 3264 | }; |
| 3265 | auto const loadTestNamesFromFile = [&]( std::string const& filename ) { |
| 3266 | std::ifstream f( filename.c_str() ); |
| 3267 | if( !f.is_open() ) |
| 3268 | return ParserResult::runtimeError( "Unable to load input file: '" + filename + '\'' ); |
| 3269 | |
| 3270 | std::string line; |
| 3271 | while( std::getline( f, line ) ) { |
| 3272 | line = trim(line); |
| 3273 | if( !line.empty() && !startsWith( line, '#' ) ) { |
| 3274 | if( !startsWith( line, '"' ) ) |
| 3275 | line = '"' + CATCH_MOVE(line) + '"'; |
| 3276 | config.testsOrTags.push_back( line ); |
| 3277 | config.testsOrTags.emplace_back( "," ); |
| 3278 | } |
| 3279 | } |
| 3280 | //Remove comma in the end |
| 3281 | if(!config.testsOrTags.empty()) |
| 3282 | config.testsOrTags.erase( config.testsOrTags.end()-1 ); |
| 3283 | |
| 3284 | return ParserResult::ok( ParseResultType::Matched ); |
| 3285 | }; |
| 3286 | auto const setTestOrder = [&]( std::string const& order ) { |
| 3287 | if( startsWith( "declared", order ) ) |
| 3288 | config.runOrder = TestRunOrder::Declared; |
| 3289 | else if( startsWith( "lexical", order ) ) |
| 3290 | config.runOrder = TestRunOrder::LexicographicallySorted; |
| 3291 | else if( startsWith( "random", order ) ) |
| 3292 | config.runOrder = TestRunOrder::Randomized; |
| 3293 | else |
| 3294 | return ParserResult::runtimeError( "Unrecognised ordering: '" + order + '\'' ); |
| 3295 | return ParserResult::ok( ParseResultType::Matched ); |
| 3296 | }; |
| 3297 | auto const setRngSeed = [&]( std::string const& seed ) { |
| 3298 | if( seed == "time" ) { |
| 3299 | config.rngSeed = generateRandomSeed(GenerateFrom::Time); |
| 3300 | return ParserResult::ok(ParseResultType::Matched); |
| 3301 | } else if (seed == "random-device") { |
| 3302 | config.rngSeed = generateRandomSeed(GenerateFrom::RandomDevice); |
| 3303 | return ParserResult::ok(ParseResultType::Matched); |
no test coverage detected