Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,24 @@
"sonarlint.connectedMode.project": {
"connectionId": "philips-software",
"projectKey": "philips-software_amp-cucumber-cpp-runner"
},
{
"parameter": ")\"",
"value": "\""
}
],
"C/C++ Include Guard.Macro Type": "Filepath",
"C/C++ Include Guard.Path Depth": 1,
"C/C++ Include Guard.Remove Extension": false,
"C/C++ Include Guard.Comment Style": "None",
"C/C++ Include Guard.Path Skip": 0,
"testMate.cpp.test.executables": "${workspaceFolder}/.build/**/*{test,Test,TEST}*",
"sonarlint.connectedMode.project": {
"connectionId": "philips-software",
"projectKey": "philips-software_amp-cucumber-cpp-runner"
},
"cmake.postRunCoverageTarget": "generate-coverage-report",
"cmake.coverageInfoFiles": [
"${workspaceFolder}/.build/${command:cmake.activeConfigurePresetName}/lcov.info"
]
}
25 changes: 18 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,29 @@ else()
set(CCR_EXCLUDE_FROM_ALL "EXCLUDE_FROM_ALL")
endif()

option(
CCR_FETCH_DEPS
"Fetch dependencies via FetchContent."
On
)

option(CCR_BUILD_TESTS "Enable building the tests" ${CCR_DEFAULTOPT})
option(CCR_FETCH_DEPS "Fetch dependencies via FetchContent." On )
option(CCR_BUILD_TESTS "Enable build of the tests" ${CCR_DEFAULTOPT})
option(CCR_ENABLE_COVERAGE "Enable compiler flags for code coverage measurements" Off)

if (CCR_BUILD_TESTS)
ccr_enable_testing()
endif()

if (CCR_ENABLE_COVERAGE)
find_program(GCOVR_PATH gcovr)

if (NOT GCOVR_PATH)
message(FATAL_ERROR "Could not find gcovr, which is required for code coverage IDE integration")
endif()

add_custom_target(
generate-coverage-report
COMMAND ${GCOVR_PATH} --delete --lcov ${CMAKE_CURRENT_BINARY_DIR}/lcov.info
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
COMMENT "Generating code coverage report in LCOV format"
)
endif()

set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED On)
set(CMAKE_CXX_EXTENSIONS Off)
Expand Down
6 changes: 6 additions & 0 deletions cucumber_cpp/library/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "cucumber_cpp/library/Errors.hpp"
#include "cucumber_cpp/library/StepRegistry.hpp"
#include "cucumber_cpp/library/cucumber_expression/Errors.hpp"
#include "cucumber_cpp/library/cucumber_expression/ParameterRegistry.hpp"
#include "cucumber_cpp/library/engine/ContextManager.hpp"
#include "cucumber_cpp/library/engine/FeatureFactory.hpp"
#include "cucumber_cpp/library/engine/FeatureInfo.hpp"
Expand Down Expand Up @@ -177,6 +178,11 @@ namespace cucumber_cpp::library
return contextManager.ProgramContext();
}

cucumber_expression::ParameterRegistration& Application::ParameterRegistration()
{
return parameterRegistry;
}

void Application::AddReportHandler(const std::string& name, std::unique_ptr<report::ReportHandlerV2>&& reporter)
{
reporters.Add(name, std::move(reporter));
Expand Down
1 change: 1 addition & 0 deletions cucumber_cpp/library/Application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ namespace cucumber_cpp::library

CLI::App& CliParser();
Context& ProgramContext();
cucumber_expression::ParameterRegistration& ParameterRegistration();

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

Expand Down
15 changes: 13 additions & 2 deletions cucumber_cpp/library/cucumber_expression/ParameterRegistry.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,12 +120,23 @@ namespace cucumber_cpp::library::cucumber_expression
std::function<std::any(MatchRange)> converter;
};

struct ParameterRegistry
struct ParameterRegistration
{
protected:
~ParameterRegistration() = default;

public:
virtual void AddParameter(std::string name, std::vector<std::string> regex, std::function<std::any(MatchRange)> converter) = 0;
};

struct ParameterRegistry : ParameterRegistration
{
ParameterRegistry();

virtual ~ParameterRegistry() = default;

Parameter Lookup(const std::string& name) const;
void AddParameter(std::string name, std::vector<std::string> regex, std::function<std::any(MatchRange)> converter);
void AddParameter(std::string name, std::vector<std::string> regex, std::function<std::any(MatchRange)> converter) override;

private:
std::map<std::string, Parameter, std::less<>> parameters{};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,4 +221,36 @@ namespace cucumber_cpp::library::cucumber_expression
"Please register a ParameterType for 'doesnotexist'\n"));
}
}

TEST_F(TestExpression, ThrowDuplicateAnonymousParameterError)
{
try
{
parameterRegistry.AddParameter("", { ".*" }, [](const MatchRange& matches)
{
return StringTo<std::string>(matches.begin()->str());
});
FAIL() << "Expected CucumberExpressionError to be thrown";
}
catch (const CucumberExpressionError& e)
{
EXPECT_THAT(e.what(), testing::StrEq("The anonymous parameter type has already been defined"));
}
}

TEST_F(TestExpression, ThrowDuplicateParameterError)
{
try
{
parameterRegistry.AddParameter("word", { ".*" }, [](const MatchRange& matches)
{
return StringTo<std::string>(matches.begin()->str());
});
FAIL() << "Expected CucumberExpressionError to be thrown";
}
catch (const CucumberExpressionError& e)
{
EXPECT_THAT(e.what(), testing::StrEq("There is already a parameter with name word"));
}
}
}
5 changes: 5 additions & 0 deletions cucumber_cpp/library/test/TestApplication.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,9 @@ namespace cucumber_cpp::library

EXPECT_THAT(stdoutString, testing::HasSubstr("1/2 passed"));
}

TEST_F(TestApplication, ExposeParameterRegistration)
{
EXPECT_THAT(&Application{}.ParameterRegistration(), testing::NotNull());
}
}
Loading