mirror of
https://github.com/catchorg/Catch2.git
synced 2025-06-02 09:57:54 +00:00
Refactor parsing of shard index/count in cmdline handling
This worsens the message for negative numbers a bit, but simplifies the code enough that this is still a win.
This commit is contained in:
parent
f1361ef624
commit
a43f67962e
10 changed files with 65 additions and 76 deletions
|
@ -7,7 +7,6 @@
|
|||
// SPDX-License-Identifier: BSL-1.0
|
||||
#include <catch2/internal/catch_commandline.hpp>
|
||||
|
||||
#include <catch2/internal/catch_compiler_capabilities.hpp>
|
||||
#include <catch2/catch_config.hpp>
|
||||
#include <catch2/internal/catch_string_manip.hpp>
|
||||
#include <catch2/interfaces/catch_interfaces_registry_hub.hpp>
|
||||
|
@ -177,42 +176,29 @@ namespace Catch {
|
|||
return ParserResult::ok( ParseResultType::Matched );
|
||||
};
|
||||
auto const setShardCount = [&]( std::string const& 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");
|
||||
}
|
||||
|
||||
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 parsedCount = parseUInt( shardCount );
|
||||
if ( !parsedCount ) {
|
||||
return ParserResult::runtimeError(
|
||||
"Could not parse '" + shardCount + "' as shard count" );
|
||||
}
|
||||
if ( *parsedCount == 0 ) {
|
||||
return ParserResult::runtimeError(
|
||||
"Shard count must be positive" );
|
||||
}
|
||||
config.shardCount = *parsedCount;
|
||||
return ParserResult::ok( ParseResultType::Matched );
|
||||
};
|
||||
|
||||
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 parsedIndex = parseUInt( shardIndex );
|
||||
if ( !parsedIndex ) {
|
||||
return ParserResult::runtimeError(
|
||||
"Could not parse '" + shardIndex + "' as shard index" );
|
||||
}
|
||||
config.shardIndex = *parsedIndex;
|
||||
return ParserResult::ok( ParseResultType::Matched );
|
||||
};
|
||||
|
||||
|
||||
auto cli
|
||||
= ExeName( config.processName )
|
||||
| Help( config.showHelp )
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue