Skip to content

Commit bbc91f1

Browse files
committed
chore: remove unneccsary complexity
1 parent a9deac4 commit bbc91f1

File tree

11 files changed

+53
-95
lines changed

11 files changed

+53
-95
lines changed

cucumber_cpp/acceptance_test/test.bats

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,9 +181,9 @@ teardown() {
181181
@test "Test error program hook results in error and skipped steps" {
182182
run .build/Host/cucumber_cpp/acceptance_test/Debug/cucumber_cpp.acceptance_test.custom run --feature cucumber_cpp/acceptance_test/features --tag "@smoke and @result:OK" --report console --required --failprogramhook
183183
assert_failure
184-
assert_output --partial "skipped Given a given step"
184+
refute_output --partial "skipped Given a given step"
185185
refute_output --partial "should not be executed"
186-
assert_output --partial "tests : 0/1 passed"
186+
assert_output --partial "tests : 0/0 passed"
187187
}
188188

189189
@test "Test unicode" {

cucumber_cpp/library/Application.cpp

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <ranges>
2929
#include <string>
3030
#include <string_view>
31+
#include <type_traits>
3132
#include <utility>
3233
#include <vector>
3334

@@ -195,13 +196,10 @@ namespace cucumber_cpp::library
195196

196197
auto tagExpression = Join(options.tags, " ");
197198
engine::HookExecutorImpl hookExecution{ contextManager };
198-
engine::TestExecutionImpl testExecution{ contextManager, reporters, hookExecution, [this]() -> const engine::TestExecution::Policy&
199-
{
200-
if (options.dryrun)
201-
return engine::dryRunPolicy;
202-
else
203-
return engine::executeRunPolicy;
204-
}() };
199+
200+
const auto& runPolicy = (options.dryrun) ? static_cast<const engine::TestExecution::Policy&>(engine::dryRunPolicy)
201+
: static_cast<const engine::TestExecution::Policy&>(engine::executeRunPolicy);
202+
engine::TestExecutionImpl testExecution{ contextManager, reporters, hookExecution, runPolicy };
205203

206204
StepRegistry stepRegistry{ parameterRegistry };
207205
engine::FeatureTreeFactory featureTreeFactory{ stepRegistry };
@@ -229,10 +227,8 @@ namespace cucumber_cpp::library
229227

230228
int Application::GetExitCode() const
231229
{
232-
if (contextManager.ProgramContext().EffectiveExecutionStatus() == engine::Result::passed)
233-
return 0;
234-
else
235-
return 1;
230+
const auto result = static_cast<std::underlying_type_t<engine::Result>>(contextManager.ProgramContext().ExecutionStatus());
231+
return result - static_cast<std::underlying_type_t<engine::Result>>(engine::Result::passed);
236232
}
237233

238234
}

cucumber_cpp/library/engine/ContextManager.cpp

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
#include "cucumber_cpp/library/engine/RuleInfo.hpp"
66
#include "cucumber_cpp/library/engine/ScenarioInfo.hpp"
77
#include "cucumber_cpp/library/engine/StepInfo.hpp"
8-
#include <algorithm>
98
#include <memory>
109
#include <string>
1110
#include <string_view>
@@ -49,29 +48,11 @@ namespace cucumber_cpp::library::engine
4948
Start();
5049
}
5150

52-
[[nodiscard]] Result CurrentContext::InheritedExecutionStatus() const
53-
{
54-
if (parent == nullptr)
55-
return executionStatus;
56-
else
57-
return std::max(executionStatus, parent->InheritedExecutionStatus());
58-
}
59-
60-
[[nodiscard]] Result CurrentContext::EffectiveExecutionStatus() const
61-
{
62-
return std::max(executionStatus, nestedExecutionStatus);
63-
}
64-
6551
[[nodiscard]] Result CurrentContext::ExecutionStatus() const
6652
{
6753
return executionStatus;
6854
}
6955

70-
[[nodiscard]] Result CurrentContext::NestedExecutionStatus() const
71-
{
72-
return nestedExecutionStatus;
73-
}
74-
7556
void CurrentContext::Start()
7657
{
7758
traceTime.Start();
@@ -88,16 +69,7 @@ namespace cucumber_cpp::library::engine
8869
executionStatus = result;
8970

9071
if (parent != nullptr)
91-
parent->NestedExecutionStatus(result);
92-
}
93-
94-
void CurrentContext::NestedExecutionStatus(Result result)
95-
{
96-
if (result > nestedExecutionStatus)
97-
nestedExecutionStatus = result;
98-
99-
if (parent != nullptr)
100-
parent->NestedExecutionStatus(result);
72+
parent->ExecutionStatus(result);
10173
}
10274

