Skip to content

Commit cad3e4f

Browse files
committed
chore: only execute hooks when there was no failure previously
1 parent 3bd22fd commit cad3e4f

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

cucumber_cpp/library/engine/HookExecutor.cpp

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,28 +23,30 @@ namespace cucumber_cpp::library::engine
2323

2424
void ExecuteHook(cucumber_cpp::library::engine::RunnerContext& runnerContext, HookType hook, const std::set<std::string, std::less<>>& tags)
2525
{
26-
if (runnerContext.InheritedExecutionStatus() == Result::passed)
27-
for (const auto& match : HookRegistry::Instance().Query(hook, tags))
28-
{
29-
match.factory(runnerContext)->Execute();
26+
for (const auto& match : HookRegistry::Instance().Query(hook, tags))
27+
{
28+
match.factory(runnerContext)->Execute();
3029

31-
if (runnerContext.ExecutionStatus() != cucumber_cpp::library::engine::Result::passed)
32-
return;
33-
}
30+
if (runnerContext.ExecutionStatus() != cucumber_cpp::library::engine::Result::passed)
31+
return;
32+
}
3433
}
3534
}
3635

3736
HookExecutor::ScopedHook::ScopedHook(cucumber_cpp::library::engine::RunnerContext& runnerContext, HookPair hookPair, const std::set<std::string, std::less<>>& tags)
3837
: runnerContext{ runnerContext }
3938
, hookPair{ hookPair }
4039
, tags{ tags }
40+
, executeHooks{ runnerContext.InheritedExecutionStatus() == Result::passed }
4141
{
42-
ExecuteHook(runnerContext, hookPair.before, tags);
42+
if (executeHooks)
43+
ExecuteHook(runnerContext, hookPair.before, tags);
4344
}
4445

4546
HookExecutor::ScopedHook::~ScopedHook()
4647
{
47-
ExecuteHook(runnerContext, hookPair.after, tags);
48+
if (executeHooks)
49+
ExecuteHook(runnerContext, hookPair.after, tags);
4850
}
4951

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

cucumber_cpp/library/engine/HookExecutor.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +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 };
5051
};
5152

5253
struct HookExecutor::ProgramScope : private ScopedHook

0 commit comments

Comments
 (0)