Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
catch_capture.hpp
Go to the documentation of this file.
1/*
2 * Created by Phil on 18/10/2010.
3 * Copyright 2010 Two Blue Cubes Ltd. All rights reserved.
4 *
5 * Distributed under the Boost Software License, Version 1.0. (See accompanying
6 * file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
7 */
8#ifndef TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
9#define TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED
10
13#include "catch_message.h"
14#include "catch_stringref.h"
15
16#if !defined(CATCH_CONFIG_DISABLE)
17
18#if !defined(CATCH_CONFIG_DISABLE_STRINGIFICATION)
19 #define CATCH_INTERNAL_STRINGIFY(...) #__VA_ARGS__
20#else
21 #define CATCH_INTERNAL_STRINGIFY(...) "Disabled by CATCH_CONFIG_DISABLE_STRINGIFICATION"
22#endif
23
24#if defined(CATCH_CONFIG_FAST_COMPILE) || defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
25
27// Another way to speed-up compilation is to omit local try-catch for REQUIRE*
28// macros.
29#define INTERNAL_CATCH_TRY
30#define INTERNAL_CATCH_CATCH( capturer )
31
32#else // CATCH_CONFIG_FAST_COMPILE
33
34#define INTERNAL_CATCH_TRY try
35#define INTERNAL_CATCH_CATCH( handler ) catch(...) { handler.handleUnexpectedInflightException(); }
36
37#endif
38
39#define INTERNAL_CATCH_REACT( handler ) handler.complete();
40
42#define INTERNAL_CATCH_TEST( macroName, resultDisposition, ... ) \
43 do { \
44 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
45 INTERNAL_CATCH_TRY { \
46 CATCH_INTERNAL_SUPPRESS_PARENTHESES_WARNINGS \
47 catchAssertionHandler.handleExpr( Catch::Decomposer() <= __VA_ARGS__ ); \
48 CATCH_INTERNAL_UNSUPPRESS_PARENTHESES_WARNINGS \
49 } INTERNAL_CATCH_CATCH( catchAssertionHandler ) \
50 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
51 } while( (void)0, (false) && static_cast<bool>( !!(__VA_ARGS__) ) ) // the expression here is never evaluated at runtime but it forces the compiler to give it a look
52 // The double negation silences MSVC's C4800 warning, the static_cast forces short-circuit evaluation if the type has overloaded &&.
53
55#define INTERNAL_CATCH_IF( macroName, resultDisposition, ... ) \
56 INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
57 if( Catch::getResultCapture().lastAssertionPassed() )
58
60#define INTERNAL_CATCH_ELSE( macroName, resultDisposition, ... ) \
61 INTERNAL_CATCH_TEST( macroName, resultDisposition, __VA_ARGS__ ); \
62 if( !Catch::getResultCapture().lastAssertionPassed() )
63
65#define INTERNAL_CATCH_NO_THROW( macroName, resultDisposition, ... ) \
66 do { \
67 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition ); \
68 try { \
69 static_cast<void>(__VA_ARGS__); \
70 catchAssertionHandler.handleExceptionNotThrownAsExpected(); \
71 } \
72 catch( ... ) { \
73 catchAssertionHandler.handleUnexpectedInflightException(); \
74 } \
75 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
76 } while( false )
77
79#define INTERNAL_CATCH_THROWS( macroName, resultDisposition, ... ) \
80 do { \
81 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__), resultDisposition); \
82 if( catchAssertionHandler.allowThrows() ) \
83 try { \
84 static_cast<void>(__VA_ARGS__); \
85 catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
86 } \
87 catch( ... ) { \
88 catchAssertionHandler.handleExceptionThrownAsExpected(); \
89 } \
90 else \
91 catchAssertionHandler.handleThrowingCallSkipped(); \
92 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
93 } while( false )
94
96#define INTERNAL_CATCH_THROWS_AS( macroName, exceptionType, resultDisposition, expr ) \
97 do { \
98 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(expr) ", " CATCH_INTERNAL_STRINGIFY(exceptionType), resultDisposition ); \
99 if( catchAssertionHandler.allowThrows() ) \
100 try { \
101 static_cast<void>(expr); \
102 catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
103 } \
104 catch( exceptionType const& ) { \
105 catchAssertionHandler.handleExceptionThrownAsExpected(); \
106 } \
107 catch( ... ) { \
108 catchAssertionHandler.handleUnexpectedInflightException(); \
109 } \
110 else \
111 catchAssertionHandler.handleThrowingCallSkipped(); \
112 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
113 } while( false )
114
115
117#define INTERNAL_CATCH_MSG( macroName, messageType, resultDisposition, ... ) \
118 do { \
119 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::StringRef(), resultDisposition ); \
120 catchAssertionHandler.handleMessage( messageType, ( Catch::MessageStream() << __VA_ARGS__ + ::Catch::StreamEndStop() ).m_stream.str() ); \
121 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
122 } while( false )
123
125#define INTERNAL_CATCH_CAPTURE( varName, macroName, ... ) \
126 auto varName = Catch::Capturer( macroName, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info, #__VA_ARGS__ ); \
127 varName.captureValues( 0, __VA_ARGS__ )
128
130#define INTERNAL_CATCH_INFO( macroName, log ) \
131 Catch::ScopedMessage INTERNAL_CATCH_UNIQUE_NAME( scopedMessage )( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log );
132
134#define INTERNAL_CATCH_UNSCOPED_INFO( macroName, log ) \
135 Catch::getResultCapture().emplaceUnscopedMessage( Catch::MessageBuilder( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, Catch::ResultWas::Info ) << log )
136
138// Although this is matcher-based, it can be used with just a string
139#define INTERNAL_CATCH_THROWS_STR_MATCHES( macroName, resultDisposition, matcher, ... ) \
140 do { \
141 Catch::AssertionHandler catchAssertionHandler( macroName##_catch_sr, CATCH_INTERNAL_LINEINFO, CATCH_INTERNAL_STRINGIFY(__VA_ARGS__) ", " CATCH_INTERNAL_STRINGIFY(matcher), resultDisposition ); \
142 if( catchAssertionHandler.allowThrows() ) \
143 try { \
144 static_cast<void>(__VA_ARGS__); \
145 catchAssertionHandler.handleUnexpectedExceptionNotThrown(); \
146 } \
147 catch( ... ) { \
148 Catch::handleExceptionMatchExpr( catchAssertionHandler, matcher, #matcher##_catch_sr ); \
149 } \
150 else \
151 catchAssertionHandler.handleThrowingCallSkipped(); \
152 INTERNAL_CATCH_REACT( catchAssertionHandler ) \
153 } while( false )
154
155#endif // CATCH_CONFIG_DISABLE
156
157#endif // TWOBLUECUBES_CATCH_CAPTURE_HPP_INCLUDED