Skip to content

Commit b3655ec

Browse files
authored
feat: expose parameter registration interface (#190)
1 parent cac7695 commit b3655ec

File tree

7 files changed

+94
-9
lines changed

7 files changed

+94
-9
lines changed

.vscode/settings.json

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,5 +24,24 @@
2424
"sonarlint.connectedMode.project": {
2525
"connectionId": "philips-software",
2626
"projectKey": "philips-software_amp-cucumber-cpp-runner"
27+
},
28+
{
29+
"parameter": ")\"",
30+
"value": "\""
2731
}
32+
],
33+
"C/C++ Include Guard.Macro Type": "Filepath",
34+
"C/C++ Include Guard.Path Depth": 1,
35+
"C/C++ Include Guard.Remove Extension": false,
36+
"C/C++ Include Guard.Comment Style": "None",
37+
"C/C++ Include Guard.Path Skip": 0,
38+
"testMate.cpp.test.executables": "${workspaceFolder}/.build/**/*{test,Test,TEST}*",
39+
"sonarlint.connectedMode.project": {
40+
"connectionId": "philips-software",
41+
"projectKey": "philips-software_amp-cucumber-cpp-runner"
42+
},
43+
"cmake.postRunCoverageTarget": "generate-coverage-report",
44+
"cmake.coverageInfoFiles": [
45+
"${workspaceFolder}/.build/${command:cmake.activeConfigurePresetName}/lcov.info"
46+
]
2847
}

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/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)