Skip to content

Commit 71ffa7b

Browse files
committed
Improved assert_exception
1 parent affe84f commit 71ffa7b

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

test/helper.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,14 @@ void assert_equal(const T& left, const U& right, const std::source_location& loc
1818

1919
template<typename T>
2020
void assert_exception(std::function<void(void)> code, std::optional<std::string_view> message = std::nullopt) {
21-
bool exception = false;
21+
std::optional<T> exception;
2222
try {
2323
code();
2424
} catch (const T& e) {
25-
exception = true;
26-
if (message) {
27-
assert_equal(std::string_view(e.what()), *message);
28-
}
25+
exception = e;
26+
}
27+
assert_equal(exception.has_value(), true);
28+
if (message) {
29+
assert_equal(std::string_view((*exception).what()), *message);
2930
}
30-
assert_equal(exception, true);
3131
}

0 commit comments

Comments
 (0)