Skip to content

Commit 5f2495f

Browse files
committed
added environment variable TEST_CPPCHECK_INJECT_BUILDDIR to inject --cppcheck-build-dir into the cppcheck invocation of Python tests [skip ci]
1 parent be04977 commit 5f2495f

6 files changed

Lines changed: 57 additions & 0 deletions

File tree

.github/workflows/CI-unixish.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,14 @@ jobs:
424424
env:
425425
TEST_CPPCHECK_INJECT_CLANG: clang
426426

427+
# do not use pushd in this step since we go below the working directory
428+
- name: Run test/cli (--cppcheck-build-dir)
429+
run: |
430+
cd test/cli
431+
python3 -m pytest -Werror --strict-markers -vv
432+
env:
433+
TEST_CPPCHECK_INJECT_BUILDDIR: injected
434+
427435
- name: Run cfg tests
428436
if: matrix.os != 'ubuntu-22.04'
429437
run: |

.github/workflows/CI-windows.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,14 @@ jobs:
191191
env:
192192
TEST_CPPCHECK_INJECT_CLANG: clang
193193

194+
- name: Run test/cli (--cppcheck-build-dir)
195+
if: matrix.config == 'release'
196+
run: |
197+
cd test/cli || exit /b !errorlevel!
198+
python -m pytest -Werror --strict-markers -vv || exit /b !errorlevel!
199+
env:
200+
TEST_CPPCHECK_INJECT_BUILDDIR: injected
201+
194202
- name: Test addons
195203
if: matrix.config == 'release'
196204
run: |

.github/workflows/asan.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,14 @@ jobs:
120120
env:
121121
TEST_CPPCHECK_INJECT_CLANG: clang
122122

123+
- name: Run test/cli (--cppcheck-build-dir)
124+
run: |
125+
pwd=$(pwd)
126+
cd test/cli
127+
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
128+
env:
129+
TEST_CPPCHECK_INJECT_BUILDDIR: injected
130+
123131
- name: Generate dependencies
124132
if: false
125133
run: |

.github/workflows/tsan.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,14 @@ jobs:
121121
env:
122122
TEST_CPPCHECK_INJECT_CLANG: clang
123123

124+
- name: Run test/cli (--cppcheck-build-dir)
125+
run: |
126+
pwd=$(pwd)
127+
cd test/cli
128+
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
129+
env:
130+
TEST_CPPCHECK_INJECT_BUILDDIR: injected
131+
124132
- name: Generate dependencies
125133
if: false
126134
run: |

.github/workflows/ubsan.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,14 @@ jobs:
119119
env:
120120
TEST_CPPCHECK_INJECT_CLANG: clang
121121

122+
- name: Run test/cli (--cppcheck-build-dir)
123+
run: |
124+
pwd=$(pwd)
125+
cd test/cli
126+
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv
127+
env:
128+
TEST_CPPCHECK_INJECT_BUILDDIR: injected
129+
122130
- name: Generate dependencies
123131
run: |
124132
# make sure auto-generated GUI files exist

test/cli/testutils.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import select
55
import subprocess
66
import time
7+
import tempfile
78

89
# Create Cppcheck project file
910
import sys
@@ -188,6 +189,19 @@ def cppcheck_ex(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_
188189
arg_executor = '--executor=' + str(os.environ['TEST_CPPCHECK_INJECT_EXECUTOR'])
189190
args.append(arg_executor)
190191

192+
builddir_tmp = None
193+
194+
if 'TEST_CPPCHECK_INJECT_BUILDDIR' in os.environ:
195+
found_builddir = False
196+
for arg in args:
197+
if arg.startswith('--cppcheck-build-dir='):
198+
found_builddir = True
199+
break
200+
if not found_builddir:
201+
builddir_tmp = tempfile.TemporaryDirectory(prefix=str(os.environ['TEST_CPPCHECK_INJECT_BUILDDIR']))
202+
arg_clang = '--cppcheck-build-dir=' + builddir_tmp.name
203+
args.append(arg_clang)
204+
191205
logging.info(exe + ' ' + ' '.join(args))
192206

193207
run_subprocess = __run_subprocess_tty if tty else __run_subprocess
@@ -196,6 +210,9 @@ def cppcheck_ex(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_
196210
stdout = stdout.decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n')
197211
stderr = stderr.decode(encoding='utf-8', errors='ignore').replace('\r\n', '\n')
198212

213+
if builddir_tmp:
214+
builddir_tmp.cleanup()
215+
199216
if remove_checkers_report:
200217
if stderr.find('[checkersReport]\n') > 0:
201218
start_id = stderr.find('[checkersReport]\n')

0 commit comments

Comments
 (0)