12 #include "gtest/gtest.h" 26 template <
class ExceptionType = std::exception,
class Action =
bool>
29 const std::optional<std::string> & contains = {},
30 const bool set_throw_on_error =
false)
32 static_assert(std::is_base_of_v<std::exception, ExceptionType>,
"Not an exception");
34 std::unique_ptr<Moose::ScopedThrowOnError> scoped_throw_on_error;
35 if (set_throw_on_error)
36 scoped_throw_on_error = std::make_unique<Moose::ScopedThrowOnError>();
41 FAIL() <<
"Expected " << MooseUtils::prettyCppType<ExceptionType>() <<
" not thrown";
43 catch (std::exception
const & e)
45 if constexpr (!std::is_same_v<std::exception, ExceptionType>)
46 if (!dynamic_cast<const ExceptionType *>(&e))
47 FAIL() <<
"Threw " <<
demangle(
typeid(e).
name()) <<
" instead of " 48 << MooseUtils::prettyCppType<ExceptionType>() <<
" with message '" << e.what()
53 ASSERT_TRUE(std::string(e.what()).
find(*contains) != std::string::npos)
54 <<
"Exception \"" << e.what() <<
"\" does not contain \"" << *
contains <<
"\"";
std::string name(const ElemQuality q)
KOKKOS_INLINE_FUNCTION const T * find(const T &target, const T *const begin, const T *const end)
Find a value in an array.
void assertThrows(const Action &action, const std::optional< std::string > &contains={}, const bool set_throw_on_error=false)
A helper for asserting that calling something throws an exception.
bool contains(std::string_view superstring, std::string_view substring)
std::string demangle(const char *name)