aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/catch2/matchers/catch_matchers_exception.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/catch2/matchers/catch_matchers_exception.hpp')
-rw-r--r--src/catch2/matchers/catch_matchers_exception.hpp26
1 files changed, 26 insertions, 0 deletions
diff --git a/src/catch2/matchers/catch_matchers_exception.hpp b/src/catch2/matchers/catch_matchers_exception.hpp
index 27e1b932..e7c3a636 100644
--- a/src/catch2/matchers/catch_matchers_exception.hpp
+++ b/src/catch2/matchers/catch_matchers_exception.hpp
@@ -29,6 +29,32 @@ public:
//! Creates a matcher that checks whether a std derived exception has the provided message
ExceptionMessageMatcher Message(std::string const& message);
+template <typename StringMatcherType>
+class ExceptionMessageMatchesMatcher final
+ : public MatcherBase<std::exception> {
+ StringMatcherType m_matcher;
+
+public:
+ ExceptionMessageMatchesMatcher( StringMatcherType matcher ):
+ m_matcher( CATCH_MOVE( matcher ) ) {}
+
+ bool match( std::exception const& ex ) const override {
+ return m_matcher.match( ex.what() );
+ }
+
+ std::string describe() const override {
+ return " matches \"" + m_matcher.describe() + '"';
+ }
+};
+
+//! Creates a matcher that checks whether a message from an std derived
+//! exception matches a provided matcher
+template <typename StringMatcherType>
+ExceptionMessageMatchesMatcher<StringMatcherType>
+MessageMatches( StringMatcherType&& matcher ) {
+ return { CATCH_FORWARD( matcher ) };
+}
+
} // namespace Matchers
} // namespace Catch