| 9634 | namespace Catch { |
| 9635 | |
| 9636 | clara::Parser makeCommandLineParser( ConfigData& config ) { |
| 9637 | |
| 9638 | using namespace clara; |
| 9639 | |
| 9640 | auto const setWarning = [&]( std::string const& warning ) { |
| 9641 | auto warningSet = [&]() { |
| 9642 | if( warning == "NoAssertions" ) |
| 9643 | return WarnAbout::NoAssertions; |
| 9644 | |
| 9645 | if ( warning == "NoTests" ) |
| 9646 | return WarnAbout::NoTests; |
| 9647 | |
| 9648 | return WarnAbout::Nothing; |
| 9649 | }(); |
| 9650 | |
| 9651 | if (warningSet == WarnAbout::Nothing) |
| 9652 | return ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" ); |
| 9653 | config.warnings = static_cast<WarnAbout::What>( config.warnings | warningSet ); |
| 9654 | return ParserResult::ok( ParseResultType::Matched ); |
| 9655 | }; |
| 9656 | auto const loadTestNamesFromFile = [&]( std::string const& filename ) { |
| 9657 | std::ifstream f( filename.c_str() ); |
| 9658 | if( !f.is_open() ) |
| 9659 | return ParserResult::runtimeError( "Unable to load input file: '" + filename + "'" ); |
| 9660 | |
| 9661 | std::string line; |
| 9662 | while( std::getline( f, line ) ) { |
| 9663 | line = trim(line); |
| 9664 | if( !line.empty() && !startsWith( line, '#' ) ) { |
| 9665 | if( !startsWith( line, '"' ) ) |
| 9666 | line = '"' + line + '"'; |
| 9667 | config.testsOrTags.push_back( line ); |
| 9668 | config.testsOrTags.push_back( "," ); |
| 9669 | |
| 9670 | } |
| 9671 | } |
| 9672 | //Remove comma in the end |
| 9673 | if(!config.testsOrTags.empty()) |
| 9674 | config.testsOrTags.erase( config.testsOrTags.end()-1 ); |
| 9675 | |
| 9676 | return ParserResult::ok( ParseResultType::Matched ); |
| 9677 | }; |
| 9678 | auto const setTestOrder = [&]( std::string const& order ) { |
| 9679 | if( startsWith( "declared", order ) ) |
| 9680 | config.runOrder = RunTests::InDeclarationOrder; |
| 9681 | else if( startsWith( "lexical", order ) ) |
| 9682 | config.runOrder = RunTests::InLexicographicalOrder; |
| 9683 | else if( startsWith( "random", order ) ) |
| 9684 | config.runOrder = RunTests::InRandomOrder; |
| 9685 | else |
| 9686 | return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" ); |
| 9687 | return ParserResult::ok( ParseResultType::Matched ); |
| 9688 | }; |
| 9689 | auto const setRngSeed = [&]( std::string const& seed ) { |
| 9690 | if( seed != "time" ) |
| 9691 | return clara::detail::convertInto( seed, config.rngSeed ); |
| 9692 | config.rngSeed = static_cast<unsigned int>( std::time(nullptr) ); |
| 9693 | return ParserResult::ok( ParseResultType::Matched ); |
no test coverage detected