mirror of
https://github.com/google/benchmark.git
synced 2025-01-30 22:00:16 +08:00
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:
parent
b4fdf6e9df
commit
817bfee273
@ -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(); \
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user