Skip to content

Commit 46b3715

Browse files
committed
test
1 parent 6f95fcb commit 46b3715

1 file changed

Lines changed: 65 additions & 0 deletions

File tree

‎test/cli/other_test.py‎

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
11681198
def __test_showtime_file_total(tmp_path, use_compdb=False):
11691199
__test_showtime(tmp_path, 'file-total', 0, 'Check time: ', use_compdb=use_compdb)
11701200

@@ -2666,6 +2696,41 @@ def test_inline_suppr_builddir_project_cached(tmp_path):
26662696
__test_inline_suppr_project(tmp_path, ['--cppcheck-build-dir={}'.format(build_dir), '-j1'])
26672697

26682698

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+
26692734
def test_duplicate_suppression(tmp_path):
26702735
test_file = tmp_path / 'file.cpp'
26712736
with open(test_file, 'wt'):

0 commit comments

Comments
 (0)