added `-Werror` to pytest calls and fixed reported warnings (#5483)

This commit is contained in:
Oliver Stöneberg 2023-09-26 15:31:37 +02:00 committed by GitHub
parent a9952d9da6
commit a3ff6d53c4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 35 additions and 20 deletions

View File

@ -366,11 +366,11 @@ jobs:
- name: Run test/cli - name: Run test/cli
run: | run: |
cd test/cli cd test/cli
python3 -m pytest --strict -vv test-*.py python3 -m pytest -Werror --strict-markers -vv test-*.py
cd ../../.. cd ../../..
ln -s cppcheck 'cpp check' ln -s cppcheck 'cpp check'
cd 'cpp check/test/cli' cd 'cpp check/test/cli'
python3 -m pytest --strict -vv test-*.py python3 -m pytest -Werror --strict-markers -vv test-*.py
- name: Run cfg tests - name: Run cfg tests
if: matrix.os != 'ubuntu-22.04' if: matrix.os != 'ubuntu-22.04'

View File

@ -168,13 +168,13 @@ jobs:
copy .\bin\cppcheck.exe .\cppcheck.exe || exit /b !errorlevel! copy .\bin\cppcheck.exe .\cppcheck.exe || exit /b !errorlevel!
copy .\bin\cppcheck-core.dll .\cppcheck-core.dll || exit /b !errorlevel! copy .\bin\cppcheck-core.dll .\cppcheck-core.dll || exit /b !errorlevel!
cd test/cli || exit /b !errorlevel! cd test/cli || exit /b !errorlevel!
:: python -m pytest --strict -vv --suppress-no-test-exit-code test-clang-import.py || exit /b !errorlevel! :: python -m pytest -Werror --strict-markers -vv --suppress-no-test-exit-code test-clang-import.py || exit /b !errorlevel!
python -m pytest --strict -vv test-helloworld.py || exit /b !errorlevel! python -m pytest -Werror --strict-markers -vv test-helloworld.py || exit /b !errorlevel!
python -m pytest --strict -vv test-inline-suppress.py || exit /b !errorlevel! python -m pytest -Werror --strict-markers -vv test-inline-suppress.py || exit /b !errorlevel!
python -m pytest --strict -vv test-more-projects.py || exit /b !errorlevel! python -m pytest -Werror --strict-markers -vv test-more-projects.py || exit /b !errorlevel!
python -m pytest --strict -vv test-other.py || exit /b !errorlevel! python -m pytest -Werror --strict-markers -vv test-other.py || exit /b !errorlevel!
python -m pytest --strict -vv test-proj2.py || exit /b !errorlevel! python -m pytest -Werror --strict-markers -vv test-proj2.py || exit /b !errorlevel!
python -m pytest --strict -vv test-suppress-syntaxError.py || exit /b !errorlevel! python -m pytest -Werror --strict-markers -vv test-suppress-syntaxError.py || exit /b !errorlevel!
- name: Test addons - name: Test addons
if: matrix.config == 'release' if: matrix.config == 'release'

View File

@ -135,9 +135,18 @@ jobs:
run: | run: |
python tools/test_matchcompiler.py python tools/test_matchcompiler.py
# we cannot specify -Werror since xml/etree/ElementTree.py in Python 3.9/3.10 contains an unclosed file
- name: test addons - name: test addons
if: matrix.python-version == '3.9' || matrix.python-version == '3.10'
run: | run: |
python -m pytest --strict -vv addons/test/test-*.py python -m pytest --strict-markers -vv addons/test/test-*.py
env:
PYTHONPATH: ./addons
- name: test addons
if: matrix.python-version != '3.9' && matrix.python-version != '3.10'
run: |
python -m pytest -Werror --strict-markers -vv addons/test/test-*.py
env: env:
PYTHONPATH: ./addons PYTHONPATH: ./addons
@ -149,21 +158,21 @@ jobs:
- name: test reduce - name: test reduce
run: | run: |
python -m pytest --strict -vv tools/test_reduce.py python -m pytest -Werror --strict-markers -vv tools/test_reduce.py
env: env:
PYTHONPATH: ./tools PYTHONPATH: ./tools
- name: test donate_cpu_lib - name: test donate_cpu_lib
if: matrix.python-version != '2.7' if: matrix.python-version != '2.7'
run: | run: |
python -m pytest --strict -vv tools/test_donate_cpu_lib.py python -m pytest -Werror --strict-markers -vv tools/test_donate_cpu_lib.py
env: env:
PYTHONPATH: ./tools PYTHONPATH: ./tools
- name: test donate_cpu_server - name: test donate_cpu_server
if: matrix.python-version != '2.7' if: matrix.python-version != '2.7'
run: | run: |
python -m pytest --strict -vv tools/test_donate_cpu_server.py python -m pytest -Werror --strict-markers -vv tools/test_donate_cpu_server.py
env: env:
PYTHONPATH: ./tools PYTHONPATH: ./tools

View File

@ -1106,11 +1106,12 @@ def getAddonRules():
"""Returns dict of MISRA rules handled by this addon.""" """Returns dict of MISRA rules handled by this addon."""
addon_rules = [] addon_rules = []
compiled = re.compile(r'.*def[ ]+misra_([0-9]+)_([0-9]+)[(].*') compiled = re.compile(r'.*def[ ]+misra_([0-9]+)_([0-9]+)[(].*')
for line in open(__file__): with open(__file__) as f:
res = compiled.match(line) for line in f:
if res is None: res = compiled.match(line)
continue if res is None:
addon_rules.append(res.group(1) + '.' + res.group(2)) continue
addon_rules.append(res.group(1) + '.' + res.group(2))
return addon_rules return addon_rules
@ -4155,6 +4156,7 @@ class MisraChecker:
file_stream.readlines() file_stream.readlines()
file_stream.seek(0) file_stream.seek(0)
except UnicodeDecodeError: except UnicodeDecodeError:
file_stream.close()
file_stream = None file_stream = None
else: else:
break break
@ -4234,6 +4236,8 @@ class MisraChecker:
self.ruleTexts[rule.num] = rule self.ruleTexts[rule.num] = rule
expect_more = True expect_more = True
file_stream.close()
def verifyRuleTexts(self): def verifyRuleTexts(self):
"""Prints rule numbers without rule text.""" """Prints rule numbers without rule text."""
rule_texts_rules = [] rule_texts_rules = []

View File

@ -25,11 +25,13 @@ def dump_create(fpath, *argv):
p.communicate() p.communicate()
if p.returncode != 0: if p.returncode != 0:
raise OSError("cppcheck returns error code: %d" % p.returncode) raise OSError("cppcheck returns error code: %d" % p.returncode)
subprocess.Popen(["sync"]) p = subprocess.Popen(["sync"])
p.communicate()
def dump_remove(fpath): def dump_remove(fpath):
subprocess.Popen(["rm", "-f", fpath + ".dump"]) p = subprocess.Popen(["rm", "-f", fpath + ".dump"])
p.communicate()
def convert_json_output(raw_json_strings): def convert_json_output(raw_json_strings):