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
run: |
cd test/cli
python3 -m pytest --strict -vv test-*.py
python3 -m pytest -Werror --strict-markers -vv test-*.py
cd ../../..
ln -s cppcheck 'cpp check'
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
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-core.dll .\cppcheck-core.dll || 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 --strict -vv test-helloworld.py || exit /b !errorlevel!
python -m pytest --strict -vv test-inline-suppress.py || exit /b !errorlevel!
python -m pytest --strict -vv test-more-projects.py || exit /b !errorlevel!
python -m pytest --strict -vv test-other.py || exit /b !errorlevel!
python -m pytest --strict -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 --suppress-no-test-exit-code test-clang-import.py || exit /b !errorlevel!
python -m pytest -Werror --strict-markers -vv test-helloworld.py || exit /b !errorlevel!
python -m pytest -Werror --strict-markers -vv test-inline-suppress.py || exit /b !errorlevel!
python -m pytest -Werror --strict-markers -vv test-more-projects.py || exit /b !errorlevel!
python -m pytest -Werror --strict-markers -vv test-other.py || exit /b !errorlevel!
python -m pytest -Werror --strict-markers -vv test-proj2.py || exit /b !errorlevel!
python -m pytest -Werror --strict-markers -vv test-suppress-syntaxError.py || exit /b !errorlevel!
- name: Test addons
if: matrix.config == 'release'

View File

@ -135,9 +135,18 @@ jobs:
run: |
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
if: matrix.python-version == '3.9' || matrix.python-version == '3.10'
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:
PYTHONPATH: ./addons
@ -149,21 +158,21 @@ jobs:
- name: test reduce
run: |
python -m pytest --strict -vv tools/test_reduce.py
python -m pytest -Werror --strict-markers -vv tools/test_reduce.py
env:
PYTHONPATH: ./tools
- name: test donate_cpu_lib
if: matrix.python-version != '2.7'
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:
PYTHONPATH: ./tools
- name: test donate_cpu_server
if: matrix.python-version != '2.7'
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:
PYTHONPATH: ./tools

View File

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

View File

@ -25,11 +25,13 @@ def dump_create(fpath, *argv):
p.communicate()
if p.returncode != 0:
raise OSError("cppcheck returns error code: %d" % p.returncode)
subprocess.Popen(["sync"])
p = subprocess.Popen(["sync"])
p.communicate()
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):