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