From 4f8bfeae470950ef005327973f15b0044eceaceb Mon Sep 17 00:00:00 2001 From: Dominic Hamon Date: Fri, 28 Oct 2016 14:22:22 -0700 Subject: [PATCH] Report error when no benchmarks match regex. (#308) Fixes #306 --- src/benchmark.cc | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/benchmark.cc b/src/benchmark.cc index 8e356de522..95f6a25b75 100644 --- a/src/benchmark.cc +++ b/src/benchmark.cc @@ -450,7 +450,7 @@ void State::FinishKeepRunning() { namespace internal { namespace { -void RunMatchingBenchmarks(const std::vector& benchmarks, +void RunBenchmarks(const std::vector& benchmarks, BenchmarkReporter* console_reporter, BenchmarkReporter* file_reporter) { // Note the file_reporter can be null. @@ -581,11 +581,15 @@ size_t RunSpecifiedBenchmarks(BenchmarkReporter* console_reporter, std::vector benchmarks; if (!FindBenchmarksInternal(spec, &benchmarks, &Err)) return 0; + if (benchmarks.empty()) { + Err << "Failed to match any benchmarks against regex: " << spec << "\n"; + return 0; + } + if (FLAGS_benchmark_list_tests) { for (auto const& benchmark : benchmarks) Out << benchmark.name << "\n"; } else { - internal::RunMatchingBenchmarks(benchmarks, console_reporter, - file_reporter); + internal::RunBenchmarks(benchmarks, console_reporter, file_reporter); } return benchmarks.size();