From 749cb335e3394ae94ac655eac1ca6ccd4d090901 Mon Sep 17 00:00:00 2001 From: Bruno BELANYI Date: Sat, 24 Aug 2024 19:19:27 +0100 Subject: [PATCH] Make test failure more verbose Outputting the state of the map and this history of operations makes debugging easier. --- tests/unit/unit_test.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/tests/unit/unit_test.cc b/tests/unit/unit_test.cc index a99c643..a5d2c5c 100644 --- a/tests/unit/unit_test.cc +++ b/tests/unit/unit_test.cc @@ -2,6 +2,7 @@ #include +#include #include #include "model.hh" @@ -86,10 +87,28 @@ protected: } void check() const { + SCOPED_TRACE(stringify_map()); + SCOPED_TRACE(stringify_operations()); check_ranges(); check_canonicity(); } + std::string stringify_map() const { + std::ostringstream out; + out << "map: "; + for (const auto& [key, val] : map.underlying_) + out << "[" << +key << ": " << +val << "]"; + return out.str(); + } + + std::string stringify_operations() const { + std::ostringstream out; + out << "ops: "; + for (const auto& [start, end, val] : model.ranges_) + out << "[" << +start << ":" << +end << " => " << +val << "]"; + return out.str(); + } + // Compare against the fake 'Model' implementation void check_ranges() const { auto i = std::numeric_limits::min();