From fef956f3f085cb2f5c7ad24d9a32d83eaee62625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Mon, 1 Mar 2021 18:49:59 +0100 Subject: [PATCH] Testing; Moved test/cli tests from travis to github actions --- .github/workflows/CI-unixish.yml | 10 ++++++ .travis.yml | 5 --- test/cli/test-more-projects.py | 53 ++++++++++++++++---------------- 3 files changed, 36 insertions(+), 32 deletions(-) diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index a0d4f7972..873017a24 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -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 diff --git a/.travis.yml b/.travis.yml index d66fbdf73..24da622b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/test/cli/test-more-projects.py b/test/cli/test-more-projects.py index a3852e809..1516333f8 100644 --- a/test/cli/test-more-projects.py +++ b/test/cli/test-more-projects.py @@ -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'