@@ -1165,6 +1165,36 @@ def test_showtime_summary_clang_tidy_compdb(tmp_path):
11651165 __test_showtime_summary (tmp_path , use_clang_tidy = True , use_compdb = True )
11661166
11671167
1168+ @pytest .mark .skipif (not __has_clang_tidy , reason = 'clang-tidy is not available' )
1169+ def test_clang_tidy_builddir_project_configurations (tmp_path ):
1170+ test_file = tmp_path / 'test.c'
1171+ with open (test_file , 'wt' ) as f :
1172+ f .write ('int main(void) { return 0; }\n ' )
1173+
1174+ configs = '' .join (
1175+ f'<ProjectConfiguration Include="{ c } |x64"><Configuration>{ c } </Configuration><Platform>x64</Platform></ProjectConfiguration>'
1176+ for c in ('Debug' , 'Release' ))
1177+ project_file = tmp_path / 'test.vcxproj'
1178+ with open (project_file , 'wt' ) as f :
1179+ f .write ('<?xml version="1.0" encoding="utf-8"?>'
1180+ '<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">'
1181+ f'<ItemGroup Label="ProjectConfigurations">{ configs } </ItemGroup>'
1182+ '<ItemGroup><ClCompile Include="test.c" /></ItemGroup>'
1183+ '</Project>' )
1184+
1185+ build_dir = tmp_path / 'b'
1186+ os .mkdir (build_dir )
1187+
1188+ args = ['-q' , '--clang-tidy' , '--project=test.vcxproj' , '--cppcheck-build-dir=b' ]
1189+ exitcode , stdout , _ = cppcheck (args , cwd = str (tmp_path ))
1190+ assert exitcode == 0 , stdout
1191+
1192+ files = os .listdir (build_dir )
1193+ assert 'test.c.analyzerinfo.clang-tidy-cmd' not in files
1194+ for i in range (1 , 3 ):
1195+ assert f'test.a{ i } .clang-tidy-cmd' in files
1196+
1197+
11681198def __test_showtime_file_total (tmp_path , use_compdb = False ):
11691199 __test_showtime (tmp_path , 'file-total' , 0 , 'Check time: ' , use_compdb = use_compdb )
11701200
@@ -2621,6 +2651,86 @@ def test_inline_suppr_builddir_j_cached(tmp_path):
26212651 __test_inline_suppr (tmp_path , ['--cppcheck-build-dir={}' .format (build_dir ), '-j2' ])
26222652
26232653
2654+ def __test_inline_suppr_project (tmp_path , extra_args ):
2655+ test_file = tmp_path / 'test.c'
2656+ with open (test_file , 'wt' ) as f :
2657+ f .write ("""
2658+ void f() {
2659+ // cppcheck-suppress memleak
2660+ }
2661+ """ )
2662+
2663+ configs = '' .join (
2664+ f'<ProjectConfiguration Include="{ c } |x64"><Configuration>{ c } </Configuration><Platform>x64</Platform></ProjectConfiguration>'
2665+ for c in ('Debug' , 'Release' ))
2666+ project_file = tmp_path / 'test.vcxproj'
2667+ with open (project_file , 'wt' ) as f :
2668+ f .write ('<?xml version="1.0" encoding="utf-8"?>'
2669+ '<Project DefaultTargets="Build" ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">'
2670+ f'<ItemGroup Label="ProjectConfigurations">{ configs } </ItemGroup>'
2671+ '<ItemGroup><ClCompile Include="test.c" /></ItemGroup>'
2672+ '</Project>' )
2673+
2674+ args = [
2675+ '-q' ,
2676+ '--template=simple' ,
2677+ '--enable=information' ,
2678+ '--inline-suppr' ,
2679+ '--project={}' .format (project_file )
2680+ ]
2681+
2682+ args += extra_args
2683+
2684+ exitcode , stdout , stderr , = cppcheck (args )
2685+ assert exitcode == 0 , stdout
2686+ assert stdout == ''
2687+ assert stderr .splitlines () == [
2688+ '{}:4:1: information: Unmatched suppression: memleak [unmatchedSuppression]' .format (test_file )
2689+ ]
2690+
2691+
2692+ def test_inline_suppr_builddir_project_cached (tmp_path ):
2693+ build_dir = tmp_path / 'b1'
2694+ os .mkdir (build_dir )
2695+ __test_inline_suppr_project (tmp_path , ['--cppcheck-build-dir={}' .format (build_dir ), '-j1' ])
2696+ __test_inline_suppr_project (tmp_path , ['--cppcheck-build-dir={}' .format (build_dir ), '-j1' ])
2697+
2698+
2699+ def test_inline_suppr_builddir_compdb_duplicate (tmp_path ):
2700+ test_file = tmp_path / 'test.c'
2701+ with open (test_file , 'wt' ) as f :
2702+ f .write ("""
2703+ void f() {
2704+ // cppcheck-suppress memleak
2705+ }
2706+ """ )
2707+
2708+ # The same file listed twice gets one analyzer information file per entry
2709+ compdb_file = tmp_path / 'compile_commands.json'
2710+ create_compile_commands (compdb_file , [test_file , test_file ])
2711+
2712+ build_dir = tmp_path / 'b1'
2713+ os .mkdir (build_dir )
2714+
2715+ args = [
2716+ '-q' ,
2717+ '--template=simple' ,
2718+ '--enable=information' ,
2719+ '--inline-suppr' ,
2720+ '--cppcheck-build-dir={}' .format (build_dir ),
2721+ '--project={}' .format (compdb_file )
2722+ ]
2723+
2724+ exitcode , stdout , stderr , = cppcheck (args )
2725+ assert exitcode == 0 , stdout
2726+ assert stdout == ''
2727+ assert '{}:4:1: information: Unmatched suppression: memleak [unmatchedSuppression]' .format (test_file ) in stderr .splitlines ()
2728+
2729+ for afile in ('test.a1' , 'test.a2' ):
2730+ with open (build_dir / afile , 'rt' ) as f :
2731+ assert f .read ().count ('id="unmatchedSuppression"' ) == 1 , afile
2732+
2733+
26242734def test_duplicate_suppression (tmp_path ):
26252735 test_file = tmp_path / 'file.cpp'
26262736 with open (test_file , 'wt' ):
0 commit comments