Skip to content

Commit 3e626e7

Browse files
committed
fix sonar warnings and replace \r\n with \n
1 parent c66a111 commit 3e626e7

File tree

7 files changed

+62
-28
lines changed

7 files changed

+62
-28
lines changed

compatibility/compatibility.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ namespace compatibility
9393

9494
++jsonIter;
9595
}
96+
else if (key == "data")
97+
{
98+
json[key] = std::regex_replace(json[key].get<std::string>(), std::regex(R"(\r\n)"), "\n");
99+
}
96100
else if (key == "uri")
97101
{
98102
auto uri = value.get<std::string>();

cucumber_cpp/library/assemble/AssembleTestSuites.cpp

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
#include "cucumber/messages/step_match_arguments_list.hpp"
55
#include "cucumber/messages/test_case.hpp"
66
#include "cucumber_cpp/library/HookRegistry.hpp"
7+
#include "cucumber_cpp/library/StepRegistry.hpp"
78
#include "cucumber_cpp/library/assemble/AssembledTestSuite.hpp"
9+
#include "cucumber_cpp/library/cucumber_expression/Argument.hpp"
810
#include "cucumber_cpp/library/cucumber_expression/Matcher.hpp"
911
#include "cucumber_cpp/library/support/SupportCodeLibrary.hpp"
1012
#include "cucumber_cpp/library/support/Types.hpp"
@@ -22,13 +24,30 @@
2224

2325
namespace cucumber_cpp::library::assemble
2426
{
27+
namespace
28+
{
29+
auto TransformToMatch(const std::string& text)
30+
{
31+
return [&text](const StepRegistry::Definition& definition) -> std::pair<std::string, std::optional<std::vector<cucumber_expression::Argument>>>
32+
{
33+
const auto match = std::visit(cucumber_expression::MatchVisitor{ text }, definition.regex);
34+
return { definition.id, match };
35+
};
36+
}
37+
38+
bool HasMatch(const std::pair<std::string, std::optional<std::vector<cucumber_expression::Argument>>>& pair)
39+
{
40+
return pair.second.has_value();
41+
}
42+
}
43+
2544
std::vector<AssembledTestSuite> AssembleTestSuites(support::SupportCodeLibrary supportCodeLibrary,
2645
std::string_view testRunStartedId,
2746
util::Broadcaster& broadcaster,
2847
const std::list<support::PickleSource>& sourcedPickles,
2948
cucumber::gherkin::id_generator_ptr idGenerator)
3049
{
31-
std::vector<std::string> testUris;
50+
std::list<std::string> testUris;
3251
std::map<std::string, AssembledTestSuite> assembledTestSuiteMap;
3352

3453
for (const auto& pickleSource : sourcedPickles)
@@ -47,30 +66,24 @@ namespace cucumber_cpp::library::assemble
4766

4867
for (const auto& step : pickleSource.pickle->steps)
4968
{
50-
// auto definitions = supportCodeLibrary.stepRegistry.FindDefinitions(step.text);
5169
const auto& stepDefinitions = supportCodeLibrary.stepRegistry.StepDefinitions();
5270

53-
std::vector<std::string> stepDefinitionIds;
54-
std::vector<cucumber::messages::step_match_arguments_list> stepMatchArgumentsLists;
55-
56-
for (const auto& definition : stepDefinitions)
57-
{
58-
const auto match = std::visit(cucumber_expression::MatchVisitor{ step.text }, definition.regex);
59-
if (match)
60-
{
61-
stepDefinitionIds.push_back(definition.id);
62-
auto& argumentList = stepMatchArgumentsLists.emplace_back();
63-
for (const auto& result : *match)
64-
argumentList.step_match_arguments.emplace_back(result.Group(), result.Name().empty() ? std::nullopt : std::make_optional(result.Name()));
65-
}
66-
}
67-
68-
testCase.test_steps.emplace_back(
71+
auto& testStep = testCase.test_steps.emplace_back(
6972
std::nullopt,
7073
idGenerator->next_id(),
7174
step.id,
72-
stepDefinitionIds,
73-
stepMatchArgumentsLists);
75+
std::vector<std::string>{},
76+
std::vector<cucumber::messages::step_match_arguments_list>{});
77+
78+
for (const auto& [id, match] : stepDefinitions |
79+
std::views::transform(TransformToMatch(step.text)) |
80+
std::views::filter(HasMatch))
81+
{
82+
testStep.step_definition_ids.value().push_back(id);
83+
auto& argumentList = testStep.step_match_arguments_lists.value().emplace_back();
84+
for (const auto& result : *match)
85+
argumentList.step_match_arguments.emplace_back(result.Group(), result.Name().empty() ? std::nullopt : std::make_optional(result.Name()));
86+
}
7487
}
7588

7689
for (const auto& hookId : supportCodeLibrary.hookRegistry.FindIds(HookType::after, pickleSource.pickle->tags) | std::views::reverse)

cucumber_cpp/library/cucumber_expression/TreeRegexp.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ namespace cucumber_cpp::library::cucumber_expression
3535

3636
struct TreeRegexp
3737
{
38-
TreeRegexp(std::string_view pattern);
38+
explicit TreeRegexp(std::string_view pattern);
3939

4040
const GroupBuilder& RootBuilder() const;
4141

cucumber_cpp/library/formatter/PrettyPrinter.cpp

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,9 @@ namespace cucumber_cpp::library::formatter
113113
}
114114

115115
void PrettyPrinter::HandleAttachment(const cucumber::messages::attachment& attachment)
116-
{}
116+
{
117+
/* TODO implement */
118+
}
117119

118120
void PrettyPrinter::HandleTestStepFinished(const cucumber::messages::test_step_finished& testStepFinished)
119121
{
@@ -133,7 +135,9 @@ namespace cucumber_cpp::library::formatter
133135
}
134136

135137
void PrettyPrinter::HandleTestRunFinished(const cucumber::messages::test_run_finished& testRunFinished)
136-
{}
138+
{
139+
/* TODO implement */
140+
}
137141

138142
void PrettyPrinter::PrintFeatureLine(const cucumber::messages::feature& feature)
139143
{
@@ -187,7 +191,7 @@ namespace cucumber_cpp::library::formatter
187191
}
188192
const auto padding = maxContentLength - title.length();
189193

190-
if (uri && line)
194+
if (uri.has_value() && line.has_value())
191195
support::print(outputStream, "{:{}}{}{:{}} {}\n", "", indent, formatTitle ? formatTitle(title) : std::string(title), "", padding, ColorFunctions::Location(std::format("# {}:{}", *uri, *line)));
192196
else
193197
support::print(outputStream, "{:{}}{}\n", "", indent, formatTitle ? formatTitle(title) : std::string(title));

cucumber_cpp/library/formatter/helper/SummaryHelpers.cpp

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "cucumber_cpp/library/formatter/helper/SummaryHelpers.hpp"
22
#include "cucumber/messages/duration.hpp"
3+
#include "cucumber/messages/test_step.hpp"
34
#include "cucumber/messages/test_step_result.hpp"
45
#include "cucumber/messages/test_step_result_status.hpp"
56
#include "cucumber_cpp/library/formatter/GetColorFunctions.hpp"
@@ -59,6 +60,11 @@ namespace cucumber_cpp::library::formatter::helper
5960
const auto total = support::DurationToMilliseconds(duration);
6061
return std::format("{:%Mm %S}s", total);
6162
}
63+
64+
bool HasPickleStepId(const cucumber::messages::test_step& testStep)
65+
{
66+
return testStep.pickle_step_id.has_value();
67+
}
6268
}
6369

6470
std::string FormatSummary(std::span<const TestCaseAttempt> testCaseAttempts, cucumber::messages::duration testRunDuration)
@@ -75,9 +81,10 @@ namespace cucumber_cpp::library::formatter::helper
7581
if (!testCaseAttempt.willBeRetried)
7682
{
7783
testCaseResults.emplace_back(testCaseAttempt.worstTestStepResult);
78-
for (const auto& testStep : testCaseAttempt.testCase.test_steps)
79-
if (testStep.pickle_step_id)
80-
testStepResults.emplace_back(testCaseAttempt.stepResults.at(testStep.id));
84+
85+
for (const auto& testStep : testCaseAttempt.testCase.test_steps |
86+
std::views::filter(HasPickleStepId))
87+
testStepResults.emplace_back(testCaseAttempt.stepResults.at(testStep.id));
8188
}
8289
}
8390

