From 30e82a81e892b2e630cbc01490a2e3cc9908058a Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Sun, 7 Jul 2024 16:25:27 +0800 Subject: [PATCH] test: do not define boost_test_print_type() for types with operator<< before this change, we provide `boost_test_print_type()` for all types which can be formatted using {fmt}. these types includes those who fulfill the concept of range, and their element can be formatted using {fmt}. if the compilation unit happens to include `fmt/ranges.h`. the ranges are formatted with `boost_test_print_type()` as well. this is what we expect. in other words, we use {fmt} to format types which do not natively support {fmt}, but they fulfill the range concept. but `boost::unit_test::basic_cstring` is one of them - it can be formatted using operator<<, but it does not provide fmt::format specialization - it fulfills the concept of range - and its element type is `char const`, which can be formatted using {fmt} that's why it's formatted like: ``` test/boost/sstable_directory_test.cc(317): fatal error: in "sstable_directory_test_generation_sanity": critical check ['s', 's', 't', '-', '>', 'g', 'e', 'n', 'e', 'r', 'a', 't', 'i', 'o', 'n', '(', ')', ' ', '=', '=', ' ', 's', 's', 't', '1', '-', '>', 'g', 'e', 'n', 'e', 'r', 'a', 't', 'i', 'o', 'n', '(', ')'] has failed` ``` where the string is formatted as a sequence-alike container. this is far from readable. so, in this change, we do not define `boost_test_print_type()` for the types which natively support `operator<<` anymore. so they can be printed with `operator<<` when boost::test prints them. Fixes scylladb/scylladb#19637 Signed-off-by: Kefu Chai Closes scylladb/scylladb#19638 --- test/lib/test_utils.hh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/lib/test_utils.hh b/test/lib/test_utils.hh index a6018184bc..95a088b946 100644 --- a/test/lib/test_utils.hh +++ b/test/lib/test_utils.hh @@ -116,7 +116,8 @@ extern std::mutex boost_logger_mutex; namespace std { template -requires fmt::is_formattable::value +requires (fmt::is_formattable::value && + !boost::has_left_shift::value) std::ostream& boost_test_print_type(std::ostream& os, const T& p) { fmt::print(os, "{}", p); return os;