aboutsummaryrefslogtreecommitdiff
path: root/test/filter_test.cc
diff options
context:
space:
mode:
Diffstat (limited to 'test/filter_test.cc')
-rw-r--r--test/filter_test.cc43
1 files changed, 28 insertions, 15 deletions
diff --git a/test/filter_test.cc b/test/filter_test.cc
index 0e27065..4c8b8ea 100644
--- a/test/filter_test.cc
+++ b/test/filter_test.cc
@@ -1,36 +1,40 @@
-#include "benchmark/benchmark.h"
-
+#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdint>
#include <cstdlib>
-
#include <iostream>
#include <limits>
#include <sstream>
#include <string>
+#include "benchmark/benchmark.h"
+
namespace {
class TestReporter : public benchmark::ConsoleReporter {
public:
- virtual bool ReportContext(const Context& context) {
+ bool ReportContext(const Context& context) override {
return ConsoleReporter::ReportContext(context);
};
- virtual void ReportRuns(const std::vector<Run>& report) {
+ void ReportRuns(const std::vector<Run>& report) override {
++count_;
+ max_family_index_ = std::max(max_family_index_, report[0].family_index);
ConsoleReporter::ReportRuns(report);
};
- TestReporter() : count_(0) {}
+ TestReporter() : count_(0), max_family_index_(0) {}
- virtual ~TestReporter() {}
+ ~TestReporter() override {}
- size_t GetCount() const { return count_; }
+ int GetCount() const { return count_; }
+
+ int64_t GetMaxFamilyIndex() const { return max_family_index_; }
private:
- mutable size_t count_;
+ mutable int count_;
+ mutable int64_t max_family_index_;
};
} // end namespace
@@ -65,7 +69,7 @@ static void BM_FooBa(benchmark::State& state) {
}
BENCHMARK(BM_FooBa);
-int main(int argc, char **argv) {
+int main(int argc, char** argv) {
bool list_only = false;
for (int i = 0; i < argc; ++i)
list_only |= std::string(argv[i]).find("--benchmark_list_tests") !=
@@ -74,13 +78,13 @@ int main(int argc, char **argv) {
benchmark::Initialize(&argc, argv);
TestReporter test_reporter;
- const size_t returned_count =
- benchmark::RunSpecifiedBenchmarks(&test_reporter);
+ const int64_t returned_count =
+ static_cast<int64_t>(benchmark::RunSpecifiedBenchmarks(&test_reporter));
if (argc == 2) {
// Make sure we ran all of the tests
std::stringstream ss(argv[1]);
- size_t expected_return;
+ int64_t expected_return;
ss >> expected_return;
if (returned_count != expected_return) {
@@ -90,14 +94,23 @@ int main(int argc, char **argv) {
return -1;
}
- const size_t expected_reports = list_only ? 0 : expected_return;
- const size_t reports_count = test_reporter.GetCount();
+ const int64_t expected_reports = list_only ? 0 : expected_return;
+ const int64_t reports_count = test_reporter.GetCount();
if (reports_count != expected_reports) {
std::cerr << "ERROR: Expected " << expected_reports
<< " tests to be run but reported_count = " << reports_count
<< std::endl;
return -1;
}
+
+ const int64_t max_family_index = test_reporter.GetMaxFamilyIndex();
+ const int64_t num_families = reports_count == 0 ? 0 : 1 + max_family_index;
+ if (num_families != expected_reports) {
+ std::cerr << "ERROR: Expected " << expected_reports
+ << " test families to be run but num_families = "
+ << num_families << std::endl;
+ return -1;
+ }
}
return 0;