Skip to content

Commit 3dc0c50

Browse files
committed
refactor(hooks): simplify hook execution by removing throw policies
1 parent 87f451a commit 3dc0c50

File tree

1 file changed

+3
-37
lines changed

1 file changed

+3
-37
lines changed

cucumber_cpp/library/engine/HookExecutor.cpp

Lines changed: 3 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,7 @@ namespace cucumber_cpp::library::engine
2020
constexpr HookPair scenarioHooks{ HookType::before, HookType::after };
2121
constexpr HookPair stepHooks{ HookType::beforeStep, HookType::afterStep };
2222

23-
struct HookFailed : std::runtime_error
24-
{
25-
using runtime_error::runtime_error;
26-
};
27-
28-
struct ThrowPolicy
29-
{
30-
virtual ~ThrowPolicy() = default;
31-
virtual void Throw() const = 0;
32-
};
33-
34-
struct ThrowExceptionPolicy : ThrowPolicy
35-
{
36-
explicit ThrowExceptionPolicy(std::string message)
37-
: message{ std::move(message) }
38-
{}
39-
40-
void Throw() const override
41-
{
42-
throw HookFailed{ message };
43-
}
44-
45-
private:
46-
std::string message;
47-
};
48-
49-
struct NoThrowExceptionPolicy : ThrowPolicy
50-
{
51-
void Throw() const override
52-
{
53-
// No exception thrown
54-
}
55-
};
56-
57-
void ExecuteHook(cucumber_cpp::library::engine::RunnerContext& runnerContext, HookType hook, const std::set<std::string, std::less<>>& tags, const ThrowPolicy& throwPolicy)
23+
void ExecuteHook(cucumber_cpp::library::engine::RunnerContext& runnerContext, HookType hook, const std::set<std::string, std::less<>>& tags)
5824
{
5925
if (runnerContext.InheritedExecutionStatus() == Result::passed)
6026
for (const auto& match : HookRegistry::Instance().Query(hook, tags))
@@ -72,12 +38,12 @@ namespace cucumber_cpp::library::engine
7238
, hookPair{ hookPair }
7339
, tags{ tags }
7440
{
75-
ExecuteHook(runnerContext, hookPair.before, tags, ThrowExceptionPolicy{ "Hook failed" });
41+
ExecuteHook(runnerContext, hookPair.before, tags);
7642
}
7743

7844
HookExecutor::ScopedHook::~ScopedHook()
7945
{
80-
ExecuteHook(runnerContext, hookPair.after, tags, NoThrowExceptionPolicy{});
46+
ExecuteHook(runnerContext, hookPair.after, tags);
8147
}
8248

8349
HookExecutor::ProgramScope::ProgramScope(cucumber_cpp::library::engine::ContextManager& contextManager)

0 commit comments

Comments
 (0)