Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
catch_assertionhandler.cpp
Go to the documentation of this file.
1/*
2 * Created by Phil on 8/8/2017.
3 * Copyright 2017 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
13#include "catch_context.h"
14#include "catch_debugger.h"
17#include "catch_run_context.h"
18
19namespace Catch {
20
21 namespace {
22 auto operator <<( std::ostream& os, ITransientExpression const& expr ) -> std::ostream& {
23 expr.streamReconstructedExpression( os );
24 return os;
25 }
26 }
27
29 : m_isNegated( isNegated )
30 {}
31
32 LazyExpression::LazyExpression( LazyExpression const& other ) : m_isNegated( other.m_isNegated ) {}
33
34 LazyExpression::operator bool() const {
35 return m_transientExpression != nullptr;
36 }
37
38 auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream& {
39 if( lazyExpr.m_isNegated )
40 os << "!";
41
42 if( lazyExpr ) {
43 if( lazyExpr.m_isNegated && lazyExpr.m_transientExpression->isBinaryExpression() )
44 os << "(" << *lazyExpr.m_transientExpression << ")";
45 else
46 os << *lazyExpr.m_transientExpression;
47 }
48 else {
49 os << "{** error - unchecked empty expression requested **}";
50 }
51 return os;
52 }
53
55 ( StringRef const& macroName,
56 SourceLineInfo const& lineInfo,
57 StringRef capturedExpression,
58 ResultDisposition::Flags resultDisposition )
59 : m_assertionInfo{ macroName, lineInfo, capturedExpression, resultDisposition },
60 m_resultCapture( getResultCapture() )
61 {}
62
64 m_resultCapture.handleExpr( m_assertionInfo, expr, m_reaction );
65 }
67 m_resultCapture.handleMessage( m_assertionInfo, resultType, message, m_reaction );
68 }
69
70 auto AssertionHandler::allowThrows() const -> bool {
71 return getCurrentContext().getConfig()->allowThrows();
72 }
73
76 if( m_reaction.shouldDebugBreak ) {
77
78 // If you find your debugger stopping you here then go one level up on the
79 // call-stack for the code that caused it (typically a failed assertion)
80
81 // (To go back to the test and change execution, jump over the throw, next)
83 }
84 if (m_reaction.shouldThrow) {
85#if !defined(CATCH_CONFIG_DISABLE_EXCEPTIONS)
87#else
88 CATCH_ERROR( "Test failure requires aborting test!" );
89#endif
90 }
91 }
93 m_completed = true;
94 }
95
99
101 m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction);
102 }
104 m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction);
105 }
106
108 m_resultCapture.handleUnexpectedExceptionNotThrown( m_assertionInfo, m_reaction );
109 }
110
112 m_resultCapture.handleNonExpr(m_assertionInfo, ResultWas::Ok, m_reaction);
113 }
114
115 // This is the overload that takes a string and infers the Equals matcher from it
116 // The more general overload, that takes any string matcher, is in catch_capture_matchers.cpp
117 void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef const& matcherString ) {
118 handleExceptionMatchExpr( handler, Matchers::Equals( str ), matcherString );
119 }
120
121} // namespace Catch
#define CATCH_BREAK_INTO_DEBUGGER()
#define CATCH_ERROR(msg)
void handleExpr(ExprLhs< T > const &expr)
AssertionHandler(StringRef const &macroName, SourceLineInfo const &lineInfo, StringRef capturedExpression, ResultDisposition::Flags resultDisposition)
void handleMessage(ResultWas::OfType resultType, StringRef const &message)
os_t os
StdString::EqualsMatcher Equals(std::string const &str, CaseSensitive::Choice caseSensitivity)
IContext & getCurrentContext()
auto operator<<(std::ostream &os, LazyExpression const &lazyExpr) -> std::ostream &
std::string translateActiveException()
void handleExceptionMatchExpr(AssertionHandler &handler, std::string const &str, StringRef const &matcherString)
IResultCapture & getResultCapture()
virtual IConfigPtr const & getConfig() const =0
virtual void handleMessage(AssertionInfo const &info, ResultWas::OfType resultType, StringRef const &message, AssertionReaction &reaction)=0
virtual void handleExpr(AssertionInfo const &info, ITransientExpression const &expr, AssertionReaction &reaction)=0
virtual void handleUnexpectedExceptionNotThrown(AssertionInfo const &info, AssertionReaction &reaction)=0
virtual void handleNonExpr(AssertionInfo const &info, ResultWas::OfType resultType, AssertionReaction &reaction)=0
virtual void handleUnexpectedInflightException(AssertionInfo const &info, std::string const &message, AssertionReaction &reaction)=0