1 #ifndef UTOPIA_CORE_TESTTOOLS_EXCEPTIONS_HH
2 #define UTOPIA_CORE_TESTTOOLS_EXCEPTIONS_HH
9 #include <boost/test/unit_test.hpp>
10 #include <boost/core/demangle.hpp>
12 #include "../exceptions.hh"
41 template<
typename ExcT,
typename Callable=std::function<
void()>>
43 const std::string_view match =
"",
47 static_assert(std::is_invocable_v<Callable>,
48 "Callable needs to be invocable without any arguments!");
53 if constexpr (std::is_same<ExcT, std::exception>()) {
56 BOOST_ERROR(loc <<
"Should have thrown but did not!");
59 if (not match.empty() and not
contains(e.what(), match)) {
60 BOOST_ERROR(loc <<
"Did not throw expected error message!\n"
61 " Expected match : " << match <<
"\n"
62 " But got : " << e.what() <<
"\n");
67 BOOST_ERROR(loc <<
"Threw non-std::exception!");
76 BOOST_ERROR(loc <<
"Should have thrown but did not!");
79 if (not match.empty() and not
contains(e.what(), match)) {
80 BOOST_ERROR(loc <<
"Did not throw expected error message!\n"
81 " Expected match : " << match <<
"\n"
82 " But got : " << e.what() <<
"\n");
86 catch (std::exception& e) {
87 BOOST_ERROR(loc <<
"Threw error of unexpected type ("
88 << boost::core::demangle(
typeid(e).name())
89 <<
") with message: " << e.what());
92 BOOST_ERROR(loc <<
"Threw non-std::exception!");