Add MessageMatches matcher for exception (#2570)

This commit is contained in:
lbckmnn
2022-12-12 00:40:47 +01:00
committed by GitHub
parent ed02710b83
commit 9c0533a905
20 changed files with 225 additions and 20 deletions

View File

@@ -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