Skip to content

Commit 43b4b70

Browse files
authored
refs #12836 - added Python tests showing inline suppressions not working with unusedFunction check and -j2 (#6522)
1 parent c71caef commit 43b4b70

2 files changed

Lines changed: 74 additions & 0 deletions

File tree

test/cli/inline-suppress_test.py

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,3 +282,72 @@ def test_suppress_unmatched_inline_suppression(): # 11172
282282
assert lines == []
283283
assert stdout == ''
284284
assert ret == 0, stdout
285+
286+
287+
# reporting of inline unusedFunction is deferred
288+
def __test_unused_function_unmatched(tmpdir, use_j):
289+
args = [
290+
'-q',
291+
'--template=simple',
292+
'--enable=all',
293+
'--inline-suppr',
294+
'proj-inline-suppress/unusedFunctionUnmatched.cpp'
295+
]
296+
297+
if use_j:
298+
args.append('-j2')
299+
else:
300+
args.append('-j1')
301+
302+
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
303+
lines = stderr.splitlines()
304+
lines.sort()
305+
assert lines == [
306+
'{}unusedFunctionUnmatched.cpp:5:0: information: Unmatched suppression: uninitvar [unmatchedSuppression]'.format(__proj_inline_suppres_path),
307+
'{}unusedFunctionUnmatched.cpp:5:0: information: Unmatched suppression: unusedFunction [unmatchedSuppression]'.format(__proj_inline_suppres_path)
308+
]
309+
assert stdout == ''
310+
assert ret == 0, stdout
311+
312+
313+
def test_unused_function_unmatched(tmpdir):
314+
__test_unused_function_unmatched(tmpdir, False)
315+
316+
317+
@pytest.mark.skip # unusedFunction does not work with -j
318+
def test_unused_function_unmatched_j(tmpdir):
319+
__test_unused_function_unmatched(tmpdir, True)
320+
321+
322+
# reporting of inline unusedFunction is deferred
323+
def __test_unused_function_unmatched_build_dir(tmpdir, extra_args):
324+
args = [
325+
'-q',
326+
'--template=simple',
327+
'--cppcheck-build-dir={}'.format(tmpdir),
328+
'--enable=all',
329+
'--inline-suppr',
330+
'proj-inline-suppress/unusedFunctionUnmatched.cpp'
331+
]
332+
333+
args = args + extra_args
334+
335+
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
336+
lines = stderr.splitlines()
337+
lines.sort()
338+
print(lines)
339+
assert lines == [
340+
'{}unusedFunctionUnmatched.cpp:5:0: information: Unmatched suppression: uninitvar [unmatchedSuppression]'.format(__proj_inline_suppres_path),
341+
'{}unusedFunctionUnmatched.cpp:5:0: information: Unmatched suppression: unusedFunction [unmatchedSuppression]'.format(__proj_inline_suppres_path)
342+
]
343+
assert stdout == ''
344+
assert ret == 0, stdout
345+
346+
347+
def test_unused_function_unmatched_build_dir(tmpdir):
348+
__test_unused_function_unmatched_build_dir(tmpdir, ['-j1'])
349+
350+
351+
@pytest.mark.xfail(strict=True)
352+
def test_unused_function_unmatched_build_dir_j(tmpdir):
353+
__test_unused_function_unmatched_build_dir(tmpdir, ['-j2'])
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// cppcheck-suppress unusedFunction
2+
void f() {
3+
// cppcheck-suppress unusedFunction
4+
// cppcheck-suppress uninitvar
5+
}

0 commit comments

Comments
 (0)