Helper for the [EXPECT,ASSERT]_[MOOSEERROR,THROW]_[MSG,MSG_CONTAINS] macros.
71{
72 static_assert(std::is_base_of_v<std::exception, ExceptionType>, "Not an exception");
73
74 std::ostringstream error;
75
76 try
77 {
78 std::unique_ptr<Moose::ScopedThrowOnError> scoped_throw_on_error;
79 if constexpr (set_throw_on_error)
80 scoped_throw_on_error = std::make_unique<Moose::ScopedThrowOnError>();
81
82 fn();
83
84 error <<
"Expected exception of type " <<
libMesh::demangle(
typeid(ExceptionType).name())
85 << " but no exception was thrown.";
86 }
87 catch (const ExceptionType & ex)
88 {
89
90 if constexpr (exact)
91 {
92 if (std::string(ex.what()) == message)
93 return;
94 }
95
96 else
97 {
98 if (std::string(ex.what()).find(message) != std::string::npos)
99 return;
100 }
101
102 error << "Expected" << (exact ? "" : " partial") << " exception message: \"" << message
103 << "\"\n Actual exception message: \"" << ex.what() << "\"";
104 }
105 catch (const std::exception & ex)
106 {
109 }
110
111 ::testing::internal::AssertHelper(
112 ::testing::TestPartResult::kNonFatalFailure, file, line, error.str().c_str()) =
113 ::testing::Message();
114}
std::string name(const ElemQuality q)
std::string demangle(const char *name)