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