Report unrecognized arguments from BENCHMARK_MAIN() macro (#332)

* BENCHMARK_MAIN() now reports unrecognised command-line flags (see google/benchmark#320)

* add benchmark::ReportUnrecognizedArguments()

Update BENCHMARK_MAIN() to use ReportUnrecognizedArguments() instead of
having the reporting code directly in the macro.

See issue google/benchmark#320 for reference

* let's stick to american english -- fix type in ReportUnrecognizedArguments()

* make ReportUnrecognizedArguments() print to stderr

* make ReportUnrecognizedArguments() return true if any arguments have been reported (i.e. argc > 1)
This commit is contained in:
Niklas Rosenstein 2017-01-18 04:28:20 +01:00 committed by Dominic Hamon
parent b4fdf6e9df
commit 817bfee273
2 changed files with 12 additions and 0 deletions

View File

@ -168,6 +168,10 @@ class BenchmarkReporter;
void Initialize(int* argc, char** argv);
// Report to stdout all arguments in 'argv' as unrecognized except the first.
// Returns true there is at least on unrecognized argument (i.e. 'argc' > 1).
bool ReportUnrecognizedArguments(int argc, char** argv);
// Generate a list of benchmarks matching the specified --benchmark_filter flag
// and if --benchmark_list_tests is specified return after printing the name
// of each matching benchmark. Otherwise run each matching benchmark and
@ -858,6 +862,7 @@ class Fixture : public internal::Benchmark {
#define BENCHMARK_MAIN() \
int main(int argc, char** argv) { \
::benchmark::Initialize(&argc, argv); \
if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1; \
::benchmark::RunSpecifiedBenchmarks(); \
}

View File

@ -664,4 +664,11 @@ void Initialize(int* argc, char** argv) {
internal::LogLevel() = FLAGS_v;
}
bool ReportUnrecognizedArguments(int argc, char** argv) {
for (int i = 1; i < argc; ++i) {
fprintf(stderr, "%s: error: unrecognized command-line flag: %s\n", argv[0], argv[i]);
}
return argc > 1;
}
} // end namespace benchmark