Skip to content

Commit 5893f62

Browse files
committed
fixed build issues and solved sonarcloud warnings
1 parent c235f1a commit 5893f62

File tree

13 files changed

+94
-90
lines changed

13 files changed

+94
-90
lines changed

cucumber_cpp/example/hooks/Hooks.cpp

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,42 @@ HOOK_BEFORE_ALL()
1212
context.Emplace<NordicBleFixture>();
1313
}
1414

15-
HOOK_BEFORE_ALL(.name = "Initialize something") // does NOT have a .tagExpression
16-
{}
15+
HOOK_BEFORE_ALL(.name = "Initialize something")
16+
{
17+
/* no body, example only */
18+
}
1719

1820
HOOK_BEFORE_SCENARIO(.name = "explicit name only")
1921
{
22+
/* no body, example only */
2023
}
2124

2225
HOOK_BEFORE_SCENARIO("@dingus", "name", 10)
2326
{
27+
/* no body, example only */
2428
}
2529

2630
HOOK_BEFORE_SCENARIO("@result:OK")
2731
{
32+
/* no body, example only */
2833
}
2934

3035
HOOK_BEFORE_SCENARIO()
3136
{
37+
/* no body, example only */
3238
}
3339

3440
HOOK_AFTER_SCENARIO()
3541
{
42+
/* no body, example only */
3643
}
3744

3845
HOOK_BEFORE_STEP()
3946
{
47+
/* no body, example only */
4048
}
4149

4250
HOOK_AFTER_STEP()
4351
{
52+
/* no body, example only */
4453
}

cucumber_cpp/example/steps/Steps.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,16 @@
88

99
GIVEN(R"(a background step)")
1010
{
11+
/* no body, example only */
1112
}
1213

1314
GIVEN(R"(a simple data table)")
1415
{
15-
// std::cout << "row0.col0: " << table[0][0].As<std::string>() << "\n";
16-
// std::cout << "row0.col1: " << table[0][1].As<std::string>() << "\n";
16+
[[maybe_unused]] const auto row0col0 = table.value()[0].cells[0].value;
17+
[[maybe_unused]] const auto row0col1 = table.value()[0].cells[1].value;
1718

18-
// std::cout << "row1.col0: " << table[1][0].As<std::string>() << "\n";
19-
// std::cout << "row1.col1: " << table[1][1].As<std::string>() << "\n";
19+
[[maybe_unused]] const auto row1col0 = table.value()[1].cells[0].value;
20+
[[maybe_unused]] const auto row1col1 = table.value()[1].cells[1].value;
2021
}
2122

2223
GIVEN(R"(there are {int} cucumbers)", (std::int32_t num))

cucumber_cpp/library/Body.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ namespace cucumber_cpp::library
2727
{
2828
}
2929

30-
void ReportTestPartResult(const testing::TestPartResult& testPartResult)
30+
void ReportTestPartResult(const testing::TestPartResult& testPartResult) override
3131
{
3232
if (testPartResult.failed())
3333
{
@@ -71,7 +71,7 @@ namespace cucumber_cpp::library
7171
if (!e.message.empty())
7272
testStepResult.message = e.message;
7373
}
74-
catch (const FatalError& error)
74+
catch ([[maybe_unused]] const FatalError& error)
7575
{
7676
testStepResult.status = cucumber::messages::test_step_result_status::FAILED;
7777
}
@@ -95,8 +95,8 @@ namespace cucumber_cpp::library
9595
auto nanoseconds = support::Stopwatch::Instance().Duration();
9696
static constexpr std::size_t nanosecondsPerSecond = 1e9;
9797
testStepResult.duration = {
98-
.seconds = static_cast<std::size_t>(nanoseconds.count() / static_cast<std::size_t>(nanosecondsPerSecond)),
99-
.nanos = static_cast<std::size_t>(nanoseconds.count() % static_cast<std::size_t>(nanosecondsPerSecond)),
98+
.seconds = nanoseconds.count() / nanosecondsPerSecond,
99+
.nanos = nanoseconds.count() % nanosecondsPerSecond,
100100
};
101101

102102
return testStepResult;

cucumber_cpp/library/BodyMacro.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ T TransformArg(const cucumber::messages::step_match_argument& match)
3636
void Execute(const cucumber::messages::step_match_arguments_list& args) override \
3737
{ \
3838
cucumber_cpp::library::SetUpTearDownWrapper wrapper{ *this }; \
39-
/* ASSERT_NO_THROW(ExecuteWithArgs(args, static_cast<void(*) targs>(nullptr))); */ \
4039
ExecuteWithArgs(args, static_cast<void(*) targs>(nullptr)); \
4140
} \
4241
\

cucumber_cpp/library/HookRegistry.cpp

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ namespace cucumber_cpp::library
6464
}
6565

