diff options
| author | qerased | 2026-01-03 01:15:13 +0300 |
|---|---|---|
| committer | GitHub | 2026-01-02 23:15:13 +0100 |
| commit | b66b89374e60fa2fb725814acefbfc987ee5ff5e (patch) | |
| tree | 3f01c6cd3b3710cdb2a56d518f4eac152a24f386 /src/catch2 | |
| parent | b7e31c9ab3a4b6f7ef5f11d01aa3453c03e695b6 (diff) | |
| download | catch3-b66b89374e60fa2fb725814acefbfc987ee5ff5e.tar.gz | |
Add validation for --benchmark-samples to prevent crash with zero value (#3056)
* Add validation for --benchmark-samples to prevent crash with zero samples
* Add automated test for benchmark samples validation
* Update baselines for benchmark-samples validation
* Add missing test for benchmark samples validation
---------
Co-authored-by: Chan Aung <chan@Thinkpad.localdomain>
Diffstat (limited to 'src/catch2')
| -rw-r--r-- | src/catch2/internal/catch_commandline.cpp | 15 |
1 files changed, 14 insertions, 1 deletions
diff --git a/src/catch2/internal/catch_commandline.cpp b/src/catch2/internal/catch_commandline.cpp index 88454c0a..cf9cbf6d 100644 --- a/src/catch2/internal/catch_commandline.cpp +++ b/src/catch2/internal/catch_commandline.cpp @@ -189,6 +189,19 @@ namespace Catch { config.shardCount = *parsedCount; return ParserResult::ok( ParseResultType::Matched ); }; + auto const setBenchmarkSamples = [&]( std::string const& samples ) { + auto parsedSamples = parseUInt( samples ); + if ( !parsedSamples ) { + return ParserResult::runtimeError( + "Could not parse '" + samples + "' as benchmark samples" ); + } + if ( *parsedSamples == 0 ) { + return ParserResult::runtimeError( + "Benchmark samples must be greater than 0" ); + } + config.benchmarkSamples = *parsedSamples; + return ParserResult::ok( ParseResultType::Matched ); + }; auto const setShardIndex = [&](std::string const& shardIndex) { auto parsedIndex = parseUInt( shardIndex ); @@ -281,7 +294,7 @@ namespace Catch { | Opt( config.skipBenchmarks) ["--skip-benchmarks"] ( "disable running benchmarks") - | Opt( config.benchmarkSamples, "samples" ) + | Opt( setBenchmarkSamples, "samples" ) ["--benchmark-samples"] ( "number of samples to collect (default: 100)" ) | Opt( config.benchmarkResamples, "resamples" ) |