diff options
| author | Martin Hořeňovský | 2021-10-26 23:26:07 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2021-10-27 17:24:30 +0200 |
| commit | 5ac1ffe9ee394ca6b8ffeee0bd969170c817629e (patch) | |
| tree | 3b595257380e5957c63fdf59b7a2068c651dd4c7 /src/catch2/internal | |
| parent | 3087e19cc72ccb6caddc42ec2f39eebc56160754 (diff) | |
| download | catch3-5ac1ffe9ee394ca6b8ffeee0bd969170c817629e.tar.gz | |
Improve shardIndex/Count cli argument parsing
Diffstat (limited to 'src/catch2/internal')
| -rw-r--r-- | src/catch2/internal/catch_commandline.cpp | 39 |
1 files changed, 33 insertions, 6 deletions
diff --git a/src/catch2/internal/catch_commandline.cpp b/src/catch2/internal/catch_commandline.cpp index 5f8a44d5..6cf71b77 100644 --- a/src/catch2/internal/catch_commandline.cpp +++ b/src/catch2/internal/catch_commandline.cpp @@ -150,15 +150,42 @@ namespace Catch { return ParserResult::ok( ParseResultType::Matched ); }; auto const setShardCount = [&]( std::string const& shardCount ) { - auto result = Clara::Detail::convertInto( shardCount, config.shardCount ); + CATCH_TRY{ + std::size_t parsedTo = 0; + int64_t parsedCount = std::stoll(shardCount, &parsedTo, 0); + if (parsedTo != shardCount.size()) { + return ParserResult::runtimeError("Could not parse '" + shardCount + "' as shard count"); + } + if (parsedCount <= 0) { + return ParserResult::runtimeError("Shard count must be a positive number"); + } - if (config.shardCount == 0) { - return ParserResult::runtimeError( "The shard count must be greater than 0" ); - } else { - return result; + config.shardCount = static_cast<unsigned int>(parsedCount); + return ParserResult::ok(ParseResultType::Matched); + } CATCH_CATCH_ANON(std::exception const&) { + return ParserResult::runtimeError("Could not parse '" + shardCount + "' as shard count"); } }; + auto const setShardIndex = [&](std::string const& shardIndex) { + CATCH_TRY{ + std::size_t parsedTo = 0; + int64_t parsedIndex = std::stoll(shardIndex, &parsedTo, 0); + if (parsedTo != shardIndex.size()) { + return ParserResult::runtimeError("Could not parse '" + shardIndex + "' as shard index"); + } + if (parsedIndex < 0) { + return ParserResult::runtimeError("Shard index must be a non-negative number"); + } + + config.shardIndex = static_cast<unsigned int>(parsedIndex); + return ParserResult::ok(ParseResultType::Matched); + } CATCH_CATCH_ANON(std::exception const&) { + return ParserResult::runtimeError("Could not parse '" + shardIndex + "' as shard index"); + } + }; + + auto cli = ExeName( config.processName ) | Help( config.showHelp ) @@ -252,7 +279,7 @@ namespace Catch { | Opt( setShardCount, "shard count" ) ["--shard-count"] ( "split the tests to execute into this many groups" ) - | Opt( config.shardIndex, "shard index" ) + | Opt( setShardIndex, "shard index" ) ["--shard-index"] ( "index of the group of tests to execute (see --shard-count)" ) | Arg( config.testsOrTags, "test name|pattern|tags" ) |