@@ -60,7 +60,7 @@ class TestSingleExecutorBase : public TestFixture {
6060 return std::to_string (i);
6161 }
6262
63- 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 = {}) {
63+ 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 = {}) {
6464 errout.str (" " );
6565 output.str (" " );
6666 settings.project .fileSettings .clear ();
@@ -90,6 +90,7 @@ class TestSingleExecutorBase : public TestFixture {
9090 }
9191
9292 settings.showtime = showtime;
93+ settings.quiet = quiet;
9394 if (plistOutput)
9495 settings.plistOutput = plistOutput;
9596 // NOLINTNEXTLINE(performance-unnecessary-value-param)
@@ -122,26 +123,25 @@ class TestSingleExecutorBase : public TestFixture {
122123 TEST_CASE (one_error_less_files);
123124 TEST_CASE (one_error_several_files);
124125 TEST_CASE (markup);
126+ TEST_CASE (showtime_top5_file);
127+ TEST_CASE (showtime_top5_summary);
128+ TEST_CASE (showtime_file);
129+ TEST_CASE (showtime_summary);
125130 }
126131
127132 void many_files () {
128- const Settings settingsOld = settings;
129- settings.quiet = false ;
130-
131133 check (100 , 100 ,
132134 " int main()\n "
133135 " {\n "
134136 " char *a = malloc(10);\n "
135137 " return 0;\n "
136- " }" );
138+ " }" , false );
137139 std::string expected;
138140 for (int i = 1 ; i <= 100 ; ++i) {
139141 expected += " Checking " + fprefix () + " _" + zpad3 (i) + " .cpp ...\n " ;
140142 expected += std::to_string (i) + " /100 files checked " + std::to_string (i) + " % done\n " ;
141143 }
142144 ASSERT_EQUALS (expected, output.str ());
143-
144- settings = settingsOld;
145145 }
146146
147147 void many_files_showtime () {
@@ -151,7 +151,7 @@ class TestSingleExecutorBase : public TestFixture {
151151 " {\n "
152152 " char *a = malloc(10);\n "
153153 " return 0;\n "
154- " }" , SHOWTIME_MODES::SHOWTIME_SUMMARY);
154+ " }" , true , SHOWTIME_MODES::SHOWTIME_SUMMARY);
155155 }
156156
157157 void many_files_plist () {
@@ -163,7 +163,7 @@ class TestSingleExecutorBase : public TestFixture {
163163 " {\n "
164164 " char *a = malloc(10);\n "
165165 " return 0;\n "
166- " }" , SHOWTIME_MODES::SHOWTIME_NONE, plistOutput);
166+ " }" , true , SHOWTIME_MODES::SHOWTIME_NONE, plistOutput);
167167 }
168168
169169 void no_errors_more_files () {
@@ -224,7 +224,7 @@ class TestSingleExecutorBase : public TestFixture {
224224 " char *a = malloc(10);\n "
225225 " return 0;\n "
226226 " }" ,
227- SHOWTIME_MODES::SHOWTIME_NONE, nullptr , files);
227+ false , SHOWTIME_MODES::SHOWTIME_NONE, nullptr , files);
228228 // TODO: filter out the "files checked" messages
229229 ASSERT_EQUALS (" Checking " + fprefix () + " _2.cpp ...\n "
230230 " 1/4 files checked 25% done\n "
@@ -237,6 +237,51 @@ class TestSingleExecutorBase : public TestFixture {
237237 settings = settingsOld;
238238 }
239239
240+ // TODO: provide data which actually shows values above 0
241+
242+ void showtime_top5_file () {
243+ REDIRECT;
244+ check (2 , 0 ,
245+ " int main() {}" ,
246+ true , SHOWTIME_MODES::SHOWTIME_TOP5_FILE);
247+ const std::string output_s = GET_REDIRECT_OUTPUT;
248+ // for each file: top5 results + overall + empty line
249+ TODO_ASSERT_EQUALS ((5 + 1 + 1 ) * 2 , (5 + 1 + 1 ), cppcheck::count_all_of (output_s, ' \n ' ));
250+ }
251+
252+ void showtime_top5_summary () {
253+ REDIRECT;
254+ check (2 , 0 ,
255+ " int main() {}" ,
256+ true , SHOWTIME_MODES::SHOWTIME_TOP5_SUMMARY);
257+ const std::string output_s = GET_REDIRECT_OUTPUT;
258+ // once: top5 results + overall + empty line
259+ TODO_ASSERT_EQUALS (5 + 1 + 1 , 0 , cppcheck::count_all_of (output_s, ' \n ' ));
260+ // should only report the top5 once
261+ ASSERT (output_s.find (" 1 result(s)" ) == std::string::npos);
262+ TODO_ASSERT (output_s.find (" 2 result(s)" ) != std::string::npos);
263+ }
264+
265+ void showtime_file () {
266+ REDIRECT;
267+ check (2 , 0 ,
268+ " int main() {}" ,
269+ true , SHOWTIME_MODES::SHOWTIME_FILE);
270+ const std::string output_s = GET_REDIRECT_OUTPUT;
271+ TODO_ASSERT_EQUALS (2 , 1 , cppcheck::count_all_of (output_s, " Overall time:" ));
272+ }
273+
274+ void showtime_summary () {
275+ REDIRECT;
276+ check (2 , 0 ,
277+ " int main() {}" ,
278+ true , SHOWTIME_MODES::SHOWTIME_SUMMARY);
279+ const std::string output_s = GET_REDIRECT_OUTPUT;
280+ // should only report the actual summary once
281+ ASSERT (output_s.find (" 1 result(s)" ) == std::string::npos);
282+ TODO_ASSERT (output_s.find (" 2 result(s)" ) != std::string::npos);
283+ }
284+
240285 // TODO: test clang-tidy
241286 // TODO: test whole program analysis
242287};
0 commit comments