Commit 817bfee2 by Niklas Rosenstein Committed by Dominic Hamon

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)
parent b4fdf6e9
...@@ -168,6 +168,10 @@ class BenchmarkReporter; ...@@ -168,6 +168,10 @@ class BenchmarkReporter;
void Initialize(int* argc, char** argv); 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 // Generate a list of benchmarks matching the specified --benchmark_filter flag
// and if --benchmark_list_tests is specified return after printing the name // and if --benchmark_list_tests is specified return after printing the name
// of each matching benchmark. Otherwise run each matching benchmark and // of each matching benchmark. Otherwise run each matching benchmark and
...@@ -858,6 +862,7 @@ class Fixture : public internal::Benchmark { ...@@ -858,6 +862,7 @@ class Fixture : public internal::Benchmark {
#define BENCHMARK_MAIN() \ #define BENCHMARK_MAIN() \
int main(int argc, char** argv) { \ int main(int argc, char** argv) { \
::benchmark::Initialize(&argc, argv); \ ::benchmark::Initialize(&argc, argv); \
if (::benchmark::ReportUnrecognizedArguments(argc, argv)) return 1; \
::benchmark::RunSpecifiedBenchmarks(); \ ::benchmark::RunSpecifiedBenchmarks(); \
} }
......
...@@ -664,4 +664,11 @@ void Initialize(int* argc, char** argv) { ...@@ -664,4 +664,11 @@ void Initialize(int* argc, char** argv) {
internal::LogLevel() = FLAGS_v; 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 } // end namespace benchmark
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment