Skip to content

Commit 856282d

Browse files
committed
added environment variable TEST_CPPCHECK_INJECT_BUILDDIR to inject --cppcheck-build-dir into the cppcheck invocation of Python tests
1 parent 0a8ec90 commit 856282d

6 files changed

Lines changed: 51 additions & 0 deletions

File tree

.github/workflows/CI-unixish.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,12 @@ jobs:
355355
env:
356356
TEST_CPPCHECK_INJECT_CLANG: clang
357357

358+
- name: Run test/cli (--cppcheck-build-dir)
359+
run: |
360+
python3 -m pytest -Werror --strict-markers -vv test/cli
361+
env:
362+
TEST_CPPCHECK_INJECT_BUILDDIR: injected
363+
358364
- name: Run cfg tests
359365
if: matrix.os != 'ubuntu-22.04'
360366
run: |

.github/workflows/CI-windows.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,13 @@ jobs:
193193
env:
194194
TEST_CPPCHECK_INJECT_CLANG: clang
195195

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

.github/workflows/asan.yml

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

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

.github/workflows/tsan.yml

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

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

.github/workflows/ubsan.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,13 @@ jobs:
118118
env:
119119
TEST_CPPCHECK_INJECT_CLANG: clang
120120

121+
- name: Run test/cli (--cppcheck-build-dir)
122+
run: |
123+
pwd=$(pwd)
124+
TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test/cli
125+
env:
126+
TEST_CPPCHECK_INJECT_BUILDDIR: injected
127+
121128
- name: Generate dependencies
122129
run: |
123130
# 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
@@ -187,6 +188,19 @@ def cppcheck_ex(args, env=None, remove_checkers_report=True, cwd=None, cppcheck_
187188
arg_executor = '--executor=' + str(os.environ['TEST_CPPCHECK_INJECT_EXECUTOR'])
188189
args.append(arg_executor)
189190

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

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

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

0 commit comments

Comments
 (0)