Skip to content

Commit 2a1c0b4

Browse files
committed
moved find_all_of() into cppcheck namespace and into helpers.h
1 parent 246eaa5 commit 2a1c0b4

2 files changed

Lines changed: 17 additions & 15 deletions

File tree

test/helpers.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,19 @@ class PreprocessorHelper
9292
static std::string getcode(Preprocessor &preprocessor, const std::string &filedata, const std::string &cfg, const std::string &filename, Suppressions *inlineSuppression = nullptr);
9393
};
9494

95+
namespace cppcheck {
96+
template<typename T>
97+
std::size_t find_all_of(const std::string& str, T sub) {
98+
std::size_t n = 0;
99+
std::string::size_type pos = 0;
100+
while ((pos = str.find(sub, pos)) != std::string::npos) {
101+
++pos;
102+
++n;
103+
}
104+
return n;
105+
}
106+
}
107+
95108
/* designated initialization helper
96109
Usage:
97110
struct S

test/testthreadexecutor.cpp

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -244,17 +244,6 @@ class TestThreadExecutor : public TestFixture {
244244

245245
// TODO: provide data which actually shows values above 0
246246

247-
template<typename T>
248-
std::size_t find_all_of(const std::string& str, T sub) {
249-
std::size_t n = 0;
250-
std::string::size_type pos = 0;
251-
while ((pos = str.find(sub, pos)) != std::string::npos) {
252-
++pos;
253-
++n;
254-
}
255-
return n;
256-
}
257-
258247
// TODO: should this be logged only once like summary?
259248
void showtime_top5() {
260249
REDIRECT;
@@ -263,7 +252,7 @@ class TestThreadExecutor : public TestFixture {
263252
true, SHOWTIME_MODES::SHOWTIME_TOP5);
264253
// for each file: top5 results + overall + empty line
265254
const std::string output_s = GET_REDIRECT_OUTPUT;
266-
ASSERT_EQUALS((5 + 1 + 1) * 2, find_all_of(output_s, '\n'));
255+
ASSERT_EQUALS((5 + 1 + 1) * 2, cppcheck::find_all_of(output_s, '\n'));
267256
}
268257

269258
void showtime_file() {
@@ -272,7 +261,7 @@ class TestThreadExecutor : public TestFixture {
272261
"int main() {}",
273262
true, SHOWTIME_MODES::SHOWTIME_FILE);
274263
const std::string output_s = GET_REDIRECT_OUTPUT;
275-
ASSERT_EQUALS(2, find_all_of(output_s, "Overall time:"));
264+
ASSERT_EQUALS(2, cppcheck::find_all_of(output_s, "Overall time:"));
276265
}
277266

278267
void showtime_summary() {
@@ -293,7 +282,7 @@ class TestThreadExecutor : public TestFixture {
293282
true, SHOWTIME_MODES::SHOWTIME_TOP5);
294283
// for each file: top5 results + overall + empty line
295284
const std::string output_s = GET_REDIRECT_OUTPUT;
296-
ASSERT_EQUALS((5 + 1 + 1) * 2, find_all_of(output_s, '\n'));
285+
ASSERT_EQUALS((5 + 1 + 1) * 2, cppcheck::find_all_of(output_s, '\n'));
297286
}
298287

299288
void showtime_file_j() {
@@ -302,7 +291,7 @@ class TestThreadExecutor : public TestFixture {
302291
"int main() {}",
303292
true, SHOWTIME_MODES::SHOWTIME_FILE);
304293
const std::string output_s = GET_REDIRECT_OUTPUT;
305-
ASSERT_EQUALS(2, find_all_of(output_s, "Overall time:"));
294+
ASSERT_EQUALS(2, cppcheck::find_all_of(output_s, "Overall time:"));
306295
}
307296

308297
void showtime_summary_j() {

0 commit comments

Comments
 (0)