Skip to content

Commit e4d04a7

Browse files
authored
Merge branch 'main' into chore/update-cmake-configuration
2 parents edb6489 + 4a0749f commit e4d04a7

File tree

8 files changed

+103
-36
lines changed

8 files changed

+103
-36
lines changed

.vscode/settings.json

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
11
{
2-
"cmake.useCMakePresets": "always",
3-
"cucumberautocomplete.steps": [
4-
"cucumber_cpp/example/steps/*.cpp",
5-
"cucumber_cpp/acceptance_test/steps/*.cpp"
6-
],
7-
"cucumberautocomplete.gherkinDefinitionPart": "(GIVEN|WHEN|THEN|STEP)\\(",
8-
"cucumberautocomplete.customParameters": [
9-
{
10-
"parameter": "R\"(",
11-
"value": "\""
12-
},
13-
{
14-
"parameter": ")\"",
15-
"value": "\""
16-
}
17-
],
18-
"C/C++ Include Guard.Macro Type": "Filepath",
19-
"C/C++ Include Guard.Path Depth": 1,
20-
"C/C++ Include Guard.Remove Extension": false,
21-
"C/C++ Include Guard.Comment Style": "None",
22-
"C/C++ Include Guard.Path Skip": 0,
23-
"testMate.cpp.test.executables": "${workspaceFolder}/.build/**/*{test,Test,TEST}*",
24-
"sonarlint.connectedMode.project": {
25-
"connectionId": "philips-software",
26-
"projectKey": "philips-software_amp-cucumber-cpp-runner"
2+
"cmake.useCMakePresets": "always",
3+
"cucumberautocomplete.steps": [
4+
"cucumber_cpp/example/steps/*.cpp",
5+
"cucumber_cpp/acceptance_test/steps/*.cpp"
6+
],
7+
"cucumberautocomplete.gherkinDefinitionPart": "(GIVEN|WHEN|THEN|STEP)\\(",
8+
"cucumberautocomplete.customParameters": [
9+
{
10+
"parameter": "R\"(",
11+
"value": "\""
12+
},
13+
{
14+
"parameter": ")\"",
15+
"value": "\""
2716
}
28-
}
17+
],
18+
"C/C++ Include Guard.Macro Type": "Filepath",
19+
"C/C++ Include Guard.Path Depth": 1,
20+
"C/C++ Include Guard.Remove Extension": false,
21+
"C/C++ Include Guard.Comment Style": "None",
22+
"C/C++ Include Guard.Path Skip": 0,
23+
"testMate.cpp.test.executables": "${workspaceFolder}/.build/**/*{test,Test,TEST}*",
24+
"sonarlint.connectedMode.project": {
25+
"connectionId": "philips-software",
26+
"projectKey": "philips-software_amp-cucumber-cpp-runner"
27+
}
28+
}

CMakeLists.txt

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,29 @@ else()
2121
set(CCR_EXCLUDE_FROM_ALL "EXCLUDE_FROM_ALL")
2222
endif()
2323

24-
option(
25-
CCR_FETCH_DEPS
26-
"Fetch dependencies via FetchContent."
27-
On
28-
)
29-
30-
option(CCR_BUILD_TESTS "Enable building the tests" ${CCR_DEFAULTOPT})
24+
option(CCR_FETCH_DEPS "Fetch dependencies via FetchContent." On )
25+
option(CCR_BUILD_TESTS "Enable build of the tests" ${CCR_DEFAULTOPT})
26+
option(CCR_ENABLE_COVERAGE "Enable compiler flags for code coverage measurements" Off)
3127

3228
if (CCR_BUILD_TESTS)
3329
ccr_enable_testing()
3430
endif()
3531

32+
if (CCR_ENABLE_COVERAGE)
33+
find_program(GCOVR_PATH gcovr)
34+
35+
if (NOT GCOVR_PATH)
36+
message(FATAL_ERROR "Could not find gcovr, which is required for code coverage IDE integration")
37+
endif()
38+
39+
add_custom_target(
40+
generate-coverage-report
41+
COMMAND ${GCOVR_PATH} --delete --lcov ${CMAKE_CURRENT_BINARY_DIR}/lcov.info
42+
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
43+
COMMENT "Generating code coverage report in LCOV format"
44+
)
45+
endif()
46+
3647
set(CMAKE_CXX_STANDARD 20)
3748
set(CMAKE_CXX_STANDARD_REQUIRED On)
3849
set(CMAKE_CXX_EXTENSIONS Off)

