99import subprocess
1010import shutil
1111
12- from testutils import cppcheck , assert_cppcheck , cppcheck_ex , __lookup_cppcheck_exe
12+ from testutils import cppcheck , assert_cppcheck , cppcheck_ex , __lookup_cppcheck_exe , create_compile_commands
1313from xml .etree import ElementTree
1414
1515
@@ -956,10 +956,9 @@ def test_unused_function_include(tmpdir):
956956
957957# TODO: test with clang-tidy
958958# TODO: test with --addon
959- # TODO: test with FileSettings
960959# TODO: test with multiple files
961- def __test_showtime (tmp_path , showtime , exp_res , exp_last , extra_args = None ):
962- test_file = tmp_path / 'test.cpp'
960+ def __test_showtime (tmp_path , showtime , exp_res , exp_last , use_compdb , extra_args = None ):
961+ test_file = tmp_path / 'test.cpp' # the use of C++ is intentional
963962 with open (test_file , 'wt' ) as f :
964963 f .write (
965964"""
@@ -972,10 +971,17 @@ def __test_showtime(tmp_path, showtime, exp_res, exp_last, extra_args=None):
972971 args = [
973972 f'--showtime={ showtime } ' ,
974973 '--quiet' ,
975- '--inline-suppr' ,
976- str (test_file )
974+ '--inline-suppr'
977975 ]
978976
977+ if use_compdb :
978+ compdb_file = tmp_path / 'compile_commands.json'
979+ create_compile_commands (compdb_file , [test_file ])
980+
981+ args .append (f'--project={ compdb_file } ' )
982+ else :
983+ args .append (str (test_file ))
984+
979985 if extra_args :
980986 args += extra_args
981987
@@ -994,50 +1000,122 @@ def __test_showtime(tmp_path, showtime, exp_res, exp_last, extra_args=None):
9941000 assert stderr == ''
9951001
9961002
1003+ def __test_showtime_top5_file (tmp_path , use_compdb ):
1004+ __test_showtime (tmp_path , 'top5_file' , 5 , 'Check time: ' , use_compdb )
1005+
1006+
9971007def test_showtime_top5_file (tmp_path ):
998- __test_showtime (tmp_path , 'top5_file' , 5 , 'Check time: ' )
1008+ __test_showtime_top5_file (tmp_path , False )
1009+
1010+
1011+ def test_showtime_top5_file_compdb (tmp_path ):
1012+ __test_showtime_top5_file (tmp_path , True )
1013+
1014+
1015+ # TODO: remove extra args when --executor=process works
1016+ def __test_showtime_top5_summary (tmp_path , use_compdb ):
1017+ __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , use_compdb , ['-j1' ])
9991018
10001019
1001- # TODO: remove extra args when --executor=process works works
10021020def test_showtime_top5_summary (tmp_path ):
1003- __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , ['-j1' ])
1021+ __test_showtime_top5_summary (tmp_path , False )
1022+
10041023
1024+ def test_showtime_top5_summary_compdb (tmp_path ):
1025+ __test_showtime_top5_summary (tmp_path , True )
10051026
1006- # TODO: remove when --executor=process works works
1027+
1028+ # TODO: remove when --executor=process works
10071029def test_showtime_top5_summary_j_thread (tmp_path ):
1008- __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , ['-j2' , '--executor=thread' ])
1030+ __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , False , ['-j2' , '--executor=thread' ])
1031+
1032+
1033+ # TODO: remove when --executor=process works
1034+ def test_showtime_top5_summary_compdb_j_thread (tmp_path ):
1035+ __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , True , ['-j2' , '--executor=thread' ])
10091036
10101037
10111038# TODO: remove override when fixed
10121039@pytest .mark .skipif (sys .platform == 'win32' , reason = "requires ProcessExecutor" )
10131040@pytest .mark .xfail (strict = True ) # TODO: need to transfer the timer results to parent process - see #4452
10141041def test_showtime_top5_summary_j_process (tmp_path ):
1015- __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , ['-j2' , '--executor=process' ])
1042+ __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , False , ['-j2' , '--executor=process' ])
1043+
1044+
1045+ # TODO: remove override when fixed
1046+ @pytest .mark .skipif (sys .platform == 'win32' , reason = "requires ProcessExecutor" )
1047+ @pytest .mark .xfail (strict = True ) # TODO: need to transfer the timer results to parent process - see #4452
1048+ def test_showtime_top5_summary_compdb_j_process (tmp_path ):
1049+ __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , True , ['-j2' , '--executor=process' ])
1050+
1051+
1052+ def __test_showtime_file (tmp_path , use_compdb ):
1053+ exp_res = 79
1054+ # project analysis does not call Preprocessor::getConfig()
1055+ if use_compdb :
1056+ exp_res -= 1
1057+ __test_showtime (tmp_path , 'file' , exp_res , 'Check time: ' , use_compdb )
10161058
10171059
10181060def test_showtime_file (tmp_path ):
1019- __test_showtime (tmp_path , 'file' , 79 , 'Check time: ' )
1061+ __test_showtime_file (tmp_path , False )
1062+
1063+
1064+ def test_showtime_file_compdb (tmp_path ):
1065+ __test_showtime_file (tmp_path , True )
1066+
1067+
1068+ # TODO: remove extra args when --executor=process works
1069+ def __test_showtime_summary (tmp_path , use_compdb ):
1070+ exp_res = 79
1071+ # project analysis does not call Preprocessor::getConfig()
1072+ if use_compdb :
1073+ exp_res -= 1
1074+ __test_showtime (tmp_path , 'summary' , exp_res , 'Overall time: ' , use_compdb , ['-j1' ])
10201075
10211076
1022- # TODO: remove extra args when --executor=process works works
10231077def test_showtime_summary (tmp_path ):
1024- __test_showtime (tmp_path , 'summary' , 79 , 'Overall time: ' , ['-j1' ])
1078+ __test_showtime_summary (tmp_path , False ,)
1079+
10251080
1081+ def test_showtime_summary_compdb (tmp_path ):
1082+ __test_showtime_summary (tmp_path , True )
10261083
1027- # TODO: remove when --executor=process works works
1084+
1085+ # TODO: remove when --executor=process works
10281086def test_showtime_summary_j_thread (tmp_path ):
1029- __test_showtime (tmp_path , 'summary' , 79 , 'Overall time: ' , ['-j2' , '--executor=thread' ])
1087+ __test_showtime (tmp_path , 'summary' , 79 , 'Overall time: ' , False , ['-j2' , '--executor=thread' ])
1088+
1089+
1090+ # TODO: remove when --executor=process works
1091+ def test_showtime_summary_compdb_j_thread (tmp_path ):
1092+ __test_showtime (tmp_path , 'summary' , 78 , 'Overall time: ' , True , ['-j2' , '--executor=thread' ])
10301093
10311094
10321095# TODO: remove override when fixed
10331096@pytest .mark .skipif (sys .platform == 'win32' , reason = "requires ProcessExecutor" )
10341097@pytest .mark .xfail (strict = True ) # TODO: need to transfer the timer results to parent process - see #4452
10351098def test_showtime_summary_j_process (tmp_path ):
1036- __test_showtime (tmp_path , 'summary' , 79 , 'Overall time: ' , ['-j2' , '--executor=process' ])
1099+ __test_showtime (tmp_path , 'summary' , 79 , 'Overall time: ' , False , ['-j2' , '--executor=process' ])
1100+
1101+
1102+ # TODO: remove override when fixed
1103+ @pytest .mark .skipif (sys .platform == 'win32' , reason = "requires ProcessExecutor" )
1104+ @pytest .mark .xfail (strict = True ) # TODO: need to transfer the timer results to parent process - see #4452
1105+ def test_showtime_summary_compdb_j_process (tmp_path ):
1106+ __test_showtime (tmp_path , 'summary' , 78 , 'Overall time: ' , True , ['-j2' , '--executor=process' ])
1107+
1108+
1109+ def __test_showtime_file_total (tmp_path , use_compdb ):
1110+ __test_showtime (tmp_path , 'file-total' , 0 , 'Check time: ' , use_compdb )
10371111
10381112
10391113def test_showtime_file_total (tmp_path ):
1040- __test_showtime (tmp_path , 'file-total' , 0 , 'Check time: ' )
1114+ __test_showtime_file_total (tmp_path , False )
1115+
1116+
1117+ def test_showtime_file_total_compdb (tmp_path ):
1118+ __test_showtime_file_total (tmp_path , True )
10411119
10421120
10431121def test_showtime_unique (tmp_path ):
0 commit comments