Introduce the possibility to customize the help printer function (#1342)

* introduce the possibility to customize the help printer function

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>

* fixed naming convertion, and introduce the option function in the init method

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>

* remove the macros to inject the helper function

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>

* remove the default implementation, and introduce the nullprt

Signed-off-by: Vincenzo Palazzo <vincenzopalazzodev@gmail.com>
This commit is contained in:
Vincenzo Palazzo 2022-02-16 10:23:54 +01:00 committed by GitHub
parent 28b210ebb8
commit c563644040
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 21 deletions

View File

@ -291,7 +291,8 @@ BENCHMARK(BM_test)->Unit(benchmark::kMillisecond);
namespace benchmark { namespace benchmark {
class BenchmarkReporter; class BenchmarkReporter;
BENCHMARK_EXPORT void Initialize(int* argc, char** argv); BENCHMARK_EXPORT void Initialize(int* argc, char** argv,
void (*HelperPrinterf)() = NULL);
BENCHMARK_EXPORT void Shutdown(); BENCHMARK_EXPORT void Shutdown();
// Report to stdout all arguments in 'argv' as unrecognized except the first. // Report to stdout all arguments in 'argv' as unrecognized except the first.
@ -1202,7 +1203,6 @@ class LambdaBenchmark : public Benchmark {
Lambda lambda_; Lambda lambda_;
}; };
#endif #endif
} // namespace internal } // namespace internal
inline internal::Benchmark* RegisterBenchmark(const char* name, inline internal::Benchmark* RegisterBenchmark(const char* name,
@ -1254,7 +1254,6 @@ class Fixture : public internal::Benchmark {
protected: protected:
virtual void BenchmarkCase(State&) = 0; virtual void BenchmarkCase(State&) = 0;
}; };
} // namespace benchmark } // namespace benchmark
// ------------------------------------------------------ // ------------------------------------------------------

View File

@ -538,24 +538,29 @@ void AddCustomContext(const std::string& key, const std::string& value) {
namespace internal { namespace internal {
void (*HelperPrintf)();
void PrintUsageAndExit() { void PrintUsageAndExit() {
fprintf(stdout, if (HelperPrintf) {
"benchmark" HelperPrintf();
" [--benchmark_list_tests={true|false}]\n" } else {
" [--benchmark_filter=<regex>]\n" fprintf(stdout,
" [--benchmark_min_time=<min_time>]\n" "benchmark"
" [--benchmark_repetitions=<num_repetitions>]\n" " [--benchmark_list_tests={true|false}]\n"
" [--benchmark_enable_random_interleaving={true|false}]\n" " [--benchmark_filter=<regex>]\n"
" [--benchmark_report_aggregates_only={true|false}]\n" " [--benchmark_min_time=<min_time>]\n"
" [--benchmark_display_aggregates_only={true|false}]\n" " [--benchmark_repetitions=<num_repetitions>]\n"
" [--benchmark_format=<console|json|csv>]\n" " [--benchmark_enable_random_interleaving={true|false}]\n"
" [--benchmark_out=<filename>]\n" " [--benchmark_report_aggregates_only={true|false}]\n"
" [--benchmark_out_format=<json|console|csv>]\n" " [--benchmark_display_aggregates_only={true|false}]\n"
" [--benchmark_color={auto|true|false}]\n" " [--benchmark_format=<console|json|csv>]\n"
" [--benchmark_counters_tabular={true|false}]\n" " [--benchmark_out=<filename>]\n"
" [--benchmark_perf_counters=<counter>,...]\n" " [--benchmark_out_format=<json|console|csv>]\n"
" [--benchmark_context=<key>=<value>,...]\n" " [--benchmark_color={auto|true|false}]\n"
" [--v=<verbosity>]\n"); " [--benchmark_counters_tabular={true|false}]\n"
" [--benchmark_context=<key>=<value>,...]\n"
" [--v=<verbosity>]\n");
}
exit(0); exit(0);
} }
@ -618,9 +623,10 @@ int InitializeStreams() {
} // end namespace internal } // end namespace internal
void Initialize(int* argc, char** argv) { void Initialize(int* argc, char** argv, void (*HelperPrintf)()) {
internal::ParseCommandLineFlags(argc, argv); internal::ParseCommandLineFlags(argc, argv);
internal::LogLevel() = FLAGS_v; internal::LogLevel() = FLAGS_v;
internal::HelperPrintf = HelperPrintf;
} }
void Shutdown() { delete internal::global_context; } void Shutdown() { delete internal::global_context; }