Skip to content

Commit 223a138

Browse files
committed
added test coverage and documentation for --showtime=file-total
1 parent b7846f4 commit 223a138

6 files changed

Lines changed: 49 additions & 1 deletion

File tree

cli/cmdlineparser.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1284,6 +1284,8 @@ void CmdLineParser::printHelp()
12841284
" Show nothing (default)\n"
12851285
" * file\n"
12861286
" Show for each processed file\n"
1287+
" * file-total\n"
1288+
" Show total time only for each processed file\n"
12871289
" * summary\n"
12881290
" Show a summary at the end\n"
12891291
" * top5_file\n"

man/cppcheck.1.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -552,7 +552,7 @@ There are false positives with this option. Each result must be carefully invest
552552
</term>
553553
<listitem>
554554
<para>Show timing information. The available mode are:
555-
<glosslist><glossentry><glossterm>none</glossterm><glossdef><para>Show nothing (default)</para></glossdef></glossentry><glossentry><glossterm>file</glossterm><glossdef><para>Show for each processed file</para></glossdef></glossentry><glossentry><glossterm>summary</glossterm><glossdef><para>Show a summary at the end</para></glossdef></glossentry><glossentry><glossterm>top5_file</glossterm><glossdef><para>Show the top 5 for each processed file</para></glossdef></glossentry><glossentry><glossterm>top5_summary</glossterm><glossdef><para>Show the top 5 summary at the end</para></glossdef></glossentry><glossentry><glossterm>top5</glossterm><glossdef><para>Alias for top5_file (deprecated)</para></glossdef></glossentry></glosslist>
555+
<glosslist><glossentry><glossterm>none</glossterm><glossdef><para>Show nothing (default)</para></glossdef></glossentry><glossentry><glossterm>file</glossterm><glossdef><para>Show for each processed file</para></glossdef></glossentry><glossentry><glossterm>file-total</glossterm><glossdef><para>Show total time only for each processed file</para></glossdef></glossentry><glossentry><glossterm>summary</glossterm><glossdef><para>Show a summary at the end</para></glossdef></glossentry><glossentry><glossterm>top5_file</glossterm><glossdef><para>Show the top 5 for each processed file</para></glossdef></glossentry><glossentry><glossterm>top5_summary</glossterm><glossdef><para>Show the top 5 summary at the end</para></glossdef></glossentry><glossentry><glossterm>top5</glossterm><glossdef><para>Alias for top5_file (deprecated)</para></glossdef></glossentry></glosslist>
556556
</para>
557557
</listitem>
558558
</varlistentry>

test/testcmdlineparser.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ class TestCmdlineParser : public TestFixture {
235235
TEST_CASE(xmlverinvalid);
236236
TEST_CASE(doc);
237237
TEST_CASE(showtimeFile);
238+
TEST_CASE(showtimeFileTotal);
238239
TEST_CASE(showtimeTop5);
239240
TEST_CASE(showtimeTop5File);
240241
TEST_CASE(showtimeTop5Summary);
@@ -1593,6 +1594,15 @@ class TestCmdlineParser : public TestFixture {
15931594
ASSERT_EQUALS("", logger->str());
15941595
}
15951596

1597+
void showtimeFileTotal() {
1598+
REDIRECT;
1599+
const char * const argv[] = {"cppcheck", "--showtime=file-total", "file.cpp"};
1600+
settings->showtime = SHOWTIME_MODES::SHOWTIME_NONE;
1601+
ASSERT(parser->parseFromArgs(3, argv));
1602+
ASSERT(settings->showtime == SHOWTIME_MODES::SHOWTIME_FILE_TOTAL);
1603+
ASSERT_EQUALS("", logger->str());
1604+
}
1605+
15961606
void showtimeTop5() {
15971607
REDIRECT;
15981608
const char * const argv[] = {"cppcheck", "--showtime=top5", "file.cpp"};

test/testprocessexecutor.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,7 @@ class TestProcessExecutor : public TestFixture {
110110
TEST_CASE(showtime_top5_summary);
111111
TEST_CASE(showtime_file);
112112
TEST_CASE(showtime_summary);
113+
TEST_CASE(showtime_file_total);
113114
#endif // !WIN32
114115
}
115116

@@ -291,6 +292,17 @@ class TestProcessExecutor : public TestFixture {
291292
TODO_ASSERT(output_s.find("2 result(s)") != std::string::npos);
292293
}
293294

295+
void showtime_file_total() {
296+
REDIRECT; // should not cause TSAN failures as the showtime logging is synchronized
297+
check(2, 2, 0,
298+
"int main() {}",
299+
dinit(CheckOptions,
300+
$.showtime = SHOWTIME_MODES::SHOWTIME_FILE_TOTAL));
301+
const std::string output_s = GET_REDIRECT_OUTPUT;
302+
TODO_ASSERT(output_s.find("Check time: " + fprefix() + "_1.cpp: ") != std::string::npos);
303+
TODO_ASSERT(output_s.find("Check time: " + fprefix() + "_2.cpp: ") != std::string::npos);
304+
}
305+
294306
// TODO: test clang-tidy
295307
// TODO: test whole program analysis
296308
};

test/testsingleexecutor.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@ class TestSingleExecutorBase : public TestFixture {
155155
TEST_CASE(showtime_top5_summary);
156156
TEST_CASE(showtime_file);
157157
TEST_CASE(showtime_summary);
158+
TEST_CASE(showtime_file_total);
158159
}
159160

160161
void many_files() {
@@ -346,6 +347,17 @@ class TestSingleExecutorBase : public TestFixture {
346347
ASSERT(output_s.find("2 result(s)") != std::string::npos);
347348
}
348349

350+
void showtime_file_total() {
351+
REDIRECT;
352+
check(2, 0,
353+
"int main() {}",
354+
dinit(CheckOptions,
355+
$.showtime = SHOWTIME_MODES::SHOWTIME_FILE_TOTAL));
356+
const std::string output_s = GET_REDIRECT_OUTPUT;
357+
ASSERT(output_s.find("Check time: " + fprefix() + "_" + zpad3(1) + ".cpp: ") != std::string::npos);
358+
ASSERT(output_s.find("Check time: " + fprefix() + "_" + zpad3(2) + ".cpp: ") != std::string::npos);
359+
}
360+
349361
// TODO: test whole program analysis
350362
};
351363

test/testthreadexecutor.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,7 @@ class TestThreadExecutor : public TestFixture {
109109
TEST_CASE(showtime_top5_summary);
110110
TEST_CASE(showtime_file);
111111
TEST_CASE(showtime_summary);
112+
TEST_CASE(showtime_file_total);
112113
}
113114

114115
void deadlock_with_many_errors() {
@@ -290,6 +291,17 @@ class TestThreadExecutor : public TestFixture {
290291
ASSERT(output_s.find("2 result(s)") != std::string::npos);
291292
}
292293

294+
void showtime_file_total() {
295+
REDIRECT; // should not cause TSAN failures as the showtime logging is synchronized
296+
check(2, 2, 0,
297+
"int main() {}",
298+
dinit(CheckOptions,
299+
$.showtime = SHOWTIME_MODES::SHOWTIME_FILE_TOTAL));
300+
const std::string output_s = GET_REDIRECT_OUTPUT;
301+
ASSERT(output_s.find("Check time: " + fprefix() + "_1.cpp: ") != std::string::npos);
302+
ASSERT(output_s.find("Check time: " + fprefix() + "_2.cpp: ") != std::string::npos);
303+
}
304+
293305
// TODO: test clang-tidy
294306
// TODO: test whole program analysis
295307
};

0 commit comments

Comments
 (0)