Handle the case when the argument name is an empty string.

This commit is contained in:
Marek Kurdej 2016-10-25 09:45:35 +02:00
parent 17e1c405dd
commit c1c01b2cd3
2 changed files with 13 additions and 8 deletions

View File

@ -153,12 +153,16 @@ bool BenchmarkFamilies::FindBenchmarks(
// Add arguments to instance name
size_t arg_i = 0;
for (auto const& arg : args) {
if (arg_i < family->arg_names_.size()) {
instance.name +=
StringPrintF("/%s:", family->arg_names_[arg_i].c_str());
} else {
instance.name += "/";
if (arg_i < family->arg_names_.size()) {
const auto& arg_name = family->arg_names_[arg_i];
if (!arg_name.empty()) {
instance.name +=
StringPrintF("%s:", family->arg_names_[arg_i].c_str());
}
}
AppendHumanReadable(arg, &instance.name);
++arg_i;
}

View File

@ -86,10 +86,11 @@ void BM_arg_names(benchmark::State& state) {
while (state.KeepRunning()) {
}
}
BENCHMARK(BM_arg_names)->Args({2, 4})->ArgNames({"first", "second"});
ADD_CASES(TC_ConsoleOut, {{"^BM_arg_names/first:2/second:4 %console_report$"}});
ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_arg_names/first:2/second:4\",$"}});
ADD_CASES(TC_CSVOut, {{"^\"BM_arg_names/first:2/second:4\",%csv_report$"}});
BENCHMARK(BM_arg_names)->Args({2, 5, 4})->ArgNames({"first", "", "third"});
ADD_CASES(TC_ConsoleOut,
{{"^BM_arg_names/first:2/5/third:4 %console_report$"}});
ADD_CASES(TC_JSONOut, {{"\"name\": \"BM_arg_names/first:2/5/third:4\",$"}});
ADD_CASES(TC_CSVOut, {{"^\"BM_arg_names/first:2/5/third:4\",%csv_report$"}});
// ========================================================================= //
// ----------------------- Testing Complexity Output ----------------------- //