Skip to content

Commit

Permalink
If MBO_CONFIG_REQUIRE throws, then explicitly call out the conditio…
Browse files Browse the repository at this point in the history
…n as a requirement.
  • Loading branch information
helly25 committed Oct 20, 2024
1 parent a3b8714 commit 712ce33
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions mbo/config/require.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion mbo/container/limited_ordered_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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.";
}
Expand Down

0 comments on commit 712ce33

Please sign in to comment.