1313from xml .etree import ElementTree
1414
1515
16+ try :
17+ # TODO: handle exitcode?
18+ subprocess .call (['clang-tidy' , '--version' ])
19+ __has_clang_tidy = True
20+ except OSError :
21+ __has_clang_tidy = False
22+
23+
1624def __remove_verbose_log (l : list ):
1725 l .remove ('Defines:' )
1826 l .remove ('Undefines:' )
@@ -954,10 +962,8 @@ def test_unused_function_include(tmpdir):
954962 __test_unused_function_include (tmpdir , [])
955963
956964
957- # TODO: test with clang-tidy
958- # TODO: test with --addon
959965# TODO: test with multiple files
960- def __test_showtime (tmp_path , showtime , exp_res , exp_last , use_compdb , extra_args = None ):
966+ def __test_showtime (tmp_path , showtime , exp_res , exp_last , use_compdb = False , use_addons = False , use_clang_tidy = False , extra_args = None ):
961967 test_file = tmp_path / 'test.cpp' # the use of C++ is intentional
962968 with open (test_file , 'wt' ) as f :
963969 f .write (
@@ -974,6 +980,17 @@ def __test_showtime(tmp_path, showtime, exp_res, exp_last, use_compdb, extra_arg
974980 '--inline-suppr'
975981 ]
976982
983+ if use_addons :
984+ args += ['--addon=misra' , '--addon=misc' ]
985+
986+ if use_clang_tidy :
987+ args += ['--clang-tidy' ]
988+ args += ['--suppress=clang-tidy-misc-use-internal-linkage' ]
989+ args += ['--suppress=clang-tidy-google-readability-casting' ]
990+ args += ['--suppress=clang-tidy-modernize-avoid-c-style-cast' ]
991+ args += ['--suppress=clang-tidy-hicpp-use-nullptr' ]
992+ args += ['--suppress=clang-tidy-modernize-use-nullptr' ]
993+
977994 if use_compdb :
978995 compdb_file = tmp_path / 'compile_commands.json'
979996 create_compile_commands (compdb_file , [test_file ])
@@ -991,6 +1008,9 @@ def __test_showtime(tmp_path, showtime, exp_res, exp_last, use_compdb, extra_arg
9911008 exp_len = exp_res
9921009 if 'cppcheck internal API usage' in stdout :
9931010 exp_len += 1
1011+ if use_addons :
1012+ exp_len += 1 # TODO: should have individual entries for each addon and whole program analysis
1013+ # TODO: add entry for clang-tidy analysis
9941014 exp_len += 1 # last line
9951015 assert len (lines ) == exp_len
9961016 for i in range (1 , exp_res ):
@@ -1000,118 +1020,154 @@ def __test_showtime(tmp_path, showtime, exp_res, exp_last, use_compdb, extra_arg
10001020 assert stderr == ''
10011021
10021022
1003- def __test_showtime_top5_file (tmp_path , use_compdb ):
1004- __test_showtime (tmp_path , 'top5_file' , 5 , 'Check time: ' , use_compdb )
1023+ def __test_showtime_top5_file (tmp_path , use_compdb = False ):
1024+ __test_showtime (tmp_path , 'top5_file' , 5 , 'Check time: ' , use_compdb = use_compdb )
10051025
10061026
10071027def test_showtime_top5_file (tmp_path ):
1008- __test_showtime_top5_file (tmp_path , False )
1028+ __test_showtime_top5_file (tmp_path )
10091029
10101030
10111031def test_showtime_top5_file_compdb (tmp_path ):
1012- __test_showtime_top5_file (tmp_path , True )
1032+ __test_showtime_top5_file (tmp_path , use_compdb = True )
10131033
10141034
10151035# 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' ])
1036+ def __test_showtime_top5_summary (tmp_path , use_compdb = False ):
1037+ __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , use_compdb = use_compdb , extra_args = ['-j1' ])
10181038
10191039
10201040def test_showtime_top5_summary (tmp_path ):
1021- __test_showtime_top5_summary (tmp_path , False )
1041+ __test_showtime_top5_summary (tmp_path )
10221042
10231043
10241044def test_showtime_top5_summary_compdb (tmp_path ):
1025- __test_showtime_top5_summary (tmp_path , True )
1045+ __test_showtime_top5_summary (tmp_path , use_compdb = True )
10261046
10271047
10281048# TODO: remove when --executor=process works
10291049def test_showtime_top5_summary_j_thread (tmp_path ):
1030- __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , False , ['-j2' , '--executor=thread' ])
1050+ __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , extra_args = ['-j2' , '--executor=thread' ])
10311051
10321052
10331053# TODO: remove when --executor=process works
10341054def test_showtime_top5_summary_compdb_j_thread (tmp_path ):
1035- __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , True , ['-j2' , '--executor=thread' ])
1055+ __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , use_compdb = True , extra_args = ['-j2' , '--executor=thread' ])
10361056
10371057
10381058# TODO: remove override when fixed
10391059@pytest .mark .skipif (sys .platform == 'win32' , reason = "requires ProcessExecutor" )
10401060@pytest .mark .xfail (strict = True ) # TODO: need to transfer the timer results to parent process - see #4452
10411061def test_showtime_top5_summary_j_process (tmp_path ):
1042- __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , False , ['-j2' , '--executor=process' ])
1062+ __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , extra_args = ['-j2' , '--executor=process' ])
10431063
10441064
10451065# TODO: remove override when fixed
10461066@pytest .mark .skipif (sys .platform == 'win32' , reason = "requires ProcessExecutor" )
10471067@pytest .mark .xfail (strict = True ) # TODO: need to transfer the timer results to parent process - see #4452
10481068def test_showtime_top5_summary_compdb_j_process (tmp_path ):
1049- __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , True , ['-j2' , '--executor=process' ])
1069+ __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , use_compdb = True , extra_args = ['-j2' , '--executor=process' ])
10501070
10511071
1052- def __test_showtime_file (tmp_path , use_compdb ):
1072+ def __test_showtime_file (tmp_path , use_compdb = False , use_addons = False , use_clang_tidy = False ):
10531073 exp_res = 79
10541074 # project analysis does not call Preprocessor::getConfig()
10551075 if use_compdb :
10561076 exp_res -= 1
1057- __test_showtime (tmp_path , 'file' , exp_res , 'Check time: ' , use_compdb )
1077+ __test_showtime (tmp_path , 'file' , exp_res , 'Check time: ' , use_compdb = use_compdb , use_addons = use_addons , use_clang_tidy = use_clang_tidy )
10581078
10591079
10601080def test_showtime_file (tmp_path ):
1061- __test_showtime_file (tmp_path , False )
1081+ __test_showtime_file (tmp_path )
10621082
10631083
10641084def test_showtime_file_compdb (tmp_path ):
1065- __test_showtime_file (tmp_path , True )
1085+ __test_showtime_file (tmp_path , use_compdb = True )
1086+
1087+
1088+ def test_showtime_file_addon (tmp_path ):
1089+ __test_showtime_file (tmp_path , use_addons = True )
1090+
1091+
1092+ def test_showtime_file_addon_compdb (tmp_path ):
1093+ __test_showtime_file (tmp_path , use_addons = True , use_compdb = True )
1094+
1095+
1096+ @pytest .mark .skipif (not __has_clang_tidy , reason = 'clang-tidy is not available' )
1097+ def test_showtime_file_clang_tidy (tmp_path ):
1098+ __test_showtime_file (tmp_path , use_clang_tidy = True )
1099+
1100+
1101+ @pytest .mark .skipif (not __has_clang_tidy , reason = 'clang-tidy is not available' )
1102+ def test_showtime_file_clang_tidy_compdb (tmp_path ):
1103+ __test_showtime_file (tmp_path , use_clang_tidy = True , use_compdb = True )
10661104
10671105
10681106# TODO: remove extra args when --executor=process works
1069- def __test_showtime_summary (tmp_path , use_compdb ):
1107+ def __test_showtime_summary (tmp_path , use_compdb = False , use_addons = False , use_clang_tidy = False ):
10701108 exp_res = 79
10711109 # project analysis does not call Preprocessor::getConfig()
10721110 if use_compdb :
10731111 exp_res -= 1
1074- __test_showtime (tmp_path , 'summary' , exp_res , 'Overall time: ' , use_compdb , ['-j1' ])
1112+ __test_showtime (tmp_path , 'summary' , exp_res , 'Overall time: ' , use_compdb = use_compdb , use_addons = use_addons , use_clang_tidy = use_clang_tidy , extra_args = ['-j1' ])
10751113
10761114
10771115def test_showtime_summary (tmp_path ):
1078- __test_showtime_summary (tmp_path , False , )
1116+ __test_showtime_summary (tmp_path )
10791117
10801118
10811119def test_showtime_summary_compdb (tmp_path ):
1082- __test_showtime_summary (tmp_path , True )
1120+ __test_showtime_summary (tmp_path , use_compdb = True )
1121+
1122+
1123+ def test_showtime_summary_addon (tmp_path ):
1124+ __test_showtime_summary (tmp_path , use_addons = True )
1125+
1126+
1127+ def test_showtime_summary_addon_compdb (tmp_path ):
1128+ __test_showtime_summary (tmp_path , use_addons = True , use_compdb = True )
1129+
1130+
1131+ @pytest .mark .skipif (not __has_clang_tidy , reason = 'clang-tidy is not available' )
1132+ def test_showtime_summary_clang_tidy (tmp_path ):
1133+ __test_showtime_summary (tmp_path , use_clang_tidy = True )
1134+
1135+
1136+ @pytest .mark .skipif (not __has_clang_tidy , reason = 'clang-tidy is not available' )
1137+ def test_showtime_summary_clang_tidy_compdb (tmp_path ):
1138+ __test_showtime_summary (tmp_path , use_clang_tidy = True , use_compdb = True )
10831139
10841140
10851141# TODO: remove when --executor=process works
10861142def test_showtime_summary_j_thread (tmp_path ):
1087- __test_showtime (tmp_path , 'summary' , 79 , 'Overall time: ' , False , ['-j2' , '--executor=thread' ])
1143+ __test_showtime (tmp_path , 'summary' , 79 , 'Overall time: ' , extra_args = ['-j2' , '--executor=thread' ])
10881144
10891145
10901146# TODO: remove when --executor=process works
10911147def test_showtime_summary_compdb_j_thread (tmp_path ):
1092- __test_showtime (tmp_path , 'summary' , 78 , 'Overall time: ' , True , ['-j2' , '--executor=thread' ])
1148+ __test_showtime (tmp_path , 'summary' , 78 , 'Overall time: ' , use_compdb = True , extra_args = ['-j2' , '--executor=thread' ])
10931149
10941150
10951151# TODO: remove override when fixed
10961152@pytest .mark .skipif (sys .platform == 'win32' , reason = "requires ProcessExecutor" )
10971153@pytest .mark .xfail (strict = True ) # TODO: need to transfer the timer results to parent process - see #4452
10981154def test_showtime_summary_j_process (tmp_path ):
1099- __test_showtime (tmp_path , 'summary' , 79 , 'Overall time: ' , False , ['-j2' , '--executor=process' ])
1155+ __test_showtime (tmp_path , 'summary' , 79 , 'Overall time: ' , extra_args = ['-j2' , '--executor=process' ])
11001156
11011157
11021158# TODO: remove override when fixed
11031159@pytest .mark .skipif (sys .platform == 'win32' , reason = "requires ProcessExecutor" )
11041160@pytest .mark .xfail (strict = True ) # TODO: need to transfer the timer results to parent process - see #4452
11051161def test_showtime_summary_compdb_j_process (tmp_path ):
1106- __test_showtime (tmp_path , 'summary' , 78 , 'Overall time: ' , True , ['-j2' , '--executor=process' ])
1162+ __test_showtime (tmp_path , 'summary' , 78 , 'Overall time: ' , use_compdb = True , extra_args = ['-j2' , '--executor=process' ])
11071163
11081164
1109- def __test_showtime_file_total (tmp_path , use_compdb ):
1110- __test_showtime (tmp_path , 'file-total' , 0 , 'Check time: ' , use_compdb )
1165+ def __test_showtime_file_total (tmp_path , use_compdb = False ):
1166+ __test_showtime (tmp_path , 'file-total' , 0 , 'Check time: ' , use_compdb = use_compdb )
11111167
11121168
11131169def test_showtime_file_total (tmp_path ):
1114- __test_showtime_file_total (tmp_path , False )
1170+ __test_showtime_file_total (tmp_path )
11151171
11161172
11171173def test_showtime_file_total_compdb (tmp_path ):
@@ -3423,13 +3479,6 @@ def test_check_unused_templates_func(tmp_path): # #13714
34233479 assert stdout .splitlines () == []
34243480 assert stderr .splitlines () == [] # no error since the unused templates are not being checked
34253481
3426- try :
3427- # TODO: handle exitcode?
3428- subprocess .call (['clang-tidy' , '--version' ])
3429- has_clang_tidy = True
3430- except OSError :
3431- has_clang_tidy = False
3432-
34333482def __test_clang_tidy (tmpdir , use_compdb ):
34343483 test_file = os .path .join (tmpdir , 'test.cpp' )
34353484 with open (test_file , 'wt' ) as f :
@@ -3460,18 +3509,18 @@ def __test_clang_tidy(tmpdir, use_compdb):
34603509 ]
34613510
34623511
3463- @pytest .mark .skipif (not has_clang_tidy , reason = 'clang-tidy is not available' )
3512+ @pytest .mark .skipif (not __has_clang_tidy , reason = 'clang-tidy is not available' )
34643513@pytest .mark .xfail (strict = True ) # TODO: clang-tidy is only invoked with FileSettings - see #12053
34653514def test_clang_tidy (tmpdir ): # #12053
34663515 __test_clang_tidy (tmpdir , False )
34673516
34683517
3469- @pytest .mark .skipif (not has_clang_tidy , reason = 'clang-tidy is not available' )
3518+ @pytest .mark .skipif (not __has_clang_tidy , reason = 'clang-tidy is not available' )
34703519def test_clang_tidy_project (tmpdir ):
34713520 __test_clang_tidy (tmpdir , True )
34723521
34733522
3474- @pytest .mark .skipif (not has_clang_tidy , reason = 'clang-tidy is not available' )
3523+ @pytest .mark .skipif (not __has_clang_tidy , reason = 'clang-tidy is not available' )
34753524def test_clang_tidy_error_exit (tmp_path ): # #13828 / #13829
34763525 test_file = tmp_path / 'test.cpp'
34773526 with open (test_file , 'wt' ) as f :
0 commit comments