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