6666
HookBase::HookBase(util::Broadcaster& broadCaster, Context& context, engine::StepOrHookStarted stepOrHookStarted)
67-
: engine::ExecutionContext{ broadCaster, context, stepOrHookStarted }
67+
: engine::ExecutionContext{ broadCaster, context, std::move(stepOrHookStarted) }
6868
{}
6969

7070
HookRegistry::Definition::Definition(std::string id, HookType type, std::optional<std::string_view> expression, std::optional<std::string_view> name, HookFactory factory, std::source_location sourceLocation)
7171
: type{ type }
7272
, tagExpression{ tag_expression::Parse(expression.value_or("")) }
7373
, factory{ factory }
7474
, hook{
75-
.id = id,
75+
.id = std::move(id),
7676
.name = name.has_value() ? std::make_optional<std::string>(name.value()) : std::nullopt,
7777
.source_reference = cucumber::messages::source_reference{
7878
.uri = sourceLocation.file_name(),
@@ -118,28 +118,18 @@ namespace cucumber_cpp::library
118118
return std::ranges::count(registry | std::views::values, hookType, &Definition::type);
119119
}
120120

121-
HookFactory HookRegistry::GetFactoryById(std::string id) const
121+
HookFactory HookRegistry::GetFactoryById(const std::string& id) const
122122
{
123123
return registry.at(id).factory;
124124
}
125125

126-
const HookRegistry::Definition& HookRegistry::GetDefinitionById(std::string id) const
126+
const HookRegistry::Definition& HookRegistry::GetDefinitionById(const std::string& id) const
127127
{
128128
return registry.at(id);
129129
}
130130

131131
void HookRegistry::Register(std::string id, HookType type, std::optional<std::string_view> expression, std::optional<std::string_view> name, HookFactory factory, std::source_location sourceLocation)
132132
{
133-
registry.emplace(id, Definition{ id, type, expression, name, factory, sourceLocation });
133+
registry.try_emplace(id, Definition{ id, type, expression, name, factory, sourceLocation });
134134
}
135-
136-
// std::span<HookEntry> HookRegistration::GetEntries()
137-
// {
138-
// return registry;
139-
// }
140-
141-
// std::span<const HookEntry> HookRegistration::GetEntries() const
142-
// {
143-
// return registry;
144-
// }
145135
}

cucumber_cpp/library/HookRegistry.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,8 @@ namespace cucumber_cpp::library
108108
[[nodiscard]] std::size_t Size() const;
109109
[[nodiscard]] std::size_t Size(HookType hookType) const;
110110

111-
HookFactory GetFactoryById(std::string id) const;
112-
const Definition& GetDefinitionById(std::string id) const;
111+
HookFactory GetFactoryById(const std::string& id) const;
112+
const Definition& GetDefinitionById(const std::string& id) const;
113113

114114
private:
115115
void Register(std::string id, HookType type, std::optional<std::string_view> expression, std::optional<std::string_view> name, HookFactory factory, std::source_location sourceLocation);

cucumber_cpp/library/Hooks.hpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
#include "cucumber_cpp/library/HookRegistry.hpp"
99
#include "cucumber_cpp/library/support/SupportCodeLibrary.hpp"
1010

11-
// #define HOOK_(matcher, type) BODY(matcher, type, (), cucumber_cpp::library::HookRegistration::Register, cucumber_cpp::library::HookBase)
1211
#define HOOK_(matcher, type) BODY(matcher, type, (), cucumber_cpp::library::support::DefinitionRegistration::Register, cucumber_cpp::library::HookBase)
1312

1413
#define HOOK_BEFORE_ALL(...) \

cucumber_cpp/library/Query.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "cucumber/messages/undefined_parameter_type.hpp"
3131
#include <cstdint>
3232
#include <format>
33+
#include <functional>
3334
#include <map>
3435
#include <memory>
3536
#include <span>
@@ -163,7 +164,7 @@ namespace cucumber_cpp::library
163164
return lineageById.at(pickle.ast_node_ids[0]);
164165
}
165166

166-
const Lineage& Query::FindLineageByUri(std::string uri) const
167+
const Lineage& Query::FindLineageByUri(const std::string& uri) const
167168
{
168169
return lineageByUri.at(uri);
169170
}
@@ -238,12 +239,12 @@ namespace cucumber_cpp::library
238239
return lineage.scenario->location;
239240
}
240241

241-
const std::map<std::string, cucumber::messages::test_case_started>& Query::TestCaseStarted() const
242+
const std::map<std::string, cucumber::messages::test_case_started, std::less<>>& Query::TestCaseStarted() const
242243
{
243244
return testCaseStartedById;
244245
}
245246

246-
const std::map<std::string, cucumber::messages::test_case_finished>& Query::TestCaseFinishedByTestCaseStartedId() const
247+
const std::map<std::string, cucumber::messages::test_case_finished, std::less<>>& Query::TestCaseFinishedByTestCaseStartedId() const
247248
{
248249
return testCaseFinishedByTestCaseStartedId;
249250
}
@@ -257,19 +258,19 @@ namespace cucumber_cpp::library
257258

