catch_assertionhandler.h 2.7 KB

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