Skip to content

Commit

Permalink
refs #12836 - added Python tests showing inline suppressions not work…
Browse files Browse the repository at this point in the history
…ing with `unusedFunction` check and -j2 (#6522)
  • Loading branch information
firewave authored Jun 13, 2024
1 parent c71caef commit 43b4b70
Show file tree
Hide file tree
Showing 2 changed files with 74 additions and 0 deletions.
69 changes: 69 additions & 0 deletions test/cli/inline-suppress_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -282,3 +282,72 @@ def test_suppress_unmatched_inline_suppression(): # 11172
assert lines == []
assert stdout == ''
assert ret == 0, stdout


# reporting of inline unusedFunction is deferred
def __test_unused_function_unmatched(tmpdir, use_j):
args = [
'-q',
'--template=simple',
'--enable=all',
'--inline-suppr',
'proj-inline-suppress/unusedFunctionUnmatched.cpp'
]

if use_j:
args.append('-j2')
else:
args.append('-j1')

ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
lines = stderr.splitlines()
lines.sort()
assert lines == [
'{}unusedFunctionUnmatched.cpp:5:0: information: Unmatched suppression: uninitvar [unmatchedSuppression]'.format(__proj_inline_suppres_path),
'{}unusedFunctionUnmatched.cpp:5:0: information: Unmatched suppression: unusedFunction [unmatchedSuppression]'.format(__proj_inline_suppres_path)
]
assert stdout == ''
assert ret == 0, stdout


def test_unused_function_unmatched(tmpdir):
__test_unused_function_unmatched(tmpdir, False)


@pytest.mark.skip # unusedFunction does not work with -j
def test_unused_function_unmatched_j(tmpdir):
__test_unused_function_unmatched(tmpdir, True)


# reporting of inline unusedFunction is deferred
def __test_unused_function_unmatched_build_dir(tmpdir, extra_args):
args = [
'-q',
'--template=simple',
'--cppcheck-build-dir={}'.format(tmpdir),
'--enable=all',
'--inline-suppr',
'proj-inline-suppress/unusedFunctionUnmatched.cpp'
]

args = args + extra_args

ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
lines = stderr.splitlines()
lines.sort()
print(lines)
assert lines == [
'{}unusedFunctionUnmatched.cpp:5:0: information: Unmatched suppression: uninitvar [unmatchedSuppression]'.format(__proj_inline_suppres_path),
'{}unusedFunctionUnmatched.cpp:5:0: information: Unmatched suppression: unusedFunction [unmatchedSuppression]'.format(__proj_inline_suppres_path)
]
assert stdout == ''
assert ret == 0, stdout


def test_unused_function_unmatched_build_dir(tmpdir):
__test_unused_function_unmatched_build_dir(tmpdir, ['-j1'])


@pytest.mark.xfail(strict=True)
def test_unused_function_unmatched_build_dir_j(tmpdir):
__test_unused_function_unmatched_build_dir(tmpdir, ['-j2'])
5 changes: 5 additions & 0 deletions test/cli/proj-inline-suppress/unusedFunctionUnmatched.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// cppcheck-suppress unusedFunction
void f() {
// cppcheck-suppress unusedFunction
// cppcheck-suppress uninitvar
}

0 comments on commit 43b4b70

Please sign in to comment.