@@ -954,33 +954,89 @@ 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 = None ):
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+ if extra_args :
977+ args += extra_args
968978
969979 exitcode , stdout , stderr = cppcheck (args )
970- assert exitcode == 0 # TODO: needs to be 1
980+ assert exitcode == 0
971981 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))' )
982+ if 'cppcheck internal API usage' in stdout :
983+ exp_len += 1
984+ assert len ( lines ) == exp_len
985+ idx_last = exp_len - 1
986+ if idx_last :
987+ assert lines [0 ] == ''
988+ for i in range ( 1 , idx_last ):
989+ assert 'avg.' in lines [ i ]
990+ assert lines [idx_last ]. startswith ( exp_last )
981991 assert stderr == ''
982992
983993
994+ def test_showtime_top5_file (tmp_path ):
995+ __test_showtime (tmp_path , 'top5_file' , 7 , 'Check time: ' )
996+
997+
998+ # TODO: remove extra args when --executor=process works works
999+ def test_showtime_top5_summary (tmp_path ):
1000+ __test_showtime (tmp_path , 'top5_summary' , 7 , 'Overall time: ' , ['-j1' ])
1001+
1002+
1003+ # TODO: remove when --executor=process works works
1004+ def test_showtime_top5_summary_j_thread (tmp_path ):
1005+ __test_showtime (tmp_path , 'top5_summary' , 7 , 'Overall time: ' , ['-j2' , '--executor=thread' ])
1006+
1007+
1008+ # TODO: remove override when fixed
1009+ @pytest .mark .skipif (sys .platform == 'win32' , reason = "requires ProcessExecutor" )
1010+ @pytest .mark .xfail (strict = True ) # TODO: need to transfer the timer results to parent process - see #4452
1011+ def test_showtime_top5_summary_j_process (tmp_path ):
1012+ __test_showtime (tmp_path , 'top5_summary' , 7 , 'Overall time: ' , ['-j2' , '--executor=process' ])
1013+
1014+
1015+ def test_showtime_file (tmp_path ):
1016+ __test_showtime (tmp_path , 'file' , 79 , 'Check time: ' )
1017+
1018+
1019+ # TODO: remove extra args when --executor=process works works
1020+ def test_showtime_summary (tmp_path ):
1021+ __test_showtime (tmp_path , 'summary' , 79 , 'Overall time: ' , ['-j1' ])
1022+
1023+
1024+ # TODO: remove when --executor=process works works
1025+ def test_showtime_summary_j_thread (tmp_path ):
1026+ __test_showtime (tmp_path , 'summary' , 79 , 'Overall time: ' , ['-j2' , '--executor=thread' ])
1027+
1028+
1029+ # TODO: remove override when fixed
1030+ @pytest .mark .skipif (sys .platform == 'win32' , reason = "requires ProcessExecutor" )
1031+ @pytest .mark .xfail (strict = True ) # TODO: need to transfer the timer results to parent process - see #4452
1032+ def test_showtime_summary_j_process (tmp_path ):
1033+ __test_showtime (tmp_path , 'summary' , 79 , 'Overall time: ' , ['-j2' , '--executor=process' ])
1034+
1035+
1036+ def test_showtime_file_total (tmp_path ):
1037+ __test_showtime (tmp_path , 'file-total' , 1 , 'Check time: ' )
1038+
1039+
9841040def test_missing_addon (tmpdir ):
9851041 args = ['--addon=misra3' , '--addon=misra' , '--addon=misra2' , 'file.c' ]
9861042
0 commit comments