From 712ce336ae2c213257bcf2612d234b720ae75657 Mon Sep 17 00:00:00 2001 From: helly25 Date: Sun, 20 Oct 2024 14:04:57 +0200 Subject: [PATCH] If `MBO_CONFIG_REQUIRE` throws, then explicitly call out the condition as a requirement. --- mbo/config/require.h | 15 ++++++++------- mbo/container/limited_ordered_test.cc | 2 +- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/mbo/config/require.h b/mbo/config/require.h index 0ae8a63..6ac45dd 100644 --- a/mbo/config/require.h +++ b/mbo/config/require.h @@ -37,13 +37,14 @@ # undef MBO_CONFIG_REQUIRE #endif -#define MBO_CONFIG_REQUIRE(condition, message) \ - if constexpr (!::mbo::config::kRequireThrows) { \ - /* NOLINTNEXTLINE(bugprone-switch-missing-default-case) */ \ - ABSL_LOG_IF(FATAL, !(condition)) << message; \ - } else if ((condition)) { /* GOOD */ \ - } else \ - throw std::runtime_error(__FILE__ ":" MBO_PRIVATE_CONFIG_NUM2STR_(__LINE__) " : " #condition " : " message) +#define MBO_CONFIG_REQUIRE(condition, message) \ + if constexpr (!::mbo::config::kRequireThrows) { \ + /* NOLINTNEXTLINE(bugprone-switch-missing-default-case) */ \ + ABSL_LOG_IF(FATAL, !(condition)) << message; \ + } else if ((condition)) { /* GOOD */ \ + } else \ + throw std::runtime_error(__FILE__ ":" MBO_PRIVATE_CONFIG_NUM2STR_(__LINE__) " : Required (" #condition \ + ") : " message) // NOLINTEND(cppcoreguidelines-macro-usage) diff --git a/mbo/container/limited_ordered_test.cc b/mbo/container/limited_ordered_test.cc index 3b84676..2a742ce 100644 --- a/mbo/container/limited_ordered_test.cc +++ b/mbo/container/limited_ordered_test.cc @@ -112,7 +112,7 @@ TEST_F(LimitedOrderedTest, ConstexprRequireSortedInputThrows) { DoTestConstexprRequireSortedInputThrows(); } catch (const std::runtime_error& error) { caught = true; - EXPECT_THAT(error.what(), ::testing::HasSubstr("std::is_sorted(first, last, key_comp_)")); + EXPECT_THAT(error.what(), ::testing::HasSubstr("Required (std::is_sorted(first, last, key_comp_))")); } catch (...) { ADD_FAILURE() << "Wrong exception type."; }