Skip to content

Commit a9deac4

Browse files
committed
feat: add CurrentContext method to ScopedFeatureContext and ExecutionStatus methods to ProgramScope and FeatureScope
1 parent cad3e4f commit a9deac4

File tree

5 files changed

+35
-4
lines changed

5 files changed

+35
-4
lines changed

cucumber_cpp/library/engine/ContextManager.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,11 @@ namespace cucumber_cpp::library::engine
114114
contextManager.DisposeFeatureContext();
115115
}
116116

117+
const cucumber_cpp::library::engine::CurrentContext& ContextManager::ScopedFeatureContext::CurrentContext() const
118+
{
119+
return contextManager.FeatureContext();
120+
}
121+
117122
ContextManager::ScopedRuleContext::ScopedRuleContext(ContextManager& contextManager)
118123
: contextManager{ contextManager }
119124
{}

cucumber_cpp/library/engine/ContextManager.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,8 @@ namespace cucumber_cpp::library::engine
124124
explicit ScopedFeatureContext(ContextManager& contextManager);
125125
~ScopedFeatureContext();
126126

127+
const cucumber_cpp::library::engine::CurrentContext& CurrentContext() const;
128+
127129
private:
128130
ContextManager& contextManager;
129131
};

cucumber_cpp/library/engine/TestExecution.cpp

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,30 @@ namespace cucumber_cpp::library::engine
1616
const DryRunPolicy dryRunPolicy;
1717
const ExecuteRunPolicy executeRunPolicy;
1818

19-
TestExecution::ProgramScope::ProgramScope(report::ReportForwarder& reportHandler, HookExecutor& hookExecution)
20-
: scopedProgramReport{ reportHandler.ProgramStart() }
19+
TestExecution::ProgramScope::ProgramScope(cucumber_cpp::library::engine::ContextManager& contextManager, report::ReportForwarder& reportHandler, HookExecutor& hookExecution)
20+
: contextManager{ contextManager }
21+
, scopedProgramReport{ reportHandler.ProgramStart() }
2122
, scopedProgramHook{ hookExecution.BeforeAll() }
2223
{
2324
}
2425

26+
Result TestExecution::ProgramScope::ExecutionStatus() const
27+
{
28+
return contextManager.ProgramContext().ExecutionStatus();
29+
}
30+
2531
TestExecution::FeatureScope::FeatureScope(cucumber_cpp::library::engine::ContextManager& contextManager, report::ReportForwarder& reportHandler, HookExecutor& hookExecution, const cucumber_cpp::library::engine::FeatureInfo& featureInfo)
2632
: scopedFeatureContext{ contextManager.CreateFeatureContext(featureInfo) }
2733
, scopedFeatureReport{ reportHandler.FeatureStart() }
2834
, scopedFeatureHook{ hookExecution.FeatureStart() }
2935
{
3036
}
3137

38+
Result TestExecution::FeatureScope::ExecutionStatus() const
39+
{
40+
return scopedFeatureContext.CurrentContext().ExecutionStatus();
41+
}
42+
3243
TestExecution::RuleScope::RuleScope(cucumber_cpp::library::engine::ContextManager& contextManager, report::ReportForwarder& reportHandler, const cucumber_cpp::library::engine::RuleInfo& ruleInfo)
3344
: scopedRuleContext{ contextManager.CreateRuleContext(ruleInfo) }
3445
, scopedRuleReport{ reportHandler.RuleStart() }
@@ -64,7 +75,7 @@ namespace cucumber_cpp::library::engine
6475

6576
TestExecution::ProgramScope TestExecutionImpl::StartRun()
6677
{
67-
return ProgramScope{ reportHandler, hookExecution };
78+
return ProgramScope{ contextManager, reportHandler, hookExecution };
6879
}
6980

7081
TestExecution::FeatureScope TestExecutionImpl::StartFeature(const cucumber_cpp::library::engine::FeatureInfo& featureInfo)

cucumber_cpp/library/engine/TestExecution.hpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "cucumber_cpp/library/engine/FailureHandler.hpp"
77
#include "cucumber_cpp/library/engine/FeatureInfo.hpp"
88
#include "cucumber_cpp/library/engine/HookExecutor.hpp"
9+
#include "cucumber_cpp/library/engine/Result.hpp"
910
#include "cucumber_cpp/library/engine/RuleInfo.hpp"
1011
#include "cucumber_cpp/library/engine/ScenarioInfo.hpp"
1112
#include "cucumber_cpp/library/engine/StepInfo.hpp"
@@ -40,9 +41,12 @@ namespace cucumber_cpp::library::engine
4041

4142
struct TestExecution::ProgramScope : library::util::Immoveable
4243
{
43-
ProgramScope(report::ReportForwarder& reportHandler, HookExecutor& hookExecution);
44+
ProgramScope(cucumber_cpp::library::engine::ContextManager& contextManager, report::ReportForwarder& reportHandler, HookExecutor& hookExecution);
45+
46+
Result ExecutionStatus() const;
4447

4548
private:
49+
cucumber_cpp::library::engine::ContextManager& contextManager;
4650
report::ReportForwarder::ProgramScope scopedProgramReport;
4751
HookExecutor::ProgramScope scopedProgramHook;
4852
};
@@ -51,6 +55,8 @@ namespace cucumber_cpp::library::engine
5155
{
5256
FeatureScope(cucumber_cpp::library::engine::ContextManager& contextManager, report::ReportForwarder& reportHandler, HookExecutor& hookExecution, const cucumber_cpp::library::engine::FeatureInfo& featureInfo);
5357

58+
Result ExecutionStatus() const;
59+
5460
private:
5561
cucumber_cpp::library::engine::ContextManager::ScopedFeatureContext scopedFeatureContext;
5662
report::ReportForwarder::FeatureScope scopedFeatureReport;

cucumber_cpp/library/engine/TestRunner.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#include "cucumber_cpp/library/engine/TestRunner.hpp"
33
#include "cucumber_cpp/library/engine/FeatureFactory.hpp"
44
#include "cucumber_cpp/library/engine/FeatureInfo.hpp"
5+
#include "cucumber_cpp/library/engine/Result.hpp"
56
#include "cucumber_cpp/library/engine/RuleInfo.hpp"
67
#include "cucumber_cpp/library/engine/StepInfo.hpp"
78
#include "cucumber_cpp/library/engine/StepType.hpp"
@@ -40,6 +41,9 @@ namespace cucumber_cpp::library::engine
4041
{
4142
auto scope = testExecution.StartRun();
4243

44+
if (scope.ExecutionStatus() != Result::passed)
45+
return;
46+
4347
for (const auto& featurePtr : features)
4448
RunFeature(*featurePtr);
4549
}
@@ -57,6 +61,9 @@ namespace cucumber_cpp::library::engine
5761

5862
const auto featureScope = testExecution.StartFeature(feature);
5963

64+
if (featureScope.ExecutionStatus() != Result::passed)
65+
return;
66+
6067
RunRules(feature.Rules());
6168
RunScenarios(feature.Scenarios());
6269
}

0 commit comments

Comments
 (0)