Testing; Moved test/cli tests from travis to github actions

This commit is contained in:
Daniel Marjamäki 2021-03-01 18:49:59 +01:00
parent 773ca43894
commit fef956f3f0
3 changed files with 36 additions and 32 deletions

View File

@ -24,6 +24,7 @@ jobs:
sudo apt-get install libxml2-utils
sudo apt-get install z3 libz3-dev
cp externals/z3_version_old.h externals/z3_version.h
sudo apt-get install python3-pytest
- name: Install missing software on ubuntu 20.04
if: matrix.os == 'ubuntu-20.04'
@ -31,6 +32,7 @@ jobs:
sudo apt-get update
sudo apt-get install libxml2-utils
sudo apt-get install z3 libz3-dev
sudo apt-get install python3-pytest
- name: Install missing software on macos
if: contains(matrix.os, 'macos')
@ -75,6 +77,14 @@ jobs:
run: |
make -j$(nproc) check USE_Z3=yes HAVE_RULES=yes
- name: Run test/cli
if: contains(matrix.os, 'ubuntu')
run: |
cd ..
ln -s cppcheck cpp\ check
cd cpp\ check/test/cli
pytest-3 test-*.py
- name: Validate
run: |
make -j$(nproc) checkCWEEntries validateXML

View File

@ -151,11 +151,6 @@ script:
# compile cppcheck, default build
- echo $CXXFLAGS
- make -s check -j$(nproc)
# Testing cli
- cp -R . ../cppcheck\ 2
- cd ../cppcheck\ 2/test/cli # path with space
- python -m pytest test-*.py
- cd -
# Testing addons (disabled 2020-11-24 because Travis fails, TODO try to enable these)
# - PYTHONPATH=./addons python -m pytest addons/test/test-*.py
# - PYTHONPATH=./addons python3 -m pytest addons/test/test-*.py

View File

@ -1,35 +1,34 @@
# python -m pytest test-other-projects.py
# python -m pytest test-more-projects.py
import os
import tempfile
from testutils import cppcheck
# FIXME make CI happy
#def test_project_force_U():
# # 10018
# # -U does not work with compile_commands.json
# with tempfile.TemporaryDirectory('10018') as temp_folder:
# with open(os.path.join(temp_folder, 'bug1.cpp'), 'wt') as f:
# f.write("""
# int x = 123 / 0;
# #ifdef MACRO1
# int y = 1000 / 0;
# #endif
# """)
#
# compile_commands = os.path.join(temp_folder, 'compile_commands.json')
#
# with open(compile_commands, 'wt') as f:
# f.write('[ { "directory": "%s", "command": "c++ -o bug1.o -c bug1.cpp", "file": "bug1.cpp", "output": "bug1.o" } ]' % str(temp_folder))
#
# # Without -U => both bugs are found
# ret, stdout, stderr = cppcheck(['--project=' + compile_commands, '--force', '-rp=' + temp_folder, '--template=cppcheck1'])
# assert (stderr == '[bug1.cpp:2]: (error) Division by zero.\n'
# '[bug1.cpp:4]: (error) Division by zero.\n')
#
# # With -U => only first bug is found
# ret, stdout, stderr = cppcheck(['--project=' + compile_commands, '--force', '-UMACRO1', '-rp=' + temp_folder, '--template=cppcheck1'])
# assert stderr == '[bug1.cpp:2]: (error) Division by zero.\n'
def test_project_force_U():
# 10018
# -U does not work with compile_commands.json
with tempfile.TemporaryDirectory('10018') as temp_folder:
with open(os.path.join(temp_folder, 'bug1.cpp'), 'wt') as f:
f.write("""
int x = 123 / 0;
#ifdef MACRO1
int y = 1000 / 0;
#endif
""")
compile_commands = os.path.join(temp_folder, 'compile_commands.json')
with open(compile_commands, 'wt') as f:
f.write('[ { "directory": "%s", "command": "c++ -o bug1.o -c bug1.cpp", "file": "bug1.cpp", "output": "bug1.o" } ]' % str(temp_folder))
# Without -U => both bugs are found
ret, stdout, stderr = cppcheck(['--project=' + compile_commands, '--force', '-rp=' + temp_folder, '--template=cppcheck1'])
assert (stderr == '[bug1.cpp:2]: (error) Division by zero.\n'
'[bug1.cpp:4]: (error) Division by zero.\n')
# With -U => only first bug is found
ret, stdout, stderr = cppcheck(['--project=' + compile_commands, '--force', '-UMACRO1', '-rp=' + temp_folder, '--template=cppcheck1'])
assert stderr == '[bug1.cpp:2]: (error) Division by zero.\n'