Skip to content

Commit 84c6bda

Browse files
committed
moved find_all_of() into cppcheck namespace and into helpers.h
1 parent 7b68d71 commit 84c6bda

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,4 +92,17 @@ class ScopedFile {
9292
const std::string mFullPath;
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
#endif // helpersH

test/testthreadexecutor.cpp

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

179179
// TODO: provide data which actually shows values above 0
180180

181-
template<typename T>
182-
std::size_t find_all_of(const std::string& str, T sub) {
183-
std::size_t n = 0;
184-
std::string::size_type pos = 0;
185-
while ((pos = str.find(sub, pos)) != std::string::npos) {
186-
++pos;
187-
++n;
188-
}
189-
return n;
190-
}
191-
192181
// TODO: should this be logged only once like summary?
193182
void showtime_top5() {
194183
REDIRECT;
@@ -197,7 +186,7 @@ class TestThreadExecutor : public TestFixture {
197186
true, SHOWTIME_MODES::SHOWTIME_TOP5);
198187
// for each file: top5 results + overall + empty line
199188
const std::string output_s = GET_REDIRECT_OUTPUT;
200-
ASSERT_EQUALS((5 + 1 + 1) * 2, find_all_of(output_s, '\n'));
189+
ASSERT_EQUALS((5 + 1 + 1) * 2, cppcheck::find_all_of(output_s, '\n'));
201190
}
202191

203192
void showtime_file() {
@@ -206,7 +195,7 @@ class TestThreadExecutor : public TestFixture {
206195
"int main() {}",
207196
true, SHOWTIME_MODES::SHOWTIME_FILE);
208197
const std::string output_s = GET_REDIRECT_OUTPUT;
209-
ASSERT_EQUALS(2, find_all_of(output_s, "Overall time:"));
198+
ASSERT_EQUALS(2, cppcheck::find_all_of(output_s, "Overall time:"));
210199
}
211200

212201
void showtime_summary() {
@@ -227,7 +216,7 @@ class TestThreadExecutor : public TestFixture {
227216
true, SHOWTIME_MODES::SHOWTIME_TOP5);
228217
// for each file: top5 results + overall + empty line
229218
const std::string output_s = GET_REDIRECT_OUTPUT;
230-
ASSERT_EQUALS((5 + 1 + 1) * 2, find_all_of(output_s, '\n'));
219+
ASSERT_EQUALS((5 + 1 + 1) * 2, cppcheck::find_all_of(output_s, '\n'));
231220
}
232221

233222
void showtime_file_j() {
@@ -236,7 +225,7 @@ class TestThreadExecutor : public TestFixture {
236225
"int main() {}",
237226
true, SHOWTIME_MODES::SHOWTIME_FILE);
238227
const std::string output_s = GET_REDIRECT_OUTPUT;
239-
ASSERT_EQUALS(2, find_all_of(output_s, "Overall time:"));
228+
ASSERT_EQUALS(2, cppcheck::find_all_of(output_s, "Overall time:"));
240229
}
241230

242231
void showtime_summary_j() {

0 commit comments

Comments
 (0)