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>
This commit is contained in:
1 parent
b7e31c9ab3
commit
b66b89374e
15 files changed
+238
-12
No files matched your search
@@ -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" )
|
||||
|
||||
Reference in new issue
Block a user