2019-05-03 20:19:28 +02:00
|
|
|
|
|
|
|
# python -m pytest test-inline-suppress.py
|
|
|
|
|
2020-11-04 21:01:48 +01:00
|
|
|
import json
|
2019-05-03 20:19:28 +02:00
|
|
|
import os
|
2021-06-12 18:19:00 +02:00
|
|
|
import tempfile
|
2019-05-03 20:19:28 +02:00
|
|
|
from testutils import cppcheck
|
|
|
|
|
2020-11-04 21:01:48 +01:00
|
|
|
def create_unused_function_compile_commands():
|
2021-01-31 10:14:22 +01:00
|
|
|
prjpath = os.path.realpath('proj-inline-suppress-unusedFunction')
|
|
|
|
compile_commands = os.path.join(prjpath, 'compile_commands.json')
|
2020-11-04 21:01:48 +01:00
|
|
|
j = [{'directory': prjpath,
|
|
|
|
'command': '/usr/bin/c++ -I"' + prjpath + '" -o "' + os.path.join(prjpath, 'B.cpp.o') + '" -c "' + os.path.join(prjpath, 'B.cpp') + '"',
|
|
|
|
'file': os.path.join(prjpath, 'B.cpp')},
|
|
|
|
{'directory': prjpath,
|
|
|
|
'command': '/usr/bin/c++ -I"' + prjpath + '" -o "' + os.path.join(prjpath, 'A.cpp.o') + '" -c "' + os.path.join(prjpath, 'A.cpp') + '"',
|
|
|
|
'file': os.path.join(prjpath, 'A.cpp')}]
|
|
|
|
with open(compile_commands, 'wt') as f:
|
|
|
|
f.write(json.dumps(j, indent=4))
|
|
|
|
|
2019-05-03 20:19:28 +02:00
|
|
|
def test1():
|
2020-09-11 18:29:42 +02:00
|
|
|
ret, stdout, stderr = cppcheck(['--inline-suppr', 'proj-inline-suppress'])
|
2021-04-03 21:22:39 +02:00
|
|
|
assert ret == 0, stdout
|
2020-09-10 21:46:15 +02:00
|
|
|
assert stderr == ''
|
2019-05-03 20:19:28 +02:00
|
|
|
|
|
|
|
def test2():
|
2020-09-11 18:29:42 +02:00
|
|
|
ret, stdout, stderr = cppcheck(['proj-inline-suppress'])
|
2021-04-03 21:22:39 +02:00
|
|
|
assert ret == 0, stdout
|
2019-05-03 20:19:28 +02:00
|
|
|
assert len(stderr) > 0
|
|
|
|
|
2019-08-17 17:49:22 +02:00
|
|
|
def test_unmatched_suppression():
|
2019-08-17 17:51:48 +02:00
|
|
|
ret, stdout, stderr = cppcheck(['--inline-suppr', '--enable=information', '--error-exitcode=1', 'proj-inline-suppress/2.c'])
|
2019-08-17 17:49:22 +02:00
|
|
|
assert ret == 1
|
|
|
|
assert 'Unmatched suppression: some_warning_id' in stderr
|
2020-07-30 22:22:54 +02:00
|
|
|
|
2020-08-03 10:30:21 +02:00
|
|
|
def test_unmatched_suppression_path_with_extra_stuf():
|
2020-07-30 22:22:54 +02:00
|
|
|
ret, stdout, stderr = cppcheck(['--inline-suppr', '--enable=information', '--error-exitcode=1', './proj-inline-suppress/2.c'])
|
|
|
|
assert ret == 1
|
|
|
|
assert 'Unmatched suppression: some_warning_id' in stderr
|
2020-10-04 16:42:09 +02:00
|
|
|
|
|
|
|
def test_backwards_compatibility():
|
|
|
|
ret, stdout, stderr = cppcheck(['proj-inline-suppress/3.cpp'])
|
|
|
|
assert '[zerodiv]' in stderr
|
|
|
|
|
|
|
|
ret, stdout, stderr = cppcheck(['--inline-suppr', 'proj-inline-suppress/3.cpp'])
|
2021-04-03 21:22:39 +02:00
|
|
|
assert ret == 0, stdout
|
2020-10-04 16:42:09 +02:00
|
|
|
assert stderr == ''
|
2020-11-04 21:01:48 +01:00
|
|
|
|
|
|
|
def test_compile_commands_unused_function():
|
|
|
|
create_unused_function_compile_commands()
|
|
|
|
ret, stdout, stderr = cppcheck(['--enable=all', '--error-exitcode=1', '--project=./proj-inline-suppress-unusedFunction/compile_commands.json'])
|
|
|
|
assert ret == 1
|
|
|
|
assert 'unusedFunction' in stderr
|
|
|
|
|
|
|
|
def test_compile_commands_unused_function_suppression():
|
|
|
|
create_unused_function_compile_commands()
|
|
|
|
ret, stdout, stderr = cppcheck(['--enable=all', '--inline-suppr', '--error-exitcode=1', '--project=./proj-inline-suppress-unusedFunction/compile_commands.json'])
|
2021-04-03 21:22:39 +02:00
|
|
|
assert ret == 0, stdout
|
2020-11-04 21:01:48 +01:00
|
|
|
assert 'unusedFunction' not in stderr
|
2021-06-12 18:19:00 +02:00
|
|
|
|
|
|
|
|
|
|
|
def test_build_dir():
|
|
|
|
with tempfile.TemporaryDirectory() as tempdir:
|
|
|
|
args = f'--cppcheck-build-dir={tempdir} --enable=all --inline-suppr proj-inline-suppress/4.c'.split()
|
|
|
|
|
|
|
|
ret, stdout, stderr = cppcheck(args)
|
|
|
|
assert ret == 0, stdout
|
|
|
|
assert len(stderr) == 0
|
|
|
|
|
|
|
|
ret, stdout, stderr = cppcheck(args)
|
|
|
|
assert ret == 0, stdout
|
|
|
|
assert len(stderr) == 0
|
|
|
|
|
|
|
|
|