Home | History | Annotate | Download | only in internal
      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 #ifndef TWOBLUECUBES_CATCH_ASSERTIONHANDLER_H_INCLUDED
      9 #define TWOBLUECUBES_CATCH_ASSERTIONHANDLER_H_INCLUDED
     10 
     11 #include "catch_assertioninfo.h"
     12 #include "catch_decomposer.h"
     13 #include "catch_interfaces_capture.h"
     14 
     15 namespace Catch {
     16 
     17     struct TestFailureException{};
     18     struct AssertionResultData;
     19     struct IResultCapture;
     20     class RunContext;
     21 
     22     class LazyExpression {
     23         friend class AssertionHandler;
     24         friend struct AssertionStats;
     25         friend class RunContext;
     26 
     27         ITransientExpression const* m_transientExpression = nullptr;
     28         bool m_isNegated;
     29     public:
     30         LazyExpression( bool isNegated );
     31         LazyExpression( LazyExpression const& other );
     32         LazyExpression& operator = ( LazyExpression const& ) = delete;
     33 
     34         explicit operator bool() const;
     35 
     36         friend auto operator << ( std::ostream& os, LazyExpression const& lazyExpr ) -> std::ostream&;
     37     };
     38 
     39     struct AssertionReaction {
     40         bool shouldDebugBreak = false;
     41         bool shouldThrow = false;
     42     };
     43 
     44     class AssertionHandler {
     45         AssertionInfo m_assertionInfo;
     46         AssertionReaction m_reaction;
     47         bool m_completed = false;
     48         IResultCapture& m_resultCapture;
     49 
     50     public:
     51         AssertionHandler
     52             (   StringRef const& macroName,
     53                 SourceLineInfo const& lineInfo,
     54                 StringRef capturedExpression,
     55                 ResultDisposition::Flags resultDisposition );
     56         ~AssertionHandler() {
     57             if ( !m_completed ) {
     58                 m_resultCapture.handleIncomplete( m_assertionInfo );
     59             }
     60         }
     61 
     62 
     63         template<typename T>
     64         void handleExpr( ExprLhs<T> const& expr ) {
     65             handleExpr( expr.makeUnaryExpr() );
     66         }
     67         void handleExpr( ITransientExpression const& expr );
     68 
     69         void handleMessage(ResultWas::OfType resultType, StringRef const& message);
     70 
     71         void handleExceptionThrownAsExpected();
     72         void handleUnexpectedExceptionNotThrown();
     73         void handleExceptionNotThrownAsExpected();
     74         void handleThrowingCallSkipped();
     75         void handleUnexpectedInflightException();
     76 
     77         void complete();
     78         void setCompleted();
     79 
     80         // query
     81         auto allowThrows() const -> bool;
     82     };
     83 
     84     void handleExceptionMatchExpr( AssertionHandler& handler, std::string const& str, StringRef const& matcherString );
     85 
     86 } // namespace Catch
     87 
     88 #endif // TWOBLUECUBES_CATCH_ASSERTIONHANDLER_H_INCLUDED
     89