Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Fix: --benchmark_counters_tabular was not being passed to tests.
  • Loading branch information
biojppm committed May 2, 2017
commit 17a012d7549fa0e962dfa0622de8aef60c42bd3a
35 changes: 21 additions & 14 deletions src/benchmark.cc
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,26 @@ std::unique_ptr<BenchmarkReporter> 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() {
Expand All @@ -563,21 +583,8 @@ size_t RunSpecifiedBenchmarks(BenchmarkReporter* console_reporter,
std::unique_ptr<BenchmarkReporter> default_console_reporter;
std::unique_ptr<BenchmarkReporter> 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();
Expand Down
2 changes: 2 additions & 0 deletions src/benchmark_api_internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ bool FindBenchmarksInternal(const std::string& re,
std::vector<Benchmark::Instance>* benchmarks,
std::ostream* Err);

ConsoleReporter::OutputOptions GetOutputOptions(bool force_no_color = false);

namespace {

bool IsZero(double n) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unused function, apparently? in travis (clang release)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've fixed by pragma-ignoring it, is it OK?

Expand Down
5 changes: 3 additions & 2 deletions src/console_reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<int>(name_field_width_),
std::string str = FormatString("%-*s %13s %13s %10s", static_cast<int>(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";
}
Expand Down
4 changes: 3 additions & 1 deletion test/output_test_helper.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 -------------------------------- //
Expand Down Expand Up @@ -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 {
Expand Down