catch_run_context.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. /*
  2. * Created by Phil on 22/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_RUNNER_IMPL_HPP_INCLUDED
  9. #define TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED
  10. #include "catch_interfaces_generatortracker.h"
  11. #include "catch_interfaces_runner.h"
  12. #include "catch_interfaces_reporter.h"
  13. #include "catch_interfaces_exception.h"
  14. #include "catch_config.hpp"
  15. #include "catch_test_registry.h"
  16. #include "catch_test_case_info.h"
  17. #include "catch_capture.hpp"
  18. #include "catch_totals.h"
  19. #include "catch_test_spec.h"
  20. #include "catch_test_case_tracker.h"
  21. #include "catch_timer.h"
  22. #include "catch_assertionhandler.h"
  23. #include "catch_fatal_condition.h"
  24. #include <string>
  25. namespace Catch {
  26. struct IMutableContext;
  27. ///////////////////////////////////////////////////////////////////////////
  28. class RunContext : public IResultCapture, public IRunner {
  29. public:
  30. RunContext( RunContext const& ) = delete;
  31. RunContext& operator =( RunContext const& ) = delete;
  32. explicit RunContext( IConfigPtr const& _config, IStreamingReporterPtr&& reporter );
  33. ~RunContext() override;
  34. void testGroupStarting( std::string const& testSpec, std::size_t groupIndex, std::size_t groupsCount );
  35. void testGroupEnded( std::string const& testSpec, Totals const& totals, std::size_t groupIndex, std::size_t groupsCount );
  36. Totals runTest(TestCase const& testCase);
  37. IConfigPtr config() const;
  38. IStreamingReporter& reporter() const;
  39. public: // IResultCapture
  40. // Assertion handlers
  41. void handleExpr
  42. ( AssertionInfo const& info,
  43. ITransientExpression const& expr,
  44. AssertionReaction& reaction ) override;
  45. void handleMessage
  46. ( AssertionInfo const& info,
  47. ResultWas::OfType resultType,
  48. StringRef const& message,
  49. AssertionReaction& reaction ) override;
  50. void handleUnexpectedExceptionNotThrown
  51. ( AssertionInfo const& info,
  52. AssertionReaction& reaction ) override;
  53. void handleUnexpectedInflightException
  54. ( AssertionInfo const& info,
  55. std::string const& message,
  56. AssertionReaction& reaction ) override;
  57. void handleIncomplete
  58. ( AssertionInfo const& info ) override;
  59. void handleNonExpr
  60. ( AssertionInfo const &info,
  61. ResultWas::OfType resultType,
  62. AssertionReaction &reaction ) override;
  63. bool sectionStarted( SectionInfo const& sectionInfo, Counts& assertions ) override;
  64. void sectionEnded( SectionEndInfo const& endInfo ) override;
  65. void sectionEndedEarly( SectionEndInfo const& endInfo ) override;
  66. auto acquireGeneratorTracker( StringRef generatorName, SourceLineInfo const& lineInfo ) -> IGeneratorTracker& override;
  67. #if defined(CATCH_CONFIG_ENABLE_BENCHMARKING)
  68. void benchmarkPreparing( std::string const& name ) override;
  69. void benchmarkStarting( BenchmarkInfo const& info ) override;
  70. void benchmarkEnded( BenchmarkStats<> const& stats ) override;
  71. void benchmarkFailed( std::string const& error ) override;
  72. #endif // CATCH_CONFIG_ENABLE_BENCHMARKING
  73. void pushScopedMessage( MessageInfo const& message ) override;
  74. void popScopedMessage( MessageInfo const& message ) override;
  75. void emplaceUnscopedMessage( MessageBuilder const& builder ) override;
  76. std::string getCurrentTestName() const override;
  77. const AssertionResult* getLastResult() const override;
  78. void exceptionEarlyReported() override;
  79. void handleFatalErrorCondition( StringRef message ) override;
  80. bool lastAssertionPassed() override;
  81. void assertionPassed() override;
  82. public:
  83. // !TBD We need to do this another way!
  84. bool aborting() const final;
  85. private:
  86. void runCurrentTest( std::string& redirectedCout, std::string& redirectedCerr );
  87. void invokeActiveTestCase();
  88. void resetAssertionInfo();
  89. bool testForMissingAssertions( Counts& assertions );
  90. void assertionEnded( AssertionResult const& result );
  91. void reportExpr
  92. ( AssertionInfo const &info,
  93. ResultWas::OfType resultType,
  94. ITransientExpression const *expr,
  95. bool negated );
  96. void populateReaction( AssertionReaction& reaction );
  97. private:
  98. void handleUnfinishedSections();
  99. TestRunInfo m_runInfo;
  100. IMutableContext& m_context;
  101. TestCase const* m_activeTestCase = nullptr;
  102. ITracker* m_testCaseTracker = nullptr;
  103. Option<AssertionResult> m_lastResult;
  104. IConfigPtr m_config;
  105. Totals m_totals;
  106. IStreamingReporterPtr m_reporter;
  107. std::vector<MessageInfo> m_messages;
  108. std::vector<ScopedMessage> m_messageScopes; /* Keeps owners of so-called unscoped messages. */
  109. AssertionInfo m_lastAssertionInfo;
  110. std::vector<SectionEndInfo> m_unfinishedSections;
  111. std::vector<ITracker*> m_activeSections;
  112. TrackerContext m_trackerContext;
  113. FatalConditionHandler m_fatalConditionhandler;
  114. bool m_lastAssertionPassed = false;
  115. bool m_shouldReportUnexpected = true;
  116. bool m_includeSuccessfulResults;
  117. };
  118. void seedRng(IConfig const& config);
  119. unsigned int rngSeed();
  120. } // end namespace Catch
  121. #endif // TWOBLUECUBES_CATCH_RUNNER_IMPL_HPP_INCLUDED