cucumber_cpp/library/Application.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "cucumber_cpp/library/Errors.hpp"
44
#include "cucumber_cpp/library/StepRegistry.hpp"
55
#include "cucumber_cpp/library/cucumber_expression/Errors.hpp"
6+
#include "cucumber_cpp/library/cucumber_expression/ParameterRegistry.hpp"
67
#include "cucumber_cpp/library/engine/ContextManager.hpp"
78
#include "cucumber_cpp/library/engine/FeatureFactory.hpp"
89
#include "cucumber_cpp/library/engine/FeatureInfo.hpp"
@@ -177,6 +178,11 @@ namespace cucumber_cpp::library
177178
return contextManager.ProgramContext();
178179
}
179180

181+
cucumber_expression::ParameterRegistration& Application::ParameterRegistration()
182+
{
183+
return parameterRegistry;
184+
}
185+
180186
void Application::AddReportHandler(const std::string& name, std::unique_ptr<report::ReportHandlerV2>&& reporter)
181187
{
182188
reporters.Add(name, std::move(reporter));

cucumber_cpp/library/Application.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ namespace cucumber_cpp::library
4545

4646
CLI::App& CliParser();
4747
Context& ProgramContext();
48+
cucumber_expression::ParameterRegistration& ParameterRegistration();
4849

4950
void AddReportHandler(const std::string& name, std::unique_ptr<report::ReportHandlerV2>&& reporter);
5051

cucumber_cpp/library/cucumber_expression/ParameterRegistry.hpp

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,12 +120,23 @@ namespace cucumber_cpp::library::cucumber_expression
120120
std::function<std::any(MatchRange)> converter;
121121
};
122122

123-
struct ParameterRegistry
123+
struct ParameterRegistration
124+
{
125+
protected:
126+
~ParameterRegistration() = default;
127+
128+
public:
129+
virtual void AddParameter(std::string name, std::vector<std::string> regex, std::function<std::any(MatchRange)> converter) = 0;
130+
};
131+
132+
struct ParameterRegistry : ParameterRegistration
124133
{
125134
ParameterRegistry();
126135

136+
virtual ~ParameterRegistry() = default;
137+
127138
Parameter Lookup(const std::string& name) const;
128-
void AddParameter(std::string name, std::vector<std::string> regex, std::function<std::any(MatchRange)> converter);
139+
void AddParameter(std::string name, std::vector<std::string> regex, std::function<std::any(MatchRange)> converter) override;
129140

130141
private:
131142
std::map<std::string, Parameter, std::less<>> parameters{};

cucumber_cpp/library/cucumber_expression/test/TestExpression.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -221,4 +221,36 @@ namespace cucumber_cpp::library::cucumber_expression
221221
"Please register a ParameterType for 'doesnotexist'\n"));
222222
}
223223
}
224+
225+
TEST_F(TestExpression, ThrowDuplicateAnonymousParameterError)
226+
{
227+
try
228+
{
229+
parameterRegistry.AddParameter("", { ".*" }, [](const MatchRange& matches)
230+
{
231+
return StringTo<std::string>(matches.begin()->str());
232+
});
233+
FAIL() << "Expected CucumberExpressionError to be thrown";
234+
}
235+
catch (const CucumberExpressionError& e)
236+
{
237+
EXPECT_THAT(e.what(), testing::StrEq("The anonymous parameter type has already been defined"));
238+
}
239+
}
240+
241+
TEST_F(TestExpression, ThrowDuplicateParameterError)
242+
{
243+
try
244+
{
245+
parameterRegistry.AddParameter("word", { ".*" }, [](const MatchRange& matches)
246+
{
247+
return StringTo<std::string>(matches.begin()->str());
248+
});
249+
FAIL() << "Expected CucumberExpressionError to be thrown";
250+
}
251+
catch (const CucumberExpressionError& e)
252+
{
253+
EXPECT_THAT(e.what(), testing::StrEq("There is already a parameter with name word"));
254+
}
255+
}
224256
}

cucumber_cpp/library/report/StdOutReport.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ namespace cucumber_cpp::library::report
184184
void StdOutReport::StepStart(const engine::StepInfo& stepInfo)
185185
{
186186
std::cout << "\n"
187-
<< stepTypeLut.at(stepInfo.Type()) << " " << stepInfo.Text();
187+
<< stepTypeLut.at(stepInfo.Type()) << " " << stepInfo.Text()
188+
<< std::flush;
188189
}
189190

190191
void StdOutReport::StepEnd(engine::Result result, const engine::StepInfo& stepInfo, TraceTime::Duration duration)

cucumber_cpp/library/test/TestApplication.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,9 @@ namespace cucumber_cpp::library
124124

125125
EXPECT_THAT(stdoutString, testing::HasSubstr("1/2 passed"));
126126
}
127+
128+
TEST_F(TestApplication, ExposeParameterRegistration)
129+
{
130+
EXPECT_THAT(&Application{}.ParameterRegistration(), testing::NotNull());
131+
}
127132
}

0 commit comments

Comments
 (0)