diff options
| author | Martin Hořeňovský | 2022-10-22 17:04:08 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2022-10-22 22:18:30 +0200 |
| commit | f1361ef6243ec88038a6b4f013c405f2df3df376 (patch) | |
| tree | 913fa278cdc2d68dd4527468e2b6f0931dc205e5 /src/catch2/internal/catch_commandline.cpp | |
| parent | d1e7544e9f8b233af8ffd37df9bee12492215aff (diff) | |
| download | catch3-f1361ef6243ec88038a6b4f013c405f2df3df376.tar.gz | |
Refactor how the RNG seed is parsed when handling cmdline
Diffstat (limited to 'src/catch2/internal/catch_commandline.cpp')
| -rw-r--r-- | src/catch2/internal/catch_commandline.cpp | 24 |
1 files changed, 8 insertions, 16 deletions
diff --git a/src/catch2/internal/catch_commandline.cpp b/src/catch2/internal/catch_commandline.cpp index fda4b2bd..20bb07f7 100644 --- a/src/catch2/internal/catch_commandline.cpp +++ b/src/catch2/internal/catch_commandline.cpp @@ -13,6 +13,7 @@ #include <catch2/interfaces/catch_interfaces_registry_hub.hpp> #include <catch2/interfaces/catch_interfaces_reporter_registry.hpp> #include <catch2/internal/catch_console_colour.hpp> +#include <catch2/internal/catch_parse_numbers.hpp> #include <catch2/internal/catch_reporter_spec_parser.hpp> #include <fstream> @@ -77,23 +78,14 @@ namespace Catch { return ParserResult::ok(ParseResultType::Matched); } - CATCH_TRY { - std::size_t parsedTo = 0; - unsigned long parsedSeed = std::stoul(seed, &parsedTo, 0); - if (parsedTo != seed.size()) { - return ParserResult::runtimeError("Could not parse '" + seed + "' as seed"); - } - - // TODO: Ideally we could parse unsigned int directly, - // but the stdlib doesn't provide helper for that - // type. After this is refactored to use fixed size - // type, we should check the parsed value is in range - // of the underlying type. - config.rngSeed = static_cast<unsigned int>(parsedSeed); - return ParserResult::ok(ParseResultType::Matched); - } CATCH_CATCH_ANON(std::exception const&) { - return ParserResult::runtimeError("Could not parse '" + seed + "' as seed"); + // TODO: ideally we should be parsing uint32_t directly + // fix this later when we add new parse overload + auto parsedSeed = parseUInt( seed, 0 ); + if ( !parsedSeed ) { + return ParserResult::runtimeError( "Could not parse '" + seed + "' as seed" ); } + config.rngSeed = *parsedSeed; + return ParserResult::ok( ParseResultType::Matched ); }; auto const setDefaultColourMode = [&]( std::string const& colourMode ) { Optional<ColourMode> maybeMode = Catch::Detail::stringToColourMode(toLower( colourMode )); |