diff options
| author | lbckmnn | 2022-12-12 00:40:47 +0100 |
|---|---|---|
| committer | GitHub | 2022-12-12 00:40:47 +0100 |
| commit | 9c0533a90504b2b1c308dc7cc77ff194f81046e2 (patch) | |
| tree | 8cd45ddd221a06f4df00b2f977ee6436cd2fe724 /src/catch2 | |
| parent | ed02710b83c2a3ddbca20b86f3d26d2fb99d2d02 (diff) | |
| download | catch3-9c0533a90504b2b1c308dc7cc77ff194f81046e2.tar.gz | |
Add MessageMatches matcher for exception (#2570)
Diffstat (limited to 'src/catch2')
| -rw-r--r-- | src/catch2/matchers/catch_matchers_exception.hpp | 26 |
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 |