diff options
| author | Martin Hořeňovský | 2020-04-26 21:33:55 +0200 |
|---|---|---|
| committer | Martin Hořeňovský | 2020-04-26 21:33:55 +0200 |
| commit | 8d50f044196c92d0b9cb3dcd9bc32fe96d768b99 (patch) | |
| tree | 9920320adcbbf2eca94b33cec5b849bb4950216c /src/catch2/internal | |
| parent | 804e2df099e59b06a97fcf794e93d89e8fcbaed5 (diff) | |
| download | catch3-8d50f044196c92d0b9cb3dcd9bc32fe96d768b99.tar.gz | |
Move around matcher macro implementation
Diffstat (limited to 'src/catch2/internal')
| -rw-r--r-- | src/catch2/internal/catch_assertionhandler.cpp | 1 | ||||
| -rw-r--r-- | src/catch2/internal/catch_capture_matchers.cpp | 20 | ||||
| -rw-r--r-- | src/catch2/internal/catch_capture_matchers.hpp | 85 |
3 files changed, 0 insertions, 106 deletions
diff --git a/src/catch2/internal/catch_assertionhandler.cpp b/src/catch2/internal/catch_assertionhandler.cpp index 0fe95f50..b16d356d 100644 --- a/src/catch2/internal/catch_assertionhandler.cpp +++ b/src/catch2/internal/catch_assertionhandler.cpp @@ -14,7 +14,6 @@ #include <catch2/internal/catch_enforce.hpp> #include <catch2/internal/catch_debugger.hpp> #include <catch2/interfaces/catch_interfaces_registry_hub.hpp> -#include <catch2/internal/catch_capture_matchers.hpp> #include <catch2/internal/catch_run_context.hpp> #include <catch2/matchers/catch_matchers_string.hpp> diff --git a/src/catch2/internal/catch_capture_matchers.cpp b/src/catch2/internal/catch_capture_matchers.cpp deleted file mode 100644 index 90f0c084..00000000 --- a/src/catch2/internal/catch_capture_matchers.cpp +++ /dev/null @@ -1,20 +0,0 @@ -/* - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ -#include <catch2/internal/catch_capture_matchers.hpp> -#include <catch2/matchers/catch_matchers.hpp> -#include <catch2/interfaces/catch_interfaces_registry_hub.hpp> - -namespace Catch { - - // This is the general overload that takes a any string matcher - // There is another overload, in catch_assertionhandler.h/.cpp, that only takes a string and infers - // the Equals matcher (so the header does not mention matchers) - void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString ) { - std::string exceptionMessage = Catch::translateActiveException(); - MatchExpr<std::string, StringMatcher const&> expr( std::move(exceptionMessage), matcher, matcherString ); - handler.handleExpr( expr ); - } - -} // namespace Catch diff --git a/src/catch2/internal/catch_capture_matchers.hpp b/src/catch2/internal/catch_capture_matchers.hpp deleted file mode 100644 index 0ec60bc2..00000000 --- a/src/catch2/internal/catch_capture_matchers.hpp +++ /dev/null @@ -1,85 +0,0 @@ -/* - * Distributed under the Boost Software License, Version 1.0. (See accompanying - * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt) - */ -#ifndef TWOBLUECUBES_CATCH_CAPTURE_MATCHERS_HPP_INCLUDED -#define TWOBLUECUBES_CATCH_CAPTURE_MATCHERS_HPP_INCLUDED - -#include <catch2/internal/catch_test_macro_impl.hpp> -#include <catch2/catch_stringref.hpp> - -namespace Catch { - - template<typename ArgT, typename MatcherT> - class MatchExpr : public ITransientExpression { - ArgT && m_arg; - MatcherT const& m_matcher; - StringRef m_matcherString; - public: - MatchExpr( ArgT && arg, MatcherT const& matcher, StringRef const& matcherString ) - : ITransientExpression{ true, matcher.match( arg ) }, // not forwarding arg here on purpose - m_arg( std::forward<ArgT>(arg) ), - m_matcher( matcher ), - m_matcherString( matcherString ) - {} - - void streamReconstructedExpression( std::ostream &os ) const override { - auto matcherAsString = m_matcher.toString(); - os << Catch::Detail::stringify( m_arg ) << ' '; - if( matcherAsString == Detail::unprintableString ) - os << m_matcherString; - else - os << matcherAsString; - } - }; - - namespace Matchers { - template <typename ArgT> - struct MatcherBase; - } - - using StringMatcher = Matchers::MatcherBase<std::string>; - - void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString ); - - template<typename ArgT, typename MatcherT> - auto makeMatchExpr( ArgT && arg, MatcherT const& matcher, StringRef const& matcherString ) -> MatchExpr<ArgT, MatcherT> { - return MatchExpr<ArgT, MatcherT>( std::forward<ArgT>(arg), matcher, matcherString ); - } - -} // namespace Catch - - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \ - do { \ - Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ - INTERNAL_CATCH_TRY { \ - catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher, #matcher##_catch_sr ) ); \ - } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( false ) - - -/////////////////////////////////////////////////////////////////////////////// -#define INTERNAL_CATCH_THROWS_MATCHES( macroName, exceptionType, resultDisposition, matcher, ... ) \ - do { \ - Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \ - if( catchAssertionHandler.allowThrows() ) \ - try { \ - static_cast<void>(__VA_ARGS__ ); \ - catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \ - } \ - catch( exceptionType const& ex ) { \ - catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher, #matcher##_catch_sr ) ); \ - } \ - catch( ... ) { \ - catchAssertionHandler.handleUnexpectedInflightException(); \ - } \ - else \ - catchAssertionHandler.handleThrowingCallSkipped(); \ - INTERNAL_CATCH_REACT( catchAssertionHandler ) \ - } while( false ) - - -#endif // TWOBLUECUBES_CATCH_CAPTURE_MATCHERS_HPP_INCLUDED |