@@ -954,33 +954,58 @@ def test_unused_function_include(tmpdir):
954954 __test_unused_function_include (tmpdir , [])
955955
956956
957- # TODO: test with all other types
958- def test_showtime_top5_file ( tmpdir ):
959- test_file = os . path . join ( tmpdir , 'test.cpp' )
957+ # TODO: test with multiple files
958+ def __test_showtime ( tmp_path , showtime , exp_len , exp_last ):
959+ test_file = tmp_path / 'test.cpp'
960960 with open (test_file , 'wt' ) as f :
961- f .write ("""
962- int main(int argc)
963- {
964- }
965- """ )
961+ f .write (
962+ """
963+ void f()
964+ {
965+ (void)(*((int*)0)); // cppcheck-suppress nullPointer
966+ }
967+ """ )
966968
967- args = ['--showtime=top5_file' , '--quiet' , test_file ]
969+ args = [
970+ f'--showtime={ showtime } ' ,
971+ '--quiet' ,
972+ '--inline-suppr' ,
973+ str (test_file )
974+ ]
968975
969976 exitcode , stdout , stderr = cppcheck (args )
970- assert exitcode == 0 # TODO: needs to be 1
977+ assert exitcode == 0
971978 lines = stdout .splitlines ()
972- assert len (lines ) == 7
973- assert lines [0 ] == ''
974- for i in range (1 , 5 ):
975- if lines [i ].startswith ('valueFlowLifetime' ):
976- assert lines [i ].endswith (' - 2 result(s))' )
977- elif lines [i ].startswith ('valueFlowEnumValue' ):
978- assert lines [i ].endswith (' - 2 result(s))' )
979- else :
980- assert lines [i ].endswith (' result(s))' )
979+ assert len (lines ) == exp_len
980+ idx_last = exp_len - 1
981+ if idx_last :
982+ assert lines [0 ] == ''
983+ for i in range (1 , idx_last ):
984+ assert 'avg.' in lines [i ]
985+ assert lines [idx_last ].startswith (exp_last )
981986 assert stderr == ''
982987
983988
989+ def test_showtime_top5_file (tmp_path ):
990+ __test_showtime (tmp_path , 'top5_file' , 7 , 'Check time: ' )
991+
992+
993+ def test_showtime_top5_summary (tmp_path ):
994+ __test_showtime (tmp_path , 'top5_summary' , 7 , 'Overall time: ' )
995+
996+
997+ def test_showtime_file (tmp_path ):
998+ __test_showtime (tmp_path , 'file' , 79 , 'Check time: ' )
999+
1000+
1001+ def test_showtime_summary (tmp_path ):
1002+ __test_showtime (tmp_path , 'summary' , 79 , 'Overall time: ' )
1003+
1004+
1005+ def test_showtime_file_total (tmp_path ):
1006+ __test_showtime (tmp_path , 'file-total' , 1 , 'Check time: ' )
1007+
1008+
9841009def test_missing_addon (tmpdir ):
9851010 args = ['--addon=misra3' , '--addon=misra' , '--addon=misra2' , 'file.c' ]
9861011
0 commit comments