cucumber_cpp/library/runtime/TestCaseRunner.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ namespace cucumber_cpp::library::runtime
181181

182182
cucumber::messages::test_step_result TestCaseRunner::RunStep(const cucumber::messages::pickle_step& pickleStep, const cucumber::messages::test_step& testStep, Context& testCaseContext, cucumber::messages::test_step_started testStepStarted)
183183
{
184-
auto stepDefinitions = (*testStep.step_definition_ids) | std::views::transform([&](const std::string& id)
184+
auto stepDefinitions = (*testStep.step_definition_ids) | std::views::transform([this](const std::string& id)
185185
{
186186
return supportCodeLibrary.stepRegistry.GetDefinitionById(id);
187187
});

cucumber_cpp/library/util/Broadcaster.hpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@ namespace cucumber_cpp::library::util
1212
struct Listener
1313
{
1414
explicit Listener(Broadcaster& broadcaster, const std::function<void(const cucumber::messages::envelope& envelope)>& onEvent);
15+
16+
Listener(const Listener&) = delete;
17+
Listener& operator=(const Listener&) = delete;
18+
Listener(Listener&&) = delete;
19+
Listener& operator=(Listener&&) = delete;
20+
1521
~Listener();
1622

1723
void Invoke(const cucumber::messages::envelope& envelope) const;

0 commit comments

Comments
 (0)