Skip to content

Commit

Permalink
added -Werror to pytest calls and fixed reported warnings (#5483)
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Sep 26, 2023
1 parent a9952d9 commit a3ff6d5
Show file tree
Hide file tree
Showing 5 changed files with 35 additions and 20 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/CI-unixish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
14 changes: 7 additions & 7 deletions .github/workflows/CI-windows.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
17 changes: 13 additions & 4 deletions .github/workflows/scriptcheck.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down
14 changes: 9 additions & 5 deletions addons/misra.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -4155,6 +4156,7 @@ def loadRuleTexts(self, filename):
file_stream.readlines()
file_stream.seek(0)
except UnicodeDecodeError:
file_stream.close()
file_stream = None
else:
break
Expand Down Expand Up @@ -4234,6 +4236,8 @@ def loadRuleTexts(self, filename):
self.ruleTexts[rule.num] = rule
expect_more = True

file_stream.close()

def verifyRuleTexts(self):
"""Prints rule numbers without rule text."""
rule_texts_rules = []
Expand Down
6 changes: 4 additions & 2 deletions addons/test/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a3ff6d5

Please sign in to comment.