2010-11-10 00:24:00 +01:00
|
|
|
/*
|
|
|
|
* Created by Phil on 18/10/2010.
|
|
|
|
* Copyright 2010 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_HPP_INCLUDED
|
|
|
|
#define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|
|
|
|
|
2014-05-28 19:53:01 +02:00
|
|
|
#include "catch_result_builder.h"
|
2013-02-02 20:58:04 +01:00
|
|
|
#include "catch_message.h"
|
2011-01-11 10:13:31 +01:00
|
|
|
#include "catch_interfaces_capture.h"
|
2013-12-03 19:52:41 +01:00
|
|
|
#include "catch_debugger.h"
|
2011-04-28 09:03:28 +02:00
|
|
|
#include "catch_common.h"
|
2014-04-23 07:51:58 +02:00
|
|
|
#include "catch_tostring.h"
|
2014-05-28 19:53:01 +02:00
|
|
|
#include "catch_interfaces_runner.h"
|
2015-03-04 08:08:53 +01:00
|
|
|
#include "catch_compiler_capabilities.h"
|
2013-04-22 09:19:17 +02:00
|
|
|
|
2012-10-29 20:55:13 +01:00
|
|
|
|
2011-02-03 21:00:46 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2014-05-28 19:53:01 +02:00
|
|
|
// In the event of a failure works out if the debugger needs to be invoked
|
|
|
|
// and/or an exception thrown and takes appropriate action.
|
|
|
|
// This needs to be done as a macro so the debugger will stop in the user
|
|
|
|
// source code rather than in Catch library code
|
|
|
|
#define INTERNAL_CATCH_REACT( resultBuilder ) \
|
|
|
|
if( resultBuilder.shouldDebugBreak() ) CATCH_BREAK_INTO_DEBUGGER(); \
|
|
|
|
resultBuilder.react();
|
|
|
|
|
2010-12-27 21:49:19 +01:00
|
|
|
|
2012-10-24 22:59:47 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2012-11-10 11:35:09 +01:00
|
|
|
#define INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ) \
|
2012-10-29 20:55:13 +01:00
|
|
|
do { \
|
2014-05-28 19:53:01 +02:00
|
|
|
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \
|
2012-10-29 20:55:13 +01:00
|
|
|
try { \
|
2016-02-29 09:01:06 +01:00
|
|
|
CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
|
2015-06-26 07:35:33 +02:00
|
|
|
( __catchResult <= expr ).endExpression(); \
|
2014-05-28 19:53:01 +02:00
|
|
|
} \
|
|
|
|
catch( ... ) { \
|
|
|
|
__catchResult.useActiveException( Catch::ResultDisposition::Normal ); \
|
2012-10-29 20:55:13 +01:00
|
|
|
} \
|
2014-05-28 19:53:01 +02:00
|
|
|
INTERNAL_CATCH_REACT( __catchResult ) \
|
2017-01-19 15:04:54 +01:00
|
|
|
} while( Catch::alwaysFalse( sizeof(expr) ) ) // expr here is never evaluated at runtime but it forces the compiler to give it a look
|
2010-11-10 00:24:00 +01:00
|
|
|
|
2012-02-10 09:30:13 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2012-11-10 11:35:09 +01:00
|
|
|
#define INTERNAL_CATCH_IF( expr, resultDisposition, macroName ) \
|
|
|
|
INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
|
2012-11-13 10:44:52 +01:00
|
|
|
if( Catch::getResultCapture().getLastResult()->succeeded() )
|
2012-02-10 09:30:13 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2012-11-10 11:35:09 +01:00
|
|
|
#define INTERNAL_CATCH_ELSE( expr, resultDisposition, macroName ) \
|
|
|
|
INTERNAL_CATCH_TEST( expr, resultDisposition, macroName ); \
|
2012-11-13 10:44:52 +01:00
|
|
|
if( !Catch::getResultCapture().getLastResult()->succeeded() )
|
2012-02-10 09:30:13 +01:00
|
|
|
|
2011-03-14 09:45:55 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2012-11-10 11:20:08 +01:00
|
|
|
#define INTERNAL_CATCH_NO_THROW( expr, resultDisposition, macroName ) \
|
2012-10-29 20:55:13 +01:00
|
|
|
do { \
|
2014-05-28 19:53:01 +02:00
|
|
|
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \
|
2012-10-29 20:55:13 +01:00
|
|
|
try { \
|
|
|
|
expr; \
|
2014-05-28 19:53:01 +02:00
|
|
|
__catchResult.captureResult( Catch::ResultWas::Ok ); \
|
2012-10-29 20:55:13 +01:00
|
|
|
} \
|
|
|
|
catch( ... ) { \
|
2014-05-28 19:53:01 +02:00
|
|
|
__catchResult.useActiveException( resultDisposition ); \
|
2012-10-29 20:55:13 +01:00
|
|
|
} \
|
2014-05-28 19:53:01 +02:00
|
|
|
INTERNAL_CATCH_REACT( __catchResult ) \
|
|
|
|
} while( Catch::alwaysFalse() )
|
2011-03-14 09:45:55 +01:00
|
|
|
|
2011-02-03 21:00:46 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-07-16 00:02:25 +02:00
|
|
|
#define INTERNAL_CATCH_THROWS( expr, resultDisposition, matcher, macroName ) \
|
2012-10-29 20:55:13 +01:00
|
|
|
do { \
|
2015-07-16 00:02:25 +02:00
|
|
|
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition, #matcher ); \
|
2014-06-05 19:11:31 +02:00
|
|
|
if( __catchResult.allowThrows() ) \
|
|
|
|
try { \
|
2014-05-28 19:53:01 +02:00
|
|
|
expr; \
|
2014-06-05 19:11:31 +02:00
|
|
|
__catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
|
|
|
|
} \
|
|
|
|
catch( ... ) { \
|
2015-07-16 00:02:25 +02:00
|
|
|
__catchResult.captureExpectedException( matcher ); \
|
2014-06-05 19:11:31 +02:00
|
|
|
} \
|
|
|
|
else \
|
2014-05-28 19:53:01 +02:00
|
|
|
__catchResult.captureResult( Catch::ResultWas::Ok ); \
|
|
|
|
INTERNAL_CATCH_REACT( __catchResult ) \
|
|
|
|
} while( Catch::alwaysFalse() )
|
2012-10-29 20:55:13 +01:00
|
|
|
|
2011-02-03 21:00:46 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2012-11-10 11:20:08 +01:00
|
|
|
#define INTERNAL_CATCH_THROWS_AS( expr, exceptionType, resultDisposition, macroName ) \
|
2012-10-29 20:55:13 +01:00
|
|
|
do { \
|
2014-05-28 19:53:01 +02:00
|
|
|
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #expr, resultDisposition ); \
|
2014-06-05 19:11:31 +02:00
|
|
|
if( __catchResult.allowThrows() ) \
|
|
|
|
try { \
|
2014-05-28 19:53:01 +02:00
|
|
|
expr; \
|
2014-06-05 19:11:31 +02:00
|
|
|
__catchResult.captureResult( Catch::ResultWas::DidntThrowException ); \
|
|
|
|
} \
|
|
|
|
catch( exceptionType ) { \
|
|
|
|
__catchResult.captureResult( Catch::ResultWas::Ok ); \
|
|
|
|
} \
|
|
|
|
catch( ... ) { \
|
|
|
|
__catchResult.useActiveException( resultDisposition ); \
|
|
|
|
} \
|
|
|
|
else \
|
2014-05-28 19:53:01 +02:00
|
|
|
__catchResult.captureResult( Catch::ResultWas::Ok ); \
|
|
|
|
INTERNAL_CATCH_REACT( __catchResult ) \
|
|
|
|
} while( Catch::alwaysFalse() )
|
2010-11-10 00:24:00 +01:00
|
|
|
|
2013-02-02 20:58:04 +01:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2013-12-13 00:02:31 +01:00
|
|
|
#ifdef CATCH_CONFIG_VARIADIC_MACROS
|
|
|
|
#define INTERNAL_CATCH_MSG( messageType, resultDisposition, macroName, ... ) \
|
|
|
|
do { \
|
2014-05-28 19:53:01 +02:00
|
|
|
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
|
2014-05-29 08:50:19 +02:00
|
|
|
__catchResult << __VA_ARGS__ + ::Catch::StreamEndStop(); \
|
2014-05-28 19:53:01 +02:00
|
|
|
__catchResult.captureResult( messageType ); \
|
|
|
|
INTERNAL_CATCH_REACT( __catchResult ) \
|
|
|
|
} while( Catch::alwaysFalse() )
|
2013-12-13 00:02:31 +01:00
|
|
|
#else
|
|
|
|
#define INTERNAL_CATCH_MSG( messageType, resultDisposition, macroName, log ) \
|
|
|
|
do { \
|
2014-05-28 19:53:01 +02:00
|
|
|
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, "", resultDisposition ); \
|
2014-05-29 08:50:19 +02:00
|
|
|
__catchResult << log + ::Catch::StreamEndStop(); \
|
2014-05-28 19:53:01 +02:00
|
|
|
__catchResult.captureResult( messageType ); \
|
|
|
|
INTERNAL_CATCH_REACT( __catchResult ) \
|
|
|
|
} while( Catch::alwaysFalse() )
|
2013-12-13 00:02:31 +01:00
|
|
|
#endif
|
2010-11-10 00:24:00 +01:00
|
|
|
|
2011-02-03 21:00:46 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2013-06-28 18:09:57 +02:00
|
|
|
#define INTERNAL_CATCH_INFO( log, macroName ) \
|
|
|
|
Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage ) = Catch::MessageBuilder( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log;
|
2013-02-02 20:58:04 +01:00
|
|
|
|
2012-03-04 12:14:21 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2012-11-10 11:20:08 +01:00
|
|
|
#define INTERNAL_CHECK_THAT( arg, matcher, resultDisposition, macroName ) \
|
2012-10-29 20:55:13 +01:00
|
|
|
do { \
|
2015-08-08 00:15:58 +02:00
|
|
|
Catch::ResultBuilder __catchResult( macroName, CATCH_INTERNAL_LINEINFO, #arg ", " #matcher, resultDisposition ); \
|
2012-10-29 20:55:13 +01:00
|
|
|
try { \
|
2015-11-05 19:10:33 +01:00
|
|
|
std::string matcherAsString = (matcher).toString(); \
|
2014-05-29 08:50:19 +02:00
|
|
|
__catchResult \
|
2014-05-28 19:53:01 +02:00
|
|
|
.setLhs( Catch::toString( arg ) ) \
|
2014-09-08 09:14:59 +02:00
|
|
|
.setRhs( matcherAsString == Catch::Detail::unprintableString ? #matcher : matcherAsString ) \
|
2014-05-28 19:53:01 +02:00
|
|
|
.setOp( "matches" ) \
|
2015-11-05 19:10:33 +01:00
|
|
|
.setResultType( (matcher).match( arg ) ); \
|
2014-05-28 19:53:01 +02:00
|
|
|
__catchResult.captureExpression(); \
|
2012-10-29 20:55:13 +01:00
|
|
|
} catch( ... ) { \
|
2014-05-28 19:53:01 +02:00
|
|
|
__catchResult.useActiveException( resultDisposition | Catch::ResultDisposition::ContinueOnFailure ); \
|
2012-10-29 20:55:13 +01:00
|
|
|
} \
|
2014-05-28 19:53:01 +02:00
|
|
|
INTERNAL_CATCH_REACT( __catchResult ) \
|
|
|
|
} while( Catch::alwaysFalse() )
|
2012-03-04 12:14:21 +01:00
|
|
|
|
2010-11-10 00:24:00 +01:00
|
|
|
#endif // TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
|