Skip to content

Commit

Permalink
refs #12835 - added Python tests showing inline suppressions not work…
Browse files Browse the repository at this point in the history
…ing with whole program analysis and -j2
  • Loading branch information
firewave committed Jun 13, 2024
1 parent c71caef commit 11b0cc5
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
3 changes: 3 additions & 0 deletions test/cli/whole-program/whole1.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
// cppcheck-suppress misra-c2012-8.4
// cppcheck-suppress misra-c2012-5.8
int misra_5_8_var1;
2 changes: 2 additions & 0 deletions test/cli/whole-program/whole2.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
// cppcheck-suppress misra-c2012-5.8
static int misra_5_8_var1;
87 changes: 87 additions & 0 deletions test/cli/whole-program_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
import os
import pytest
import json
from testutils import cppcheck

__script_dir = os.path.dirname(os.path.abspath(__file__))
__proj_inline_suppres_path = 'whole-program' + os.path.sep

# TODO: use dedicated addon


def __create_compile_commands(dir, entries):
j = []
for e in entries:
f = os.path.basename(e)
obj = {
'directory': os.path.dirname(os.path.abspath(e)),
'command': 'gcc -c {}'.format(f),
'file': f
}
j.append(obj)
compile_commands = os.path.join(dir, 'compile_commmands.json')
with open(compile_commands, 'wt') as f:
f.write(json.dumps(j))
return compile_commands


def __test_suppress_inline(extra_args):
args = [
'-q',
'--addon=misra',
'--template=simple',
'--enable=information,style',
'--disable=missingInclude', # TODO: remove
'--inline-suppr',
'--error-exitcode=1',
'{}whole1.c'.format(__proj_inline_suppres_path),
'{}whole2.c'.format(__proj_inline_suppres_path)
]
args += extra_args
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
lines = stderr.splitlines()
assert lines == []
assert stdout == ''
assert ret == 0, stdout


def test_suppress_inline():
__test_suppress_inline(['-j1'])


@pytest.mark.xfail(strict=True)
def test_suppress_inline_j():
__test_suppress_inline(['-j2'])


def __test_suppress_inline_project(tmpdir, extra_args):
compile_db = __create_compile_commands(tmpdir, [
'{}whole1.c'.format(__proj_inline_suppres_path),
'{}whole2.c'.format(__proj_inline_suppres_path)
])

args = [
'-q',
'--addon=misra',
'--template=simple',
'--enable=information,style',
'--disable=missingInclude', # TODO: remove
'--inline-suppr',
'--error-exitcode=1',
'--project='.format(compile_db)
]
args += extra_args
ret, stdout, stderr = cppcheck(args, cwd=__script_dir)
lines = stderr.splitlines()
assert lines == []
assert stdout == ''
assert ret == 0, stdout


def test_suppress_inline_project():
__test_suppress_inline(['-j1'])


@pytest.mark.xfail(strict=True)
def test_suppress_inline_project_j():
__test_suppress_inline(['-j2'])

0 comments on commit 11b0cc5

Please sign in to comment.