Skip to content

Commit bd94f17

Browse files
committed
TestProcessExecutor: applied TestThreadExecutor changes / use TODO asserts for currently broken tests
1 parent 1bfbb25 commit bd94f17

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
@@ -45,7 +45,7 @@ class TestProcessExecutor : public TestFixture {
4545
* Execute check using n jobs for y files which are have
4646
* identical data, given within data.
4747
*/
48-
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 = {}) {
48+
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 = {}) {
4949
errout.str("");
5050
output.str("");
5151

@@ -66,6 +66,7 @@ class TestProcessExecutor : public TestFixture {
6666

6767
settings.jobs = jobs;
6868
settings.showtime = showtime;
69+
settings.quiet = quiet;
6970
if (plistOutput)
7071
settings.plistOutput = plistOutput;
7172
// TODO: test with settings.project.fileSettings;
@@ -92,6 +93,12 @@ class TestProcessExecutor : public TestFixture {
9293
TEST_CASE(one_error_less_files);
9394
TEST_CASE(one_error_several_files);
9495
TEST_CASE(markup);
96+
TEST_CASE(showtime_top5);
97+
TEST_CASE(showtime_file);
98+
TEST_CASE(showtime_summary);
99+
TEST_CASE(showtime_top5_j);
100+
TEST_CASE(showtime_file_j);
101+
TEST_CASE(showtime_summary_j);
95102
#endif // !WIN32
96103
}
97104

@@ -107,6 +114,7 @@ class TestProcessExecutor : public TestFixture {
107114
check(2, 3, 3, oss.str());
108115
}
109116

117+
// TODO: check the output
110118
void many_threads() {
111119
check(16, 100, 100,
112120
"int main()\n"
@@ -124,7 +132,7 @@ class TestProcessExecutor : public TestFixture {
124132
"{\n"
125133
" char *a = malloc(10);\n"
126134
" return 0;\n"
127-
"}", SHOWTIME_MODES::SHOWTIME_SUMMARY);
135+
"}", true, SHOWTIME_MODES::SHOWTIME_SUMMARY);
128136
}
129137

130138
void many_threads_plist() {
@@ -136,7 +144,7 @@ class TestProcessExecutor : public TestFixture {
136144
"{\n"
137145
" char *a = malloc(10);\n"
138146
" return 0;\n"
139-
"}", SHOWTIME_MODES::SHOWTIME_NONE, plistOutput);
147+
"}", true, SHOWTIME_MODES::SHOWTIME_NONE, plistOutput);
140148
}
141149

142150
void no_errors_more_files() {
@@ -181,7 +189,6 @@ class TestProcessExecutor : public TestFixture {
181189
"}");
182190
}
183191

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

223294
REGISTER_TEST(TestProcessExecutor)

0 commit comments

Comments
 (0)