Skip to content

Commit 03dc02d

Browse files
committed
TestProcessExecutor: applied TestThreadExecutor changes / use TODO asserts for currently broken tests
1 parent cd483c8 commit 03dc02d

1 file changed

Lines changed: 76 additions & 5 deletions

File tree

test/testprocessexecutor.cpp

Lines changed: 76 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class TestProcessExecutor : public TestFixture {
5050
* Execute check using n jobs for y files which are have
5151
* identical data, given within data.
5252
*/
53-
void check(unsigned int jobs, 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 = {}) {
53+
void check(unsigned int jobs, 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 = {}) {
5454
errout.str("");
5555
output.str("");
5656

@@ -71,6 +71,7 @@ class TestProcessExecutor : public TestFixture {
7171

7272
settings.jobs = jobs;
7373
settings.showtime = showtime;
74+
settings.quiet = quiet;
7475
if (plistOutput)
7576
settings.plistOutput = plistOutput;
7677
// TODO: test with settings.project.fileSettings;
@@ -95,6 +96,12 @@ class TestProcessExecutor : public TestFixture {
9596
TEST_CASE(one_error_less_files);
9697
TEST_CASE(one_error_several_files);
9798
TEST_CASE(markup);
99+
TEST_CASE(showtime_top5);
100+
TEST_CASE(showtime_file);
101+
TEST_CASE(showtime_summary);
102+
TEST_CASE(showtime_top5_j);
103+
TEST_CASE(showtime_file_j);
104+
TEST_CASE(showtime_summary_j);
98105
#endif // !WIN32
99106
}
100107

@@ -110,6 +117,7 @@ class TestProcessExecutor : public TestFixture {
110117
check(2, 3, 3, oss.str());
111118
}
112119

120+
// TODO: check the output
113121
void many_threads() {
114122
check(16, 100, 100,
115123
"int main()\n"
@@ -127,7 +135,7 @@ class TestProcessExecutor : public TestFixture {
127135
"{\n"
128136
" char *a = malloc(10);\n"
129137
" return 0;\n"
130-
"}", SHOWTIME_MODES::SHOWTIME_SUMMARY);
138+
"}", true, SHOWTIME_MODES::SHOWTIME_SUMMARY);
131139
}
132140

133141
void many_threads_plist() {
@@ -139,7 +147,7 @@ class TestProcessExecutor : public TestFixture {
139147
"{\n"
140148
" char *a = malloc(10);\n"
141149
" return 0;\n"
142-
"}", SHOWTIME_MODES::SHOWTIME_NONE, plistOutput);
150+
"}", true, SHOWTIME_MODES::SHOWTIME_NONE, plistOutput);
143151
}
144152

145153
void no_errors_more_files() {
@@ -184,7 +192,6 @@ class TestProcessExecutor : public TestFixture {
184192
"}");
185193
}
186194

187-
188195
void markup() {
189196
const Settings settingsOld = settings;
190197
settings.library.mMarkupExtensions.emplace(".cp1");
@@ -201,7 +208,7 @@ class TestProcessExecutor : public TestFixture {
201208
" char *a = malloc(10);\n"
202209
" return 0;\n"
203210
"}",
204-
SHOWTIME_MODES::SHOWTIME_NONE, nullptr, files);
211+
false, SHOWTIME_MODES::SHOWTIME_NONE, nullptr, files);
205212
// TODO: order of "Checking" and "checked" is affected by thread
206213
/*TODO_ASSERT_EQUALS("Checking " + fprefix() + "_2.cpp ...\n"
207214
"1/4 files checked 25% done\n"
@@ -222,6 +229,70 @@ class TestProcessExecutor : public TestFixture {
222229
output.str());*/
223230
settings = settingsOld;
224231
}
232+
233+
234+
// TODO: provide data which actually shows values above 0
235+
236+
// TODO: should this be logged only once like summary?
237+
void showtime_top5() {
238+
REDIRECT;
239+
check(1, 2, 0,
240+
"int main() {}",
241+
true, SHOWTIME_MODES::SHOWTIME_TOP5);
242+
// for each file: top5 results + overall + empty line
243+
const std::string output_s = GET_REDIRECT_OUTPUT;
244+
TODO_ASSERT_EQUALS((5 + 1 + 1) * 2, 0, cppcheck::find_all_of(output_s, '\n'));
245+
}
246+
247+
void showtime_file() {
248+
REDIRECT;
249+
check(1, 2, 0,
250+
"int main() {}",
251+
true, SHOWTIME_MODES::SHOWTIME_FILE);
252+
const std::string output_s = GET_REDIRECT_OUTPUT;
253+
TODO_ASSERT_EQUALS(2, 0, cppcheck::find_all_of(output_s, "Overall time:"));
254+
}
255+
256+
void showtime_summary() {
257+
REDIRECT;
258+
check(1, 2, 0,
259+
"int main() {}",
260+
true, SHOWTIME_MODES::SHOWTIME_SUMMARY);
261+
const std::string output_s = GET_REDIRECT_OUTPUT;
262+
// should only report the actual summary once
263+
ASSERT(output_s.find("1 result(s)") == std::string::npos);
264+
TODO_ASSERT(output_s.find("2 result(s)") != std::string::npos);
265+
}
266+
267+
void showtime_top5_j() {
268+
REDIRECT; // should not cause TSAN failures as the showtime logging is synchronized
269+
check(2, 2, 0,
270+
"int main() {}",
271+
true, SHOWTIME_MODES::SHOWTIME_TOP5);
272+
// for each file: top5 results + overall + empty line
273+
const std::string output_s = GET_REDIRECT_OUTPUT;
274+
TODO_ASSERT_EQUALS((5 + 1 + 1) * 2, 0, cppcheck::find_all_of(output_s, '\n'));
275+
}
276+
277+
void showtime_file_j() {
278+
REDIRECT; // should not cause TSAN failures as the showtime logging is synchronized
279+
check(2, 2, 0,
280+
"int main() {}",
281+
true, SHOWTIME_MODES::SHOWTIME_FILE);
282+
const std::string output_s = GET_REDIRECT_OUTPUT;
283+
TODO_ASSERT_EQUALS(2, 0, cppcheck::find_all_of(output_s, "Overall time:"));
284+
}
285+
286+
void showtime_summary_j() {
287+
REDIRECT; // should not cause TSAN failures as the showtime logging is synchronized
288+
check(2, 2, 0,
289+
"int main() {}",
290+
true, SHOWTIME_MODES::SHOWTIME_SUMMARY);
291+
const std::string output_s = GET_REDIRECT_OUTPUT;
292+
// should only report the actual summary once
293+
ASSERT(output_s.find("1 result(s)") == std::string::npos);
294+
TODO_ASSERT(output_s.find("2 result(s)") != std::string::npos);
295+
}
225296
};
226297

227298
REGISTER_TEST(TestProcessExecutor)

0 commit comments

Comments
 (0)