From 17a012d7549fa0e962dfa0622de8aef60c42bd3a Mon Sep 17 00:00:00 2001 From: Joao Paulo Magalhaes Date: Tue, 2 May 2017 20:31:54 +0100 Subject: [PATCH] Fix: --benchmark_counters_tabular was not being passed to tests. --- src/benchmark.cc | 35 +++++++++++++++++++++-------------- src/benchmark_api_internal.h | 2 ++ src/console_reporter.cc | 5 +++-- test/output_test_helper.cc | 4 +++- 4 files changed, 29 insertions(+), 17 deletions(-) diff --git a/src/benchmark.cc b/src/benchmark.cc index dea6756d..53c41429 100644 --- a/src/benchmark.cc +++ b/src/benchmark.cc @@ -542,6 +542,26 @@ std::unique_ptr CreateReporter( } } // end namespace + +ConsoleReporter::OutputOptions GetOutputOptions(bool force_no_color) { + int output_opts = ConsoleReporter::OO_Defaults; + if ((FLAGS_benchmark_color == "auto" && IsColorTerminal()) || + IsTruthyFlagValue(FLAGS_benchmark_color)) { + output_opts |= ConsoleReporter::OO_Color; + } else { + output_opts &= ~ConsoleReporter::OO_Color; + } + if(force_no_color) { + output_opts &= ~ConsoleReporter::OO_Color; + } + if(FLAGS_benchmark_counters_tabular) { + output_opts |= ConsoleReporter::OO_Tabular; + } else { + output_opts &= ~ConsoleReporter::OO_Tabular; + } + return static_cast< ConsoleReporter::OutputOptions >(output_opts); +} + } // end namespace internal size_t RunSpecifiedBenchmarks() { @@ -563,21 +583,8 @@ size_t RunSpecifiedBenchmarks(BenchmarkReporter* console_reporter, std::unique_ptr default_console_reporter; std::unique_ptr default_file_reporter; if (!console_reporter) { - int output_opts = ConsoleReporter::OO_Defaults; - if ((FLAGS_benchmark_color == "auto" && IsColorTerminal()) || - IsTruthyFlagValue(FLAGS_benchmark_color)) { - output_opts |= ConsoleReporter::OO_Color; - } else { - output_opts &= ~ConsoleReporter::OO_Color; - } - if(FLAGS_benchmark_counters_tabular) { - output_opts |= ConsoleReporter::OO_Tabular; - } else { - output_opts &= ~ConsoleReporter::OO_Tabular; - } default_console_reporter = internal::CreateReporter( - FLAGS_benchmark_format, - static_cast< ConsoleReporter::OutputOptions >(output_opts)); + FLAGS_benchmark_format, internal::GetOutputOptions()); console_reporter = default_console_reporter.get(); } auto& Out = console_reporter->GetOutputStream(); diff --git a/src/benchmark_api_internal.h b/src/benchmark_api_internal.h index 828ed121..922ed8d7 100644 --- a/src/benchmark_api_internal.h +++ b/src/benchmark_api_internal.h @@ -36,6 +36,8 @@ bool FindBenchmarksInternal(const std::string& re, std::vector* benchmarks, std::ostream* Err); +ConsoleReporter::OutputOptions GetOutputOptions(bool force_no_color = false); + namespace { bool IsZero(double n) { diff --git a/src/console_reporter.cc b/src/console_reporter.cc index fe0dda9e..538175fa 100644 --- a/src/console_reporter.cc +++ b/src/console_reporter.cc @@ -53,18 +53,19 @@ bool ConsoleReporter::ReportContext(const Context& context) { } void ConsoleReporter::PrintHeader(const Run& run) { - std::string str = FormatString("%-*s %13s %13s %10s\n", static_cast(name_field_width_), + std::string str = FormatString("%-*s %13s %13s %10s", static_cast(name_field_width_), "Benchmark", "Time", "CPU", "Iterations"); if(!run.counters.empty()) { if(output_options_ & OO_Tabular) { for(auto const& c : run.counters) { - str += FormatString(" %10s", c.first); + str += FormatString(" %10s", c.first.c_str()); } } else { str += " UserCounters..."; } } + str += "\n"; std::string line = std::string(str.length(), '-'); GetOutputStream() << line << "\n" << str << line << "\n"; } diff --git a/test/output_test_helper.cc b/test/output_test_helper.cc index fe750c7e..84ca2a6b 100644 --- a/test/output_test_helper.cc +++ b/test/output_test_helper.cc @@ -7,6 +7,7 @@ #include "../src/check.h" // NOTE: check.h is for internal use only! #include "../src/re.h" // NOTE: re.h is for internal use only #include "output_test.h" +#include "../src/benchmark_api_internal.h" // ========================================================================= // // ------------------------------ Internals -------------------------------- // @@ -367,7 +368,8 @@ int SetSubstitutions( void RunOutputTests(int argc, char* argv[]) { using internal::GetTestCaseList; benchmark::Initialize(&argc, argv); - benchmark::ConsoleReporter CR(benchmark::ConsoleReporter::OO_None); + auto options = benchmark::internal::GetOutputOptions(/*force_no_color*/true); + benchmark::ConsoleReporter CR(options); benchmark::JSONReporter JR; benchmark::CSVReporter CSVR; struct ReporterTest {