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,9 +962,8 @@ def test_unused_function_include(tmpdir):
954962 __test_unused_function_include (tmpdir , [])
955963
956964
957- # TODO: test with clang-tidy
958965# TODO: test with multiple files
959- def __test_showtime (tmp_path , showtime , exp_res , exp_last , use_compdb = False , use_addons = False , 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 ):
960967 test_file = tmp_path / 'test.cpp' # the use of C++ is intentional
961968 with open (test_file , 'wt' ) as f :
962969 f .write (
@@ -976,6 +983,14 @@ def __test_showtime(tmp_path, showtime, exp_res, exp_last, use_compdb=False, use
976983 if use_addons :
977984 args += ['--addon=misra' , '--addon=misc' ]
978985
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+
979994 if use_compdb :
980995 compdb_file = tmp_path / 'compile_commands.json'
981996 create_compile_commands (compdb_file , [test_file ])
@@ -995,6 +1010,7 @@ def __test_showtime(tmp_path, showtime, exp_res, exp_last, use_compdb=False, use
9951010 exp_len += 1
9961011 if use_addons :
9971012 exp_len += 1 # TODO: should have individual entries for each addon and whole program analysis
1013+ # TODO: add entry for clang-tidy analysis
9981014 exp_len += 1 # last line
9991015 assert len (lines ) == exp_len
10001016 for i in range (1 , exp_res ):
@@ -1053,12 +1069,12 @@ def test_showtime_top5_summary_compdb_j_process(tmp_path):
10531069 __test_showtime (tmp_path , 'top5_summary' , 5 , 'Overall time: ' , use_compdb = True , extra_args = ['-j2' , '--executor=process' ])
10541070
10551071
1056- def __test_showtime_file (tmp_path , use_compdb = False , use_addons = False ):
1072+ def __test_showtime_file (tmp_path , use_compdb = False , use_addons = False , use_clang_tidy = False ):
10571073 exp_res = 79
10581074 # project analysis does not call Preprocessor::getConfig()
10591075 if use_compdb :
10601076 exp_res -= 1
1061- __test_showtime (tmp_path , 'file' , exp_res , 'Check time: ' , use_compdb = use_compdb , use_addons = use_addons )
1077+ __test_showtime (tmp_path , 'file' , exp_res , 'Check time: ' , use_compdb = use_compdb , use_addons = use_addons , use_clang_tidy = use_clang_tidy )
10621078
10631079
10641080def test_showtime_file (tmp_path ):
@@ -1077,13 +1093,23 @@ def test_showtime_file_addon_compdb(tmp_path):
10771093 __test_showtime_file (tmp_path , use_addons = True , use_compdb = True )
10781094
10791095
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 )
1104+
1105+
10801106# TODO: remove extra args when --executor=process works
1081- def __test_showtime_summary (tmp_path , use_compdb = False , use_addons = False ):
1107+ def __test_showtime_summary (tmp_path , use_compdb = False , use_addons = False , use_clang_tidy = False ):
10821108 exp_res = 79
10831109 # project analysis does not call Preprocessor::getConfig()
10841110 if use_compdb :
10851111 exp_res -= 1
1086- __test_showtime (tmp_path , 'summary' , exp_res , 'Overall time: ' , use_compdb = use_compdb , use_addons = use_addons , extra_args = ['-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' ])
10871113
10881114
10891115def test_showtime_summary (tmp_path ):
@@ -1102,6 +1128,16 @@ def test_showtime_summary_addon_compdb(tmp_path):
11021128 __test_showtime_summary (tmp_path , use_addons = True , use_compdb = True )
11031129
11041130
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 )
1139+
1140+
11051141# TODO: remove when --executor=process works
11061142def test_showtime_summary_j_thread (tmp_path ):
11071143 __test_showtime (tmp_path , 'summary' , 79 , 'Overall time: ' , extra_args = ['-j2' , '--executor=thread' ])
@@ -3443,13 +3479,6 @@ def test_check_unused_templates_func(tmp_path): # #13714
34433479 assert stdout .splitlines () == []
34443480 assert stderr .splitlines () == [] # no error since the unused templates are not being checked
34453481
3446- try :
3447- # TODO: handle exitcode?
3448- subprocess .call (['clang-tidy' , '--version' ])
3449- has_clang_tidy = True
3450- except OSError :
3451- has_clang_tidy = False
3452-
34533482def __test_clang_tidy (tmpdir , use_compdb ):
34543483 test_file = os .path .join (tmpdir , 'test.cpp' )
34553484 with open (test_file , 'wt' ) as f :
0 commit comments