42 std::string_view reason = {},
43 std::optional<std::source_location> location = std::source_location::current()
46 std::invoke(std::forward<Function>(function));
47 }
catch (std::exception
const& exception) {
48 auto actual_string = std::format(
49 "exception of type <{}> with message <{}>",
50 detail::exception_type_name(exception),
51 detail::to_string(exception.what())
53 auto message = std::format(
"Expected function not to throw but caught {}", actual_string);
54 throw assertion_error(message, reason, std::move(actual_string),
"no exception", location);
56 throw assertion_error(
57 "Expected function not to throw but caught <unknown exception>",
85 std::string_view unexpected_message,
86 std::string_view reason = {},
87 std::optional<std::source_location> location = std::source_location::current()
89 auto unexpected_type = detail::exception_type_name<Exception>();
92 std::invoke(std::forward<Function>(function));
93 }
catch (Exception
const& exception) {
94 auto actual_message = std::string_view(exception.what());
95 if (actual_message == unexpected_message) {
96 auto expected_string = detail::to_string(unexpected_message);
97 auto actual_string = std::format(
98 "exception of type <{}> with message <{}>",
102 auto message = std::format(
"Expected function not to throw {}", actual_string);
103 throw assertion_error(message, reason, std::move(actual_string), std::move(expected_string), location);
129 std::regex
const& unexpected_message,
130 std::string_view reason = {},
131 std::optional<std::source_location> location = std::source_location::current()
133 auto unexpected_type = detail::exception_type_name<Exception>();
136 std::invoke(std::forward<Function>(function));
137 }
catch (Exception
const& exception) {
138 auto actual_message = std::string_view(exception.what());
139 if (std::regex_match(actual_message.begin(), actual_message.end(), unexpected_message)) {
140 auto actual_string = std::format(
141 "exception of type <{}> with message matching regex",
144 auto message = std::format(
"Expected function not to throw {}", actual_string);
145 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=std::source_location::current())
Asserts that the function does not throw any exception.
Definition assert_not_throw.hpp:40