mirror of
https://github.com/catchorg/Catch2.git
synced 2025-08-02 21:35:40 +02:00
Add MessageMatches matcher for exception (#2570)
This commit is contained in:
@@ -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
|
||||
|
||||
|
Reference in New Issue
Block a user