10375
ProgramContext::ProgramContext(std::shared_ptr<ContextStorageFactory> contextStorageFactory)

cucumber_cpp/library/engine/ContextManager.hpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,7 @@ namespace cucumber_cpp::library::engine
1919
explicit CurrentContext(std::shared_ptr<ContextStorageFactory> contextStorageFactory);
2020
explicit CurrentContext(CurrentContext* parent);
2121

22-
[[nodiscard]] Result InheritedExecutionStatus() const;
23-
[[nodiscard]] Result EffectiveExecutionStatus() const;
2422
[[nodiscard]] Result ExecutionStatus() const;
25-
[[nodiscard]] Result NestedExecutionStatus() const;
2623

2724
void Start();
2825
[[nodiscard]] TraceTime::Duration Duration() const;
@@ -31,12 +28,9 @@ namespace cucumber_cpp::library::engine
3128
void ExecutionStatus(Result result);
3229

3330
private:
34-
void NestedExecutionStatus(Result result);
35-
3631
CurrentContext* parent{ nullptr };
3732

3833
Result executionStatus{ Result::passed };
39-
Result nestedExecutionStatus{ Result::passed };
4034
TraceTime traceTime;
4135
};
4236

@@ -57,10 +51,7 @@ namespace cucumber_cpp::library::engine
5751
NestedContext(RunnerContext& parent, const T& info)
5852
: RunnerContext{ &parent }
5953
, info{ info }
60-
{
61-
if (parent.InheritedExecutionStatus() != Result::passed)
62-
ExecutionStatus(Result::skipped);
63-
}
54+
{}
6455

6556
const T& info;
6657
};

cucumber_cpp/library/engine/HookExecutor.cpp

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,21 @@ namespace cucumber_cpp::library::engine
3737
: runnerContext{ runnerContext }
3838
, hookPair{ hookPair }
3939
, tags{ tags }
40-
, executeHooks{ runnerContext.InheritedExecutionStatus() == Result::passed }
40+
// , executeHooks{ runnerContext.InheritedExecutionStatus() == Result::passed }
4141
{
42-
if (executeHooks)
43-
ExecuteHook(runnerContext, hookPair.before, tags);
42+
// if (executeHooks)
43+
ExecuteHook(runnerContext, hookPair.before, tags);
4444
}
4545

4646
HookExecutor::ScopedHook::~ScopedHook()
4747
{
48-
if (executeHooks)
49-
ExecuteHook(runnerContext, hookPair.after, tags);
48+
// if (executeHooks)
49+
ExecuteHook(runnerContext, hookPair.after, tags);
5050
}
5151

5252
HookExecutor::ProgramScope::ProgramScope(cucumber_cpp::library::engine::ContextManager& contextManager)
5353
: ScopedHook{ contextManager.ProgramContext(), programHooks, {} }
54-
{
55-
}
54+
{}
5655

5756
HookExecutor::FeatureScope::FeatureScope(cucumber_cpp::library::engine::ContextManager& contextManager)
5857
: ScopedHook{ contextManager.FeatureContext(), featureHooks, contextManager.FeatureContext().info.Tags() }
@@ -75,18 +74,14 @@ namespace cucumber_cpp::library::engine
7574
return ProgramScope{ contextManager };
7675
}
7776

78-
std::optional<HookExecutor::FeatureScope> HookExecutorImpl::FeatureStart()
77+
HookExecutor::FeatureScope HookExecutorImpl::FeatureStart()
7978
{
80-
if (contextManager.FeatureContext().InheritedExecutionStatus() != Result::passed)
81-
return std::nullopt;
82-
return std::make_optional<FeatureScope>(contextManager);
79+
return FeatureScope{ contextManager };
8380
}
8481

85-
std::optional<HookExecutor::ScenarioScope> HookExecutorImpl::ScenarioStart()
82+
HookExecutor::ScenarioScope HookExecutorImpl::ScenarioStart()
8683
{
87-
if (contextManager.ScenarioContext().InheritedExecutionStatus() != Result::passed)
88-
return std::nullopt;
89-
return std::make_optional<ScenarioScope>(contextManager);
84+
return ScenarioScope{ contextManager };
9085
}
9186

9287
HookExecutor::StepScope HookExecutorImpl::StepStart()

