Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:54:07

0001 
0002 //              Copyright Catch2 Authors
0003 // Distributed under the Boost Software License, Version 1.0.
0004 //   (See accompanying file LICENSE.txt or copy at
0005 //        https://www.boost.org/LICENSE_1_0.txt)
0006 
0007 // SPDX-License-Identifier: BSL-1.0
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 //! Creates a matcher that checks whether a std derived exception has the provided message
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 //! Creates a matcher that checks whether a message from an std derived
0051 //! exception matches a provided matcher
0052 template <typename StringMatcherType>
0053 ExceptionMessageMatchesMatcher<StringMatcherType>
0054 MessageMatches( StringMatcherType&& matcher ) {
0055     return { CATCH_FORWARD( matcher ) };
0056 }
0057 
0058 } // namespace Matchers
0059 } // namespace Catch
0060 
0061 #endif // CATCH_MATCHERS_EXCEPTION_HPP_INCLUDED