| 9721 | namespace Catch { |
| 9722 | |
| 9723 | clara::Parser makeCommandLineParser( ConfigData& config ) { |
| 9724 | |
| 9725 | using namespace clara; |
| 9726 | |
| 9727 | auto const setWarning = [&]( std::string const& warning ) { |
| 9728 | auto warningSet = [&]() { |
| 9729 | if( warning == "NoAssertions" ) |
| 9730 | return WarnAbout::NoAssertions; |
| 9731 | |
| 9732 | if ( warning == "NoTests" ) |
| 9733 | return WarnAbout::NoTests; |
| 9734 | |
| 9735 | return WarnAbout::Nothing; |
| 9736 | }(); |
| 9737 | |
| 9738 | if (warningSet == WarnAbout::Nothing) |
| 9739 | return ParserResult::runtimeError( "Unrecognised warning: '" + warning + "'" ); |
| 9740 | config.warnings = static_cast<WarnAbout::What>( config.warnings | warningSet ); |
| 9741 | return ParserResult::ok( ParseResultType::Matched ); |
| 9742 | }; |
| 9743 | auto const loadTestNamesFromFile = [&]( std::string const& filename ) { |
| 9744 | std::ifstream f( filename.c_str() ); |
| 9745 | if( !f.is_open() ) |
| 9746 | return ParserResult::runtimeError( "Unable to load input file: '" + filename + "'" ); |
| 9747 | |
| 9748 | std::string line; |
| 9749 | while( std::getline( f, line ) ) { |
| 9750 | line = trim(line); |
| 9751 | if( !line.empty() && !startsWith( line, '#' ) ) { |
| 9752 | if( !startsWith( line, '"' ) ) |
| 9753 | line = '"' + line + '"'; |
| 9754 | config.testsOrTags.push_back( line ); |
| 9755 | config.testsOrTags.emplace_back( "," ); |
| 9756 | } |
| 9757 | } |
| 9758 | //Remove comma in the end |
| 9759 | if(!config.testsOrTags.empty()) |
| 9760 | config.testsOrTags.erase( config.testsOrTags.end()-1 ); |
| 9761 | |
| 9762 | return ParserResult::ok( ParseResultType::Matched ); |
| 9763 | }; |
| 9764 | auto const setTestOrder = [&]( std::string const& order ) { |
| 9765 | if( startsWith( "declared", order ) ) |
| 9766 | config.runOrder = RunTests::InDeclarationOrder; |
| 9767 | else if( startsWith( "lexical", order ) ) |
| 9768 | config.runOrder = RunTests::InLexicographicalOrder; |
| 9769 | else if( startsWith( "random", order ) ) |
| 9770 | config.runOrder = RunTests::InRandomOrder; |
| 9771 | else |
| 9772 | return clara::ParserResult::runtimeError( "Unrecognised ordering: '" + order + "'" ); |
| 9773 | return ParserResult::ok( ParseResultType::Matched ); |
| 9774 | }; |
| 9775 | auto const setRngSeed = [&]( std::string const& seed ) { |
| 9776 | if( seed != "time" ) |
| 9777 | return clara::detail::convertInto( seed, config.rngSeed ); |
| 9778 | config.rngSeed = static_cast<unsigned int>( std::time(nullptr) ); |
| 9779 | return ParserResult::ok( ParseResultType::Matched ); |
| 9780 | }; |
no test coverage detected