Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,12 @@ jobs:
env:
TEST_CPPCHECK_INJECT_CLANG: clang

- name: Run test/cli (--cppcheck-build-dir)
run: |
python3 -m pytest -Werror --strict-markers -vv test/cli
env:
TEST_CPPCHECK_INJECT_BUILDDIR: injected

- name: Run cfg tests
if: matrix.os != 'ubuntu-22.04'
run: |
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/CI-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,13 @@ jobs:
env:
TEST_CPPCHECK_INJECT_CLANG: clang

- name: Run test/cli (--cppcheck-build-dir)
if: matrix.config == 'release'
run: |
python -m pytest -Werror --strict-markers -vv test/cli || exit /b !errorlevel!
env:
TEST_CPPCHECK_INJECT_BUILDDIR: injected

- name: Test addons
if: matrix.config == 'release'
run: |
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/asan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,13 @@ jobs:
env:
TEST_CPPCHECK_INJECT_CLANG: clang

- name: Run test/cli (--cppcheck-build-dir)
run: |
pwd=$(pwd)
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test/cli
env:
TEST_CPPCHECK_INJECT_BUILDDIR: injected

- name: Generate dependencies
if: false
run: |
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/tsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,13 @@ jobs:
env:
TEST_CPPCHECK_INJECT_CLANG: clang

- name: Run test/cli (--cppcheck-build-dir)
run: |
pwd=$(pwd)
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test/cli
env:
TEST_CPPCHECK_INJECT_BUILDDIR: injected

- name: Generate dependencies
if: false
run: |
Expand Down
7 changes: 7 additions & 0 deletions .github/workflows/ubsan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,13 @@ jobs:
env:
TEST_CPPCHECK_INJECT_CLANG: clang

- name: Run test/cli (--cppcheck-build-dir)
run: |
pwd=$(pwd)
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test/cli
env:
TEST_CPPCHECK_INJECT_BUILDDIR: injected

- name: Generate dependencies
run: |
# make sure auto-generated GUI files exist
Expand Down
11 changes: 6 additions & 5 deletions test/cli/helloworld_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,24 +291,25 @@ def test_checkers_report(tmpdir):
filename = os.path.join(tmpdir, '1.txt')
args = [
f'--checkers-report={filename}',
'--no-cppcheck-build-dir', # TODO: remove this
'helloworld'
]

cppcheck(args, cwd=__script_dir)

with open(filename, 'rt') as f:
data = f.read()
assert 'No CheckAutoVariables::assignFunctionArg' in data
assert 'Yes CheckAutoVariables::autoVariables' in data
data = f.read().splitlines()
assert 'No CheckAutoVariables::assignFunctionArg require:style,warning' in data, json.dumps(data, indent=4)
assert 'Yes CheckAutoVariables::autoVariables' in data, json.dumps(data, indent=4)

args += [
'--enable=style'
]
cppcheck(args, cwd=__script_dir)
with open(filename, 'rt') as f:
data = f.read()
data = f.read().splitlines()
# checker has been activated by --enable=style
assert 'Yes CheckAutoVariables::assignFunctionArg' in data
assert 'Yes CheckAutoVariables::assignFunctionArg' in data, json.dumps(data, indent=4)


def test_missing_include_system(): # #11283
Expand Down
7 changes: 0 additions & 7 deletions test/cli/other_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -820,13 +820,6 @@ def test_unused_function_include(tmpdir):
__test_unused_function_include(tmpdir, [])


# TODO: remove when we inject builddir
def test_unused_function_include_builddir(tmpdir):
builddir = os.path.join(tmpdir, 'injected')
os.makedirs(builddir)
__test_unused_function_include(tmpdir, ['--cppcheck-build-dir={}'.format(builddir)])


# TODO: test with all other types
def test_showtime_top5_file(tmpdir):
test_file = os.path.join(tmpdir, 'test.cpp')
Expand Down
3 changes: 2 additions & 1 deletion test/cli/qml_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def __test_unused_functions(extra_args):


def test_unused_functions():
__test_unused_functions(['-j1'])
__test_unused_functions(['-j1', '--no-cppcheck-build-dir'])


def test_unused_functions_j():
Expand All @@ -45,6 +45,7 @@ def test_unused_functions_j():
'--library=qt',
'--enable=unusedFunction',
'-j2',
'--no-cppcheck-build-dir',
__project_dir
]
ret, stdout, stderr = cppcheck(args)
Expand Down
17 changes: 17 additions & 0 deletions test/cli/testutils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import select
import subprocess
import time
import tempfile

# Create Cppcheck project file
import sys
Expand Down Expand Up @@ -187,6 +188,19 @@ def cppcheck_ex(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_
arg_executor = '--executor=' + str(os.environ['TEST_CPPCHECK_INJECT_EXECUTOR'])
args.append(arg_executor)

builddir_tmp = None

if 'TEST_CPPCHECK_INJECT_BUILDDIR' in os.environ:
found_builddir = False
for arg in args:
if arg.startswith('--cppcheck-build-dir=') or arg == '--no-cppcheck-build-dir':
found_builddir = True
break
if not found_builddir:
builddir_tmp = tempfile.TemporaryDirectory(prefix=str(os.environ['TEST_CPPCHECK_INJECT_BUILDDIR']))
arg_clang = '--cppcheck-build-dir=' + builddir_tmp.name
args.append(arg_clang)

logging.info(exe + ' ' + ' '.join(args))

run_subprocess = __run_subprocess_tty if tty else __run_subprocess
Expand All @@ -195,6 +209,9 @@ def cppcheck_ex(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_
stdout = stdout.decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n')
stderr = stderr.decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n')

if builddir_tmp:
builddir_tmp.cleanup()

if remove_checkers_report:
if stderr.find('[checkersReport]\n') > 0:
start_id = stderr.find('[checkersReport]\n')
Expand Down
Loading