258259
void Query::operator+=(const cucumber::messages::pickle& pickle)
259260
{
260-
pickleById.emplace(pickle.id, pickle);
261+
pickleById.try_emplace(pickle.id, pickle);
261262
for (const auto& pickleStep : pickle.steps)
262-
pickleStepById.emplace(pickleStep.id, pickleStep);
263+
pickleStepById.try_emplace(pickleStep.id, pickleStep);
263264
}
264265

265266
void Query::operator+=(const cucumber::messages::hook& hook)
266267
{
267-
hooksById.emplace(hook.id, hook);
268+
hooksById.try_emplace(hook.id, hook);
268269
}
269270

270271
void Query::operator+=(const cucumber::messages::step_definition& stepDefinition)
271272
{
272-
stepDefinitionById.emplace(stepDefinition.id, stepDefinition);
273+
stepDefinitionById.try_emplace(stepDefinition.id, stepDefinition);
273274
}
274275

275276
void Query::operator+=(const cucumber::messages::test_run_started& testRunStarted)
@@ -279,23 +280,23 @@ namespace cucumber_cpp::library
279280

280281
void Query::operator+=(const cucumber::messages::test_run_hook_started& testRunHookStarted)
281282
{
282-
testRunHookStartedById.emplace(testRunHookStarted.id, testRunHookStarted);
283+
testRunHookStartedById.try_emplace(testRunHookStarted.id, testRunHookStarted);
283284
}
284285

285286
void Query::operator+=(const cucumber::messages::test_run_hook_finished& testRunHookFinished)
286287
{
287-
testRunHookFinishedByTestRunHookStartedId.emplace(testRunHookFinished.test_run_hook_started_id, testRunHookFinished);
288+
testRunHookFinishedByTestRunHookStartedId.try_emplace(testRunHookFinished.test_run_hook_started_id, testRunHookFinished);
288289
}
289290

290291
void Query::operator+=(const cucumber::messages::test_case& testCase)
291292
{
292-
auto& testCaseRef = testCaseById.emplace(testCase.id, testCase).first->second;
293-
testCaseByPickleId.emplace(testCase.pickle_id, testCaseRef);
293+
auto& testCaseRef = testCaseById.try_emplace(testCase.id, testCase).first->second;
294+
testCaseByPickleId.try_emplace(testCase.pickle_id, testCaseRef);
294295

295296
for (const auto& testStep : testCase.test_steps)
296297
{
297-
testStepById.emplace(testStep.id, testStep);
298-
pickleIdByTestStepId.emplace(testStep.id, testCase.pickle_id);
298+
testStepById.try_emplace(testStep.id, testStep);
299+
pickleIdByTestStepId.try_emplace(testStep.id, testCase.pickle_id);
299300

300301
if (testStep.pickle_step_id)
301302
{
@@ -310,7 +311,7 @@ namespace cucumber_cpp::library
310311

311312
void Query::operator+=(const cucumber::messages::test_case_started& testCaseStarted)
312313
{
313-
testCaseStartedById.emplace(testCaseStarted.id, testCaseStarted);
314+
testCaseStartedById.try_emplace(testCaseStarted.id, testCaseStarted);
314315

315316
/* reset data? https://github.dev/cucumber/query/blob/f31732e5972c1815614f1d83928a7065e3080dc4/javascript/src/Query.ts#L249 */
316317
}
@@ -346,7 +347,7 @@ namespace cucumber_cpp::library
346347

347348
void Query::operator+=(const cucumber::messages::test_case_finished& testCaseFinished)
348349
{
349-
testCaseFinishedByTestCaseStartedId.emplace(testCaseFinished.test_case_started_id, testCaseFinished);
350+
testCaseFinishedByTestCaseStartedId.try_emplace(testCaseFinished.test_case_started_id, testCaseFinished);
350351
}
351352

352353
void Query::operator+=(const cucumber::messages::test_run_finished& testRunFinished)
@@ -429,12 +430,12 @@ namespace cucumber_cpp::library
429430
void Query::operator+=(std::span<const cucumber::messages::step> steps)
430431
{
431432
for (const auto& step : steps)
432-
stepById.emplace(step.id, step);
433+
stepById.try_emplace(step.id, step);
433434
}
434435

435436
void Query::operator+=(const cucumber::messages::parameter_type& parameterType)
436437
{
437-
auto& ref = parameterTypeById.emplace(parameterType.id, parameterType).first->second;
438-
parameterTypeByName.emplace(parameterType.name, ref);
438+
auto& ref = parameterTypeById.try_emplace(parameterType.id, parameterType).first->second;
439+
parameterTypeByName.try_emplace(parameterType.name, ref);
439440
}
440441
}

0 commit comments

Comments
 (0)