File indexing completed on 2025-01-18 09:54:07
0001
0002
0003
0004
0005
0006
0007
0008 #ifndef CATCH_MATCHERS_EXCEPTION_HPP_INCLUDED
0009 #define CATCH_MATCHERS_EXCEPTION_HPP_INCLUDED
0010
0011 #include <catch2/matchers/catch_matchers.hpp>
0012
0013 namespace Catch {
0014 namespace Matchers {
0015
0016 class ExceptionMessageMatcher final : public MatcherBase<std::exception> {
0017 std::string m_message;
0018 public:
0019
0020 ExceptionMessageMatcher(std::string const& message):
0021 m_message(message)
0022 {}
0023
0024 bool match(std::exception const& ex) const override;
0025
0026 std::string describe() const override;
0027 };
0028
0029
0030 ExceptionMessageMatcher Message(std::string const& message);
0031
0032 template <typename StringMatcherType>
0033 class ExceptionMessageMatchesMatcher final
0034 : public MatcherBase<std::exception> {
0035 StringMatcherType m_matcher;
0036
0037 public:
0038 ExceptionMessageMatchesMatcher( StringMatcherType matcher ):
0039 m_matcher( CATCH_MOVE( matcher ) ) {}
0040
0041 bool match( std::exception const& ex ) const override {
0042 return m_matcher.match( ex.what() );
0043 }
0044
0045 std::string describe() const override {
0046 return " matches \"" + m_matcher.describe() + '"';
0047 }
0048 };
0049
0050
0051
0052 template <typename StringMatcherType>
0053 ExceptionMessageMatchesMatcher<StringMatcherType>
0054 MessageMatches( StringMatcherType&& matcher ) {
0055 return { CATCH_FORWARD( matcher ) };
0056 }
0057
0058 }
0059 }
0060
0061 #endif