Skip to content

Commit 31041c8

Browse files
committed
chore: print summy after test run ends
1 parent 7fef3a7 commit 31041c8

File tree

6 files changed

+60
-4
lines changed

6 files changed

+60
-4
lines changed
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
@fail_feature
2+
Feature: Simple feature file
3+
Background:
4+
Given a background step
5+
6+
Scenario: A failing scenario
7+
Given a given step
8+
When a when step
9+
Then an assertion is raised
10+
Then a then step
11+
12+
Scenario: An OK scenario
13+
Given a given step
14+
When a when step
15+
Then a then step

cucumber_cpp/acceptance_test/test.bats

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -148,3 +148,9 @@ teardown() {
148148
run .build/Host/cucumber_cpp/acceptance_test/Debug/cucumber_cpp.acceptance_test run --feature cucumber_cpp/acceptance_test/features --tag "@keyword-asterisk" --report console
149149
assert_failure
150150
}
151+
152+
@test "Test passing scenario after failed scenario reports feature as failed" {
153+
run .build/Host/cucumber_cpp/acceptance_test/Debug/cucumber_cpp.acceptance_test run --feature cucumber_cpp/acceptance_test/features --tag "@fail_feature" --report console
154+
assert_failure
155+
assert_output --partial "tests : 1/2 passed"
156+
}

cucumber_cpp/library/engine/TestExecution.cpp

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

19-
TestExecution::ProgramScope::ProgramScope(HookExecutor& hookExecution)
20-
: scopedProgramHook{ hookExecution.BeforeAll() }
19+
TestExecution::ProgramScope::ProgramScope(cucumber_cpp::engine::ContextManager& contextManager, report::ReportForwarder& reportHandler, HookExecutor& hookExecution)
20+
: contextManager{ contextManager }
21+
, reportHandler{ reportHandler }
22+
, scopedProgramReport{ reportHandler.ProgramStart() }
23+
, scopedProgramHook{ hookExecution.BeforeAll() }
2124
{
2225
}
2326

@@ -66,7 +69,7 @@ namespace cucumber_cpp::library::engine
6669

6770
TestExecution::ProgramScope TestExecutionImpl::StartRun()
6871
{
69-
return ProgramScope{ hookExecution };
72+
return ProgramScope{ contextManager, reportHandler, hookExecution };
7073
}
7174

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

cucumber_cpp/library/engine/TestExecution.hpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,13 @@ namespace cucumber_cpp::library::engine
3535

3636
struct TestExecution::ProgramScope : library::util::Immoveable
3737
{
38-
ProgramScope(HookExecutor& hookExecution);
38+
ProgramScope(cucumber_cpp::engine::ContextManager& contextManager, report::ReportForwarder& reportHandler, HookExecutor& hookExecution);
3939

4040
private:
41+
cucumber_cpp::engine::ContextManager& contextManager;
42+
report::ReportForwarder& reportHandler;
43+
44+
report::ReportForwarder::ProgramScope scopedProgramReport;
4145
HookExecutor::ProgramScope scopedProgramHook;
4246
};
4347

cucumber_cpp/library/report/Report.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,16 @@ namespace cucumber_cpp::report
5353
return reporters;
5454
}
5555

56+
ReportForwarder::ProgramScope::ProgramScope(cucumber_cpp::engine::ProgramContext& programContext, std::vector<std::unique_ptr<ReportHandlerV2>>& reporters)
57+
: programContext{ programContext }
58+
, reporters{ reporters }
59+
{}
60+
61+
ReportForwarder::ProgramScope::~ProgramScope()
62+
{
63+
ForwardCall(reporters, &ReportHandlerV2::Summary, programContext.Duration());
64+
}
65+
5666
ReportForwarder::FeatureScope::FeatureScope(cucumber_cpp::engine::FeatureContext& featureContext, std::vector<std::unique_ptr<ReportHandlerV2>>& reporters)
5767
: featureContext{ featureContext }
5868
, reporters{ reporters }
@@ -105,6 +115,11 @@ namespace cucumber_cpp::report
105115
: contextManager{ contextManager }
106116
{}
107117

118+
[[nodiscard]] ReportForwarder::ProgramScope ReportForwarderImpl::ProgramStart()
119+
{
120+
return ProgramScope{ contextManager.ProgramContext(), Storage() };
121+
}
122+
108123
ReportForwarder::FeatureScope ReportForwarderImpl::FeatureStart()
109124
{
110125
return FeatureScope{ contextManager.FeatureContext(), Storage() };

cucumber_cpp/library/report/Report.hpp

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,13 @@ namespace cucumber_cpp::report
6868

6969
struct ReportForwarder
7070
{
71+
struct ProgramScope;
7172
struct FeatureScope;
7273
struct RuleScope;
7374
struct ScenarioScope;
7475
struct StepScope;
7576

77+
[[nodiscard]] virtual ProgramScope ProgramStart() = 0;
7678
[[nodiscard]] virtual FeatureScope FeatureStart() = 0;
7779
[[nodiscard]] virtual RuleScope RuleStart() = 0;
7880
[[nodiscard]] virtual ScenarioScope ScenarioStart() = 0;
@@ -88,6 +90,16 @@ namespace cucumber_cpp::report
8890
virtual void Summary(TraceTime::Duration duration) = 0;
8991
};
9092

93+
struct ReportForwarder::ProgramScope
94+
{
95+
ProgramScope(cucumber_cpp::engine::ProgramContext& programContext, std::vector<std::unique_ptr<ReportHandlerV2>>& reporters);
96+
~ProgramScope();
97+
98+
private:
99+
cucumber_cpp::engine::ProgramContext& programContext;
100+
std::vector<std::unique_ptr<ReportHandlerV2>>& reporters;
101+
};
102+
91103
struct ReportForwarder::FeatureScope
92104
{
93105
FeatureScope(cucumber_cpp::engine::FeatureContext& featureContext, std::vector<std::unique_ptr<ReportHandlerV2>>& reporters);
@@ -134,6 +146,7 @@ namespace cucumber_cpp::report
134146
{
135147
explicit ReportForwarderImpl(cucumber_cpp::engine::ContextManager& contextManager);
136148

149+
[[nodiscard]] ProgramScope ProgramStart() override;
137150
[[nodiscard]] FeatureScope FeatureStart() override;
138151
[[nodiscard]] RuleScope RuleStart() override;
139152
[[nodiscard]] ScenarioScope ScenarioStart() override;

0 commit comments

Comments
 (0)