2017-08-09 13:10:14 +02:00
|
|
|
/*
|
|
|
|
* Created by Phil on 9/8/2017
|
|
|
|
* Copyright 2017 Two Blue Cubes Ltd. All rights reserved.
|
|
|
|
*
|
|
|
|
* 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 "catch_capture.hpp"
|
2017-09-07 12:24:33 +02:00
|
|
|
#include "catch_matchers.h"
|
2017-11-10 18:14:42 +01:00
|
|
|
#include "catch_matchers_floating.h"
|
2018-04-03 23:28:14 +02:00
|
|
|
#include "catch_matchers_generic.hpp"
|
2017-08-09 13:10:14 +02:00
|
|
|
#include "catch_matchers_string.h"
|
2017-08-16 15:37:54 +02:00
|
|
|
#include "catch_matchers_vector.h"
|
2018-07-23 13:55:14 +02:00
|
|
|
#include "catch_stringref.h"
|
2017-08-09 13:10:14 +02:00
|
|
|
|
|
|
|
namespace Catch {
|
|
|
|
|
|
|
|
template<typename ArgT, typename MatcherT>
|
|
|
|
class MatchExpr : public ITransientExpression {
|
|
|
|
ArgT const& m_arg;
|
|
|
|
MatcherT m_matcher;
|
|
|
|
StringRef m_matcherString;
|
|
|
|
public:
|
2018-07-23 13:49:29 +02:00
|
|
|
MatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef const& matcherString )
|
2017-11-27 20:49:26 +01:00
|
|
|
: ITransientExpression{ true, matcher.match( arg ) },
|
|
|
|
m_arg( arg ),
|
2017-08-09 13:10:14 +02:00
|
|
|
m_matcher( matcher ),
|
2017-11-27 20:49:26 +01:00
|
|
|
m_matcherString( matcherString )
|
2017-08-09 13:10:14 +02:00
|
|
|
{}
|
|
|
|
|
|
|
|
void streamReconstructedExpression( std::ostream &os ) const override {
|
|
|
|
auto matcherAsString = m_matcher.toString();
|
|
|
|
os << Catch::Detail::stringify( m_arg ) << ' ';
|
|
|
|
if( matcherAsString == Detail::unprintableString )
|
2017-08-14 09:54:57 +02:00
|
|
|
os << m_matcherString;
|
2017-08-09 13:10:14 +02:00
|
|
|
else
|
|
|
|
os << matcherAsString;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
using StringMatcher = Matchers::Impl::MatcherBase<std::string>;
|
|
|
|
|
2018-07-23 13:49:29 +02:00
|
|
|
void handleExceptionMatchExpr( AssertionHandler& handler, StringMatcher const& matcher, StringRef const& matcherString );
|
2017-08-09 13:10:14 +02:00
|
|
|
|
|
|
|
template<typename ArgT, typename MatcherT>
|
2018-07-23 13:49:29 +02:00
|
|
|
auto makeMatchExpr( ArgT const& arg, MatcherT const& matcher, StringRef const& matcherString ) -> MatchExpr<ArgT, MatcherT> {
|
2017-08-09 13:10:14 +02:00
|
|
|
return MatchExpr<ArgT, MatcherT>( arg, matcher, matcherString );
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace Catch
|
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#define INTERNAL_CHECK_THAT( macroName, matcher, resultDisposition, arg ) \
|
|
|
|
do { \
|
2018-07-23 13:55:14 +02:00
|
|
|
Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(arg) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
|
2017-11-23 17:52:46 +01:00
|
|
|
INTERNAL_CATCH_TRY { \
|
2018-07-23 13:55:14 +02:00
|
|
|
catchAssertionHandler.handleExpr( Catch::makeMatchExpr( arg, matcher, #matcher##_catch_sr ) ); \
|
2017-08-09 13:10:14 +02:00
|
|
|
} INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
|
|
|
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
2017-11-21 21:39:40 +01:00
|
|
|
} while( false )
|
2017-08-09 13:10:14 +02:00
|
|
|
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
#define INTERNAL_CATCH_THROWS_MATCHES( macroName, exceptionType, resultDisposition, matcher, ... ) \
|
|
|
|
do { \
|
2018-07-23 13:55:14 +02:00
|
|
|
Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(exceptionType) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
|
2017-08-09 13:10:14 +02:00
|
|
|
if( catchAssertionHandler.allowThrows() ) \
|
|
|
|
try { \
|
|
|
|
static_cast<void>(__VA_ARGS__ ); \
|
2017-11-24 20:15:46 +01:00
|
|
|
catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
|
2017-08-09 13:10:14 +02:00
|
|
|
} \
|
|
|
|
catch( exceptionType const& ex ) { \
|
2018-07-23 13:55:14 +02:00
|
|
|
catchAssertionHandler.handleExpr( Catch::makeMatchExpr( ex, matcher, #matcher##_catch_sr ) ); \
|
2017-08-09 13:10:14 +02:00
|
|
|
} \
|
|
|
|
catch( ... ) { \
|
2017-11-24 20:15:46 +01:00
|
|
|
catchAssertionHandler.handleUnexpectedInflightException(); \
|
2017-08-09 13:10:14 +02:00
|
|
|
} \
|
|
|
|
else \
|
2017-11-24 20:15:46 +01:00
|
|
|
catchAssertionHandler.handleThrowingCallSkipped(); \
|
2017-08-09 13:10:14 +02:00
|
|
|
INTERNAL_CATCH_REACT( catchAssertionHandler ) \
|
2017-11-21 21:39:40 +01:00
|
|
|
} while( false )
|
2017-08-09 13:10:14 +02:00
|
|
|
|
|
|
|
#endif // TWOBLUECUBES_CATCH_CAPTURE_MATCHERS_HPP_INCLUDED
|