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