From ab5ce33bc070e9b8128597a355053dca6f020d3d Mon Sep 17 00:00:00 2001 From: firewave Date: Thu, 13 Jun 2024 12:31:10 +0200 Subject: [PATCH] refs #12836 - added Python tests showing inline suppressions not working with `unusedFunction` check and -j2 --- test/cli/inline-suppress_test.py | 69 +++++++++++++++++++ .../unusedFunctionUnmatched.cpp | 5 ++ 2 files changed, 74 insertions(+) create mode 100644 test/cli/proj-inline-suppress/unusedFunctionUnmatched.cpp diff --git a/test/cli/inline-suppress_test.py b/test/cli/inline-suppress_test.py index 144ba717749..78074802896 100644 --- a/test/cli/inline-suppress_test.py +++ b/test/cli/inline-suppress_test.py @@ -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']) diff --git a/test/cli/proj-inline-suppress/unusedFunctionUnmatched.cpp b/test/cli/proj-inline-suppress/unusedFunctionUnmatched.cpp new file mode 100644 index 00000000000..8bd895e99bb --- /dev/null +++ b/test/cli/proj-inline-suppress/unusedFunctionUnmatched.cpp @@ -0,0 +1,5 @@ +// cppcheck-suppress unusedFunction +void f() { + // cppcheck-suppress unusedFunction + // cppcheck-suppress uninitvar +}