@@ -954,33 +954,86 @@ 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 , extra_args = [] ):
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+ """ )
968+
969+ args = [
970+ f'--showtime={ showtime } ' ,
971+ '--quiet' ,
972+ '--inline-suppr' ,
973+ str (test_file )
974+ ]
966975
967- args = [ '--showtime=top5_file' , '--quiet' , test_file ]
976+ args += extra_args
968977
969978 exitcode , stdout , stderr = cppcheck (args )
970- assert exitcode == 0 # TODO: needs to be 1
979+ assert exitcode == 0
971980 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))' )
981+ assert len (lines ) == exp_len
982+ idx_last = exp_len - 1
983+ if idx_last :
984+ assert lines [0 ] == ''
985+ for i in range (1 , idx_last ):
986+ assert 'avg.' in lines [i ]
987+ assert lines [idx_last ].startswith (exp_last )
981988 assert stderr == ''
982989
983990
991+ def test_showtime_top5_file (tmp_path ):
992+ __test_showtime (tmp_path , 'top5_file' , 7 , 'Check time: ' )
993+
994+
995+ # TODO: remove extra args when --executor=process works works
996+ def test_showtime_top5_summary_j_thread (tmp_path ):
997+ __test_showtime (tmp_path , 'top5_summary' , 7 , 'Overall time: ' , ['-j1' ])
998+
999+
1000+ # TODO: remove when --executor=process works works
1001+ def test_showtime_top5_summary_j_thread (tmp_path ):
1002+ __test_showtime (tmp_path , 'top5_summary' , 7 , 'Overall time: ' , ['-j2' , '--executor=thread' ])
1003+
1004+
1005+ # TODO: remove override when fixed
1006+ @pytest .mark .skipif (sys .platform == 'win32' , reason = "requires ProcessExecutor" )
1007+ @pytest .mark .xfail (strict = True ) # TODO: need to transfer the timer results to parent process - see #4452
1008+ def test_showtime_top5_summary_j_process (tmp_path ):
1009+ __test_showtime (tmp_path , 'top5_summary' , 7 , 'Overall time: ' , ['-j2' , '--executor=process' ])
1010+
1011+
1012+ def test_showtime_file (tmp_path ):
1013+ __test_showtime (tmp_path , 'file' , 79 , 'Check time: ' )
1014+
1015+
1016+ # TODO: remove extra args when --executor=process works works
1017+ def test_showtime_summary (tmp_path ):
1018+ __test_showtime (tmp_path , 'summary' , 79 , 'Overall time: ' , ['-j1' ])
1019+
1020+
1021+ # TODO: remove when --executor=process works works
1022+ def test_showtime_summary_j_thread (tmp_path ):
1023+ __test_showtime (tmp_path , 'summary' , 79 , 'Overall time: ' , ['-j2' , '--executor=thread' ])
1024+
1025+
1026+ # TODO: remove override when fixed
1027+ @pytest .mark .skipif (sys .platform == 'win32' , reason = "requires ProcessExecutor" )
1028+ @pytest .mark .xfail (strict = True ) # TODO: need to transfer the timer results to parent process - see #4452
1029+ def test_showtime_summary_j_process (tmp_path ):
1030+ __test_showtime (tmp_path , 'summary' , 79 , 'Overall time: ' , ['-j2' , '--executor=process' ])
1031+
1032+
1033+ def test_showtime_file_total (tmp_path ):
1034+ __test_showtime (tmp_path , 'file-total' , 1 , 'Check time: ' )
1035+
1036+
9841037def test_missing_addon (tmpdir ):
9851038 args = ['--addon=misra3' , '--addon=misra' , '--addon=misra2' , 'file.c' ]
9861039
0 commit comments