Skip to content

Commit 227e678

Browse files
committed
fix(tests): update hook execution test to use lambda and improve mock behavior
1 parent 7d4bb7c commit 227e678

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

cucumber_cpp/library/engine/HookExecutor.cpp

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
#include <set>
1010
#include <stdexcept>
1111
#include <string>
12+
#include <utility>
1213

1314
namespace cucumber_cpp::library::engine
1415
{
@@ -26,17 +27,14 @@ namespace cucumber_cpp::library::engine
2627

2728
struct ThrowPolicy
2829
{
29-
protected:
30-
~ThrowPolicy() = default;
31-
32-
public:
30+
virtual ~ThrowPolicy() = default;
3331
virtual void Throw() const = 0;
3432
};
3533

3634
struct ThrowExceptionPolicy : ThrowPolicy
3735
{
38-
ThrowExceptionPolicy(std::string message)
39-
: message{ message }
36+
explicit ThrowExceptionPolicy(std::string message)
37+
: message{ std::move(message) }
4038
{}
4139

4240
void Throw() const override

cucumber_cpp/library/engine/test/TestHookExecutor.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,9 @@ namespace cucumber_cpp::library::engine
7777
report::test_helper::ReportForwarderMock reportHandler{ *contextManagerInstance };
7878
TestAssertionHandlerImpl assertionHandler{ *contextManagerInstance, reportHandler };
7979

80-
EXPECT_ANY_THROW(auto scope = hookExecutor->StepStart());
80+
EXPECT_ANY_THROW([this]
81+
{
82+
auto hook = hookExecutor->StepStart();
83+
}());
8184
}
8285
}

cucumber_cpp/library/engine/test/TestTestRunner.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ namespace cucumber_cpp::library::engine
8080

8181
struct TestTestRunner : testing::Test
8282
{
83-
TestExecutionMockInstance testExecutionMock;
83+
testing::StrictMock<TestExecutionMockInstance> testExecutionMock;
8484
TestRunnerImpl runner{ testExecutionMock };
8585

8686
FeatureTreeFactory featureTreeFactory;
@@ -110,6 +110,18 @@ namespace cucumber_cpp::library::engine
110110
runner.Run(features);
111111
}
112112

113+
TEST_F(TestTestRunner, DontRunEmptyFeature)
114+
{
115+
EXPECT_CALL(testExecutionMock, StartRunMock);
116+
EXPECT_CALL(testExecutionMock, StartFeatureMock).Times(0);
117+
118+
auto tmp = test_helper::TemporaryFile{ "tmpfile.feature" };
119+
tmp << "Feature: Test feature\n";
120+
features.push_back(featureTreeFactory.Create(tmp.Path(), ""));
121+
122+
runner.Run(features);
123+
}
124+
113125
TEST_F(TestTestRunner, StartFeatureContextForEveryFeature)
114126
{
115127
EXPECT_CALL(testExecutionMock, StartRunMock);

0 commit comments

Comments
 (0)