41 std::string_view reason = {},
42 std::optional<std::source_location> location = KAYCXX_ASSERT_DEFAULT_SOURCE
45 std::invoke(std::forward<Function>(function));
46 }
catch (std::exception
const& exception) {
47 auto actual_string = std::format(
48 "exception of type <{}> with message <{}>",
49 detail::exception_type_name(exception),
50 detail::to_string(exception.what())
52 auto message = std::format(
"Expected function not to throw but caught {}", actual_string);
53 throw assertion_error(message, reason, std::move(actual_string),
"no exception", location);
55 throw assertion_error(
56 "Expected function not to throw but caught <unknown exception>",
84 std::string_view unexpected_message,
85 std::string_view reason = {},
86 std::optional<std::source_location> location = KAYCXX_ASSERT_DEFAULT_SOURCE
88 auto unexpected_type = detail::exception_type_name<Exception>();
91 std::invoke(std::forward<Function>(function));
92 }
catch (Exception
const& exception) {
93 auto actual_message = std::string_view(exception.what());
94 if (actual_message == unexpected_message) {
95 auto expected_string = detail::to_string(unexpected_message);
96 auto actual_string = std::format(
97 "exception of type <{}> with message <{}>",
101 auto message = std::format(
"Expected function not to throw {}", actual_string);
102 throw assertion_error(message, reason, std::move(actual_string), std::move(expected_string), location);
128 std::regex
const& unexpected_message,
129 std::string_view reason = {},
130 std::optional<std::source_location> location = KAYCXX_ASSERT_DEFAULT_SOURCE
132 auto unexpected_type = detail::exception_type_name<Exception>();
135 std::invoke(std::forward<Function>(function));
136 }
catch (Exception
const& exception) {
137 auto actual_message = std::string_view(exception.what());
138 if (std::regex_match(actual_message.begin(), actual_message.end(), unexpected_message)) {
139 auto actual_string = std::format(
140 "exception of type <{}> with message matching regex",
143 auto message = std::format(
"Expected function not to throw {}", actual_string);
144 throw assertion_error(message, reason, std::move(actual_string),
"regex", location);
void assert_not_throw(Function &&function, std::string_view reason={}, std::optional< std::source_location > location=KAYCXX_ASSERT_DEFAULT_SOURCE)
Asserts that the function does not throw any exception.
Definition assert_not_throw.hpp:39