cucumber_cpp/library/engine/HookExecutor.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ namespace cucumber_cpp::library::engine
2424
struct StepScope;
2525

2626
[[nodiscard]] virtual ProgramScope BeforeAll() = 0;
27-
[[nodiscard]] virtual std::optional<FeatureScope> FeatureStart() = 0;
28-
[[nodiscard]] virtual std::optional<ScenarioScope> ScenarioStart() = 0;
27+
[[nodiscard]] virtual FeatureScope FeatureStart() = 0;
28+
[[nodiscard]] virtual ScenarioScope ScenarioStart() = 0;
2929
[[nodiscard]] virtual StepScope StepStart() = 0;
3030

3131
private:
@@ -47,7 +47,7 @@ namespace cucumber_cpp::library::engine
4747
cucumber_cpp::library::engine::RunnerContext& runnerContext;
4848
HookPair hookPair;
4949
const std::set<std::string, std::less<>>& tags;
50-
bool executeHooks{ true };
50+
// bool executeHooks{ true };
5151
};
5252

5353
struct HookExecutor::ProgramScope : private ScopedHook
@@ -77,8 +77,8 @@ namespace cucumber_cpp::library::engine
7777

7878
[[nodiscard]] ProgramScope
7979
BeforeAll() override;
80-
[[nodiscard]] std::optional<FeatureScope> FeatureStart() override;
81-
[[nodiscard]] std::optional<ScenarioScope> ScenarioStart() override;
80+
[[nodiscard]] FeatureScope FeatureStart() override;
81+
[[nodiscard]] ScenarioScope ScenarioStart() override;
8282
[[nodiscard]] StepScope StepStart() override;
8383

8484
private:

cucumber_cpp/library/engine/TestExecution.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,7 @@ namespace cucumber_cpp::library::engine
9696
void TestExecutionImpl::RunStep(const cucumber_cpp::library::engine::StepInfo& stepInfo)
9797
{
9898
auto scopedContext = contextManager.CreateStepContext(stepInfo);
99-
if (contextManager.ScenarioContext().InheritedExecutionStatus() == Result::passed &&
100-
contextManager.ScenarioContext().EffectiveExecutionStatus() == Result::passed)
99+
if (contextManager.ScenarioContext().ExecutionStatus() == Result::passed)
101100
{
102101
const auto scopedStepReport = reportHandler.StepStart();
103102
const auto scopedStepHook = hookExecution.StepStart();

cucumber_cpp/library/engine/TestExecution.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ namespace cucumber_cpp::library::engine
6060
private:
6161
cucumber_cpp::library::engine::ContextManager::ScopedFeatureContext scopedFeatureContext;
6262
report::ReportForwarder::FeatureScope scopedFeatureReport;
63-
std::optional<HookExecutor::FeatureScope> scopedFeatureHook;
63+
HookExecutor::FeatureScope scopedFeatureHook;
6464
};
6565

6666
struct TestExecution::RuleScope : library::util::Immoveable
@@ -79,7 +79,7 @@ namespace cucumber_cpp::library::engine
7979
private:
8080
cucumber_cpp::library::engine::ContextManager::ScopedScenarioContext scopedScenarioContext;
8181
report::ReportForwarder::ScenarioScope scopedScenarioReport;
82-
std::optional<HookExecutor::ScenarioScope> scopedScenarioHook;
82+
HookExecutor::ScenarioScope scopedScenarioHook;
8383
};
8484

8585
struct TestExecution::Policy

cucumber_cpp/library/engine/test/TestFailureHandler.cpp

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -36,21 +36,21 @@ namespace cucumber_cpp::library::engine
3636

3737
TEST_F(TestFailureHandler, SetContextToFailed)
3838
{
39-
ASSERT_THAT(contextManager.CurrentContext().EffectiveExecutionStatus(), testing::Eq(Result::passed));
40-
ASSERT_THAT(contextManager.ProgramContext().EffectiveExecutionStatus(), testing::Eq(Result::passed));
41-
ASSERT_THAT(contextManager.FeatureContext().EffectiveExecutionStatus(), testing::Eq(Result::passed));
42-
ASSERT_THAT(contextManager.RuleContext().EffectiveExecutionStatus(), testing::Eq(Result::passed));
43-
ASSERT_THAT(contextManager.ScenarioContext().EffectiveExecutionStatus(), testing::Eq(Result::passed));
44-
ASSERT_THAT(contextManager.StepContext().EffectiveExecutionStatus(), testing::Eq(Result::passed));
39+
ASSERT_THAT(contextManager.CurrentContext().ExecutionStatus(), testing::Eq(Result::passed));
40+
ASSERT_THAT(contextManager.ProgramContext().ExecutionStatus(), testing::Eq(Result::passed));
41+
ASSERT_THAT(contextManager.FeatureContext().ExecutionStatus(), testing::Eq(Result::passed));
42+
ASSERT_THAT(contextManager.RuleContext().ExecutionStatus(), testing::Eq(Result::passed));
43+
ASSERT_THAT(contextManager.ScenarioContext().ExecutionStatus(), testing::Eq(Result::passed));
44+
ASSERT_THAT(contextManager.StepContext().ExecutionStatus(), testing::Eq(Result::passed));
4545

4646
ErrorWithFailureMessage("failure");
4747

48-
EXPECT_THAT(contextManager.CurrentContext().EffectiveExecutionStatus(), testing::Eq(Result::failed));
49-
EXPECT_THAT(contextManager.ProgramContext().EffectiveExecutionStatus(), testing::Eq(Result::failed));
50-
EXPECT_THAT(contextManager.FeatureContext().EffectiveExecutionStatus(), testing::Eq(Result::failed));
51-
EXPECT_THAT(contextManager.RuleContext().EffectiveExecutionStatus(), testing::Eq(Result::failed));
52-
EXPECT_THAT(contextManager.ScenarioContext().EffectiveExecutionStatus(), testing::Eq(Result::failed));
53-
EXPECT_THAT(contextManager.StepContext().EffectiveExecutionStatus(), testing::Eq(Result::failed));
48+
EXPECT_THAT(contextManager.CurrentContext().ExecutionStatus(), testing::Eq(Result::failed));
49+
EXPECT_THAT(contextManager.ProgramContext().ExecutionStatus(), testing::Eq(Result::failed));
50+
EXPECT_THAT(contextManager.FeatureContext().ExecutionStatus(), testing::Eq(Result::failed));
51+
EXPECT_THAT(contextManager.RuleContext().ExecutionStatus(), testing::Eq(Result::failed));
52+
EXPECT_THAT(contextManager.ScenarioContext().ExecutionStatus(), testing::Eq(Result::failed));
53+
EXPECT_THAT(contextManager.StepContext().ExecutionStatus(), testing::Eq(Result::failed));
5454
}
5555

5656
TEST_F(TestFailureHandler, ReportFailureMessage)

cucumber_cpp/library/engine/test/TestTestRunner.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,11 @@ namespace cucumber_cpp::library::engine
216216

217217
features.push_back(featureTreeFactory.Create(tmp.Path(), ""));
218218

219-
ASSERT_THAT(contextManager.ProgramContext().EffectiveExecutionStatus(), testing::Eq(Result::passed));
219+
ASSERT_THAT(contextManager.ProgramContext().ExecutionStatus(), testing::Eq(Result::passed));
220220

221221
runner.Run(features);
222222

223-
ASSERT_THAT(contextManager.ProgramContext().EffectiveExecutionStatus(), testing::Eq(Result::passed));
223+
ASSERT_THAT(contextManager.ProgramContext().ExecutionStatus(), testing::Eq(Result::passed));
224224
}
225225

226226
TEST_F(TestTestRunner, TestExceptionContinuesWithNextScenario)
@@ -240,13 +240,13 @@ namespace cucumber_cpp::library::engine
240240

241241
features.push_back(featureTreeFactory.Create(tmp.Path(), ""));
242242

243-
ASSERT_THAT(contextManager.ProgramContext().EffectiveExecutionStatus(), testing::Eq(Result::passed));
243+
ASSERT_THAT(contextManager.ProgramContext().ExecutionStatus(), testing::Eq(Result::passed));
244244

245245
testing::internal::CaptureStdout();
246246
runner.Run(features);
247247
const auto stdoutString = testing::internal::GetCapturedStdout();
248248

249-
EXPECT_THAT(contextManager.ProgramContext().EffectiveExecutionStatus(), testing::Eq(Result::failed));
249+
EXPECT_THAT(contextManager.ProgramContext().ExecutionStatus(), testing::Eq(Result::failed));
250250

251251
EXPECT_THAT(stdoutString, testing::HasSubstr("Exception thrown"));
252252
EXPECT_THAT(stdoutString, testing::Not(testing::HasSubstr("Should Not Be Thrown")));

0 commit comments

Comments
 (0)