2022-09-06 23:11:39 +02:00
|
|
|
|
|
|
|
# python -m pytest test-other.py
|
|
|
|
|
|
|
|
import os
|
|
|
|
import pytest
|
|
|
|
|
|
|
|
from testutils import cppcheck
|
|
|
|
|
|
|
|
def __test_missing_include(tmpdir, use_j):
|
|
|
|
test_file = os.path.join(tmpdir, 'test.c')
|
|
|
|
with open(test_file, 'wt') as f:
|
|
|
|
f.write("""
|
|
|
|
#include "test.h"
|
|
|
|
""")
|
|
|
|
|
2023-03-04 09:02:35 +01:00
|
|
|
args = ['--enable=missingInclude', '--template={file}:{line}:{column}: {severity}:{inconclusive:inconclusive:} {message} [{id}]', test_file]
|
2022-09-06 23:11:39 +02:00
|
|
|
if use_j:
|
2023-03-04 09:02:35 +01:00
|
|
|
args.insert(0, '-j2')
|
2022-09-06 23:11:39 +02:00
|
|
|
|
2023-03-04 09:02:35 +01:00
|
|
|
_, _, stderr = cppcheck(args)
|
|
|
|
assert stderr == '{}:2:0: information: Include file: "test.h" not found. [missingInclude]\n'.format(test_file)
|
2022-09-06 23:11:39 +02:00
|
|
|
|
|
|
|
def test_missing_include(tmpdir):
|
|
|
|
__test_missing_include(tmpdir, False)
|
|
|
|
|
|
|
|
def test_missing_include_j(tmpdir): #11283
|
|
|
|
__test_missing_include(tmpdir, True)
|
|
|
|
|
|
|
|
def __test_missing_include_check_config(tmpdir, use_j):
|
|
|
|
test_file = os.path.join(tmpdir, 'test.c')
|
|
|
|
with open(test_file, 'wt') as f:
|
|
|
|
f.write("""
|
|
|
|
#include "test.h"
|
|
|
|
""")
|
|
|
|
|
|
|
|
# TODO: -rp is not working requiring the full path in the assert
|
|
|
|
args = '--check-config -rp={} {}'.format(tmpdir, test_file)
|
|
|
|
if use_j:
|
|
|
|
args = '-j2 ' + args
|
|
|
|
|
|
|
|
_, _, stderr = cppcheck(args.split())
|
2023-03-04 09:02:35 +01:00
|
|
|
assert stderr == '' # --check-config no longer reports the missing includes
|
2022-09-06 23:11:39 +02:00
|
|
|
|
|
|
|
def test_missing_include_check_config(tmpdir):
|
|
|
|
__test_missing_include_check_config(tmpdir, False)
|
|
|
|
|
|
|
|
def test_missing_include_check_config_j(tmpdir):
|
|
|
|
__test_missing_include_check_config(tmpdir, True)
|