Skip to content

Commit ed38aee

Browse files
authored
refs #13437 - test/cli/other_test.py: added some suppression tests for addons (danmar#7190)
1 parent 77a6705 commit ed38aee

File tree

1 file changed

+53
-2
lines changed

1 file changed

+53
-2
lines changed

test/cli/other_test.py

Lines changed: 53 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,6 @@ def test_execute_addon_failure_json_ctu_notexist(tmpdir):
271271

272272
_, _, stderr = cppcheck(args)
273273
ec = 1 if os.name == 'nt' else 127
274-
print(stderr)
275274
assert stderr.splitlines() == [
276275
"{}:0:0: error: Bailing out from analysis: Checking file failed: Failed to execute addon 'addon.json' - exitcode is {} [internalError]".format(test_file, ec),
277276
":0:0: error: Bailing out from analysis: Whole program analysis failed: Failed to execute addon 'addon.json' - exitcode is {} [internalError]".format(ec)
@@ -2733,4 +2732,56 @@ def test_internal_error_loc_int(tmp_path):
27332732
assert stdout.splitlines() == []
27342733
assert stderr.splitlines() == [
27352734
'{}:3:13: error: Internal Error. MathLib::toBigUNumber: out_of_range: 0x10000000000000000 [internalError]'.format(test_file)
2736-
]
2735+
]
2736+
2737+
2738+
def __test_addon_suppr(tmp_path, extra_args):
2739+
test_file = tmp_path / 'test.c'
2740+
with open(test_file, 'wt') as f:
2741+
f.write("""
2742+
// cppcheck-suppress misra-c2012-2.3
2743+
typedef int MISRA_5_6_VIOLATION;
2744+
typedef int MISRA_5_6_VIOLATION_1;
2745+
""")
2746+
2747+
args = [
2748+
'-q',
2749+
'--template=simple',
2750+
'--enable=style',
2751+
'--addon=misra',
2752+
str(test_file)
2753+
]
2754+
2755+
args += extra_args
2756+
2757+
exitcode, stdout, stderr = cppcheck(args)
2758+
assert exitcode == 0, stdout
2759+
assert stdout == ''
2760+
assert stderr.splitlines() == [
2761+
'{}:4:1: style: misra violation (use --rule-texts=<file> to get proper output) [misra-c2012-2.3]'.format(test_file),
2762+
]
2763+
2764+
2765+
# TODO: remove override when all issues are fixed
2766+
def test_addon_suppr_inline(tmp_path):
2767+
__test_addon_suppr(tmp_path, ['--inline-suppr', '-j1'])
2768+
2769+
2770+
# TODO: remove override when all issues are fixed
2771+
@pytest.mark.xfail(strict=True) # TODO: inline suppression does not work
2772+
def test_addon_suppr_inline_j(tmp_path):
2773+
__test_addon_suppr(tmp_path, ['--inline-suppr', '-j2'])
2774+
2775+
2776+
def test_addon_suppr_cli_line(tmp_path):
2777+
__test_addon_suppr(tmp_path, ['--suppress=misra-c2012-2.3:*:3'])
2778+
2779+
2780+
@pytest.mark.xfail(strict=True) # #13437 - TODO: suppression needs to match the whole input path
2781+
def test_addon_suppr_cli_file_line(tmp_path):
2782+
__test_addon_suppr(tmp_path, ['--suppress=misra-c2012-2.3:test.c:3'])
2783+
2784+
2785+
def test_addon_suppr_cli_absfile_line(tmp_path):
2786+
test_file = tmp_path / 'test.c'
2787+
__test_addon_suppr(tmp_path, ['--suppress=misra-c2012-2.3:{}:3'.format(test_file)])

0 commit comments

Comments
 (0)