Skip to content

Commit 2ffe7a7

Browse files
committed
TestSingleExecutor: applied changes from other executor tests / marked failed tests with TODO
1 parent 56034a0 commit 2ffe7a7

File tree

1 file changed

+55
-10
lines changed

1 file changed

+55
-10
lines changed

test/testsingleexecutor.cpp

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class TestSingleExecutor : public TestFixture {
5252
return std::to_string(i);
5353
}
5454

55-
void check(int files, int result, const std::string &data, SHOWTIME_MODES showtime = SHOWTIME_MODES::SHOWTIME_NONE, const char* const plistOutput = nullptr, const std::vector<std::string>& filesList = {}) {
55+
void check(int files, int result, const std::string &data, bool quiet = true, SHOWTIME_MODES showtime = SHOWTIME_MODES::SHOWTIME_NONE, const char* const plistOutput = nullptr, const std::vector<std::string>& filesList = {}) {
5656
errout.str("");
5757
output.str("");
5858

@@ -71,6 +71,7 @@ class TestSingleExecutor : public TestFixture {
7171
}
7272

7373
settings.showtime = showtime;
74+
settings.quiet = quiet;
7475
if (plistOutput)
7576
settings.plistOutput = plistOutput;
7677
// NOLINTNEXTLINE(performance-unnecessary-value-param)
@@ -100,26 +101,25 @@ class TestSingleExecutor : public TestFixture {
100101
TEST_CASE(one_error_less_files);
101102
TEST_CASE(one_error_several_files);
102103
TEST_CASE(markup);
104+
TEST_CASE(showtime_top5_file);
105+
TEST_CASE(showtime_top5_summary);
106+
TEST_CASE(showtime_file);
107+
TEST_CASE(showtime_summary);
103108
}
104109

105110
void many_files() {
106-
const Settings settingsOld = settings;
107-
settings.quiet = false;
108-
109111
check(100, 100,
110112
"int main()\n"
111113
"{\n"
112114
" char *a = malloc(10);\n"
113115
" return 0;\n"
114-
"}");
116+
"}", false);
115117
std::string expected;
116118
for (int i = 1; i <= 100; ++i) {
117119
expected += "Checking file_" + zpad3(i) + ".cpp ...\n";
118120
expected += std::to_string(i) + "/100 files checked " + std::to_string(i) + "% done\n";
119121
}
120122
ASSERT_EQUALS(expected, output.str());
121-
122-
settings = settingsOld;
123123
}
124124

125125
void many_files_showtime() {
@@ -129,7 +129,7 @@ class TestSingleExecutor : public TestFixture {
129129
"{\n"
130130
" char *a = malloc(10);\n"
131131
" return 0;\n"
132-
"}", SHOWTIME_MODES::SHOWTIME_SUMMARY);
132+
"}", true, SHOWTIME_MODES::SHOWTIME_SUMMARY);
133133
}
134134

135135
void many_files_plist() {
@@ -141,7 +141,7 @@ class TestSingleExecutor : public TestFixture {
141141
"{\n"
142142
" char *a = malloc(10);\n"
143143
" return 0;\n"
144-
"}", SHOWTIME_MODES::SHOWTIME_NONE, plistOutput);
144+
"}", true, SHOWTIME_MODES::SHOWTIME_NONE, plistOutput);
145145
}
146146

147147
void no_errors_more_files() {
@@ -201,7 +201,7 @@ class TestSingleExecutor : public TestFixture {
201201
" char *a = malloc(10);\n"
202202
" return 0;\n"
203203
"}",
204-
SHOWTIME_MODES::SHOWTIME_NONE, nullptr, files);
204+
false, SHOWTIME_MODES::SHOWTIME_NONE, nullptr, files);
205205
// TODO: filter out the "files checked" messages
206206
ASSERT_EQUALS("Checking file_2.cpp ...\n"
207207
"1/4 files checked 25% done\n"
@@ -214,6 +214,51 @@ class TestSingleExecutor : public TestFixture {
214214
settings = settingsOld;
215215
}
216216

217+
// TODO: provide data which actually shows values above 0
218+
219+
void showtime_top5_file() {
220+
REDIRECT;
221+
check(2, 0,
222+
"int main() {}",
223+
true, SHOWTIME_MODES::SHOWTIME_TOP5_FILE);
224+
const std::string output_s = GET_REDIRECT_OUTPUT;
225+
// for each file: top5 results + overall + empty line
226+
TODO_ASSERT_EQUALS((5 + 1 + 1) * 2, (5 + 1 + 1), cppcheck::count_all_of(output_s, '\n'));
227+
}
228+
229+
void showtime_top5_summary() {
230+
REDIRECT;
231+
check(2, 0,
232+
"int main() {}",
233+
true, SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY);
234+
const std::string output_s = GET_REDIRECT_OUTPUT;
235+
// once: top5 results + overall + empty line
236+
TODO_ASSERT_EQUALS(5 + 1 + 1, 0, cppcheck::count_all_of(output_s, '\n'));
237+
// should only report the top5 once
238+
ASSERT(output_s.find("1 result(s)") == std::string::npos);
239+
TODO_ASSERT(output_s.find("2 result(s)") != std::string::npos);
240+
}
241+
242+
void showtime_file() {
243+
REDIRECT;
244+
check(2, 0,
245+
"int main() {}",
246+
true, SHOWTIME_MODES::SHOWTIME_FILE);
247+
const std::string output_s = GET_REDIRECT_OUTPUT;
248+
TODO_ASSERT_EQUALS(2, 1, cppcheck::count_all_of(output_s, "Overall time:"));
249+
}
250+
251+
void showtime_summary() {
252+
REDIRECT;
253+
check(2, 0,
254+
"int main() {}",
255+
true, SHOWTIME_MODES::SHOWTIME_SUMMARY);
256+
const std::string output_s = GET_REDIRECT_OUTPUT;
257+
// should only report the actual summary once
258+
ASSERT(output_s.find("1 result(s)") == std::string::npos);
259+
TODO_ASSERT(output_s.find("2 result(s)") != std::string::npos);
260+
}
261+
217262
// TODO: test clang-tidy
218263
// TODO: test whole program analysis
219264
};

0 commit comments

Comments
 (0)