diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index ebb2950733a..ba8a1492b15 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -398,22 +398,27 @@ jobs: run: | # this is only to test the "install" target - since we did not build with FILESDIR it would not work as intended make DESTDIR=cppcheck-make-install FILESDIR=/share/Cppcheck install + rm -rf cppcheck-make-install - name: Test Signalhandler run: | - cmake -S . -B cmake.output.signal -G "Unix Makefiles" -DBUILD_TESTS=On - cmake --build cmake.output.signal --target test-signalhandler -- -j$(nproc) - cp cmake.output.signal/bin/test-s* . + cmake -S . -B build.cmake.signal -G "Unix Makefiles" -DBUILD_TESTS=On + cmake --build build.cmake.signal --target test-signalhandler -- -j$(nproc) + # TODO: how to run this without copying the file? + cp build.cmake.signal/bin/test-s* . python3 -m pytest -Werror --strict-markers -vv test/signal/test-signalhandler.py + rm test-signalhandler # no unix backtrace support on MacOs - name: Test Stacktrace if: contains(matrix.os, 'ubuntu') run: | - cmake -S . -B cmake.output.signal -G "Unix Makefiles" -DBUILD_TESTS=On - cmake --build cmake.output.signal --target test-stacktrace -- -j$(nproc) - cp cmake.output.signal/bin/test-s* . + cmake -S . -B build.cmake.stack -G "Unix Makefiles" -DBUILD_TESTS=On + cmake --build build.cmake.stack --target test-stacktrace -- -j$(nproc) + # TODO: how to run this without copying the file? + cp build.cmake.stack/bin/test-s* . python3 -m pytest -Werror --strict-markers -vv test/signal/test-stacktrace.py + rm test-stacktrace # TODO: move to scriptcheck.yml so these are tested with all Python versions? - name: Test addons @@ -469,6 +474,17 @@ jobs: warnings="-pedantic -Wall -Wextra -Wcast-qual -Wno-deprecated-declarations -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wno-long-long -Wpacked -Wredundant-decls -Wundef -Wno-shadow -Wno-missing-field-initializers -Wno-missing-braces -Wno-sign-compare -Wno-multichar" g++ $warnings -c -Ilib -Iexternals/tinyxml2 democlient/democlient.cpp + - name: Show all ignored files + if: false # TODO: currently lists all the contents of ignored folders - we only need what actually matched + run: | + git ls-files --others --ignored --exclude-standard + + - name: Check for changed and unversioned files + run: | + # TODO: how to do this with a single command? + git status --ignored=no + git status --ignored=no | grep -q 'working tree clean' + selfcheck: needs: build # wait for all tests to be successful first diff --git a/.github/workflows/CI-windows.yml b/.github/workflows/CI-windows.yml index 18ccaf3bbf7..14fb2f06ba1 100644 --- a/.github/workflows/CI-windows.yml +++ b/.github/workflows/CI-windows.yml @@ -251,3 +251,15 @@ jobs: cd test\cfg cl.exe windows.cpp -DUNICODE=1 -D_UNICODE=1 /Zs || exit /b !errorlevel! cl.exe mfc.cpp /EHsc /Zs || exit /b !errorlevel! + + - name: Show all ignored files + if: false # TODO: currently lists all the contents of ignored folders - we only need what actually matched + run: | + git ls-files --others --ignored --exclude-standard || exit /b !errorlevel! + + - name: Check for changed and unversioned files + run: | + :: TODO: how to do this with a single command? + git status --ignored=no + :: TODO: make this work + :: git status --ignored=no | grep -q 'working tree clean' diff --git a/.github/workflows/scriptcheck.yml b/.github/workflows/scriptcheck.yml index df25c41688f..53f51288f0e 100644 --- a/.github/workflows/scriptcheck.yml +++ b/.github/workflows/scriptcheck.yml @@ -187,9 +187,22 @@ jobs: - name: test donate_cpu_server run: | python -m pytest -Werror --strict-markers -vv tools/donate_cpu_server_test.py + # TODO: why is this file generated? also should be in a temporary folder if possible + rm -f tools/donate-cpu-server.log env: PYTHONPATH: ./tools + - name: Show all ignored files + if: false # TODO: currently lists all the contents of ignored folders - we only need what actually matched + run: | + git ls-files --others --ignored --exclude-standard + + - name: Check for changed and unversioned files + run: | + # TODO: how to do this with a single command? + git status --ignored=no + git status --ignored=no | grep -q 'working tree clean' + dmake: strategy: matrix: diff --git a/.gitignore b/.gitignore index bcc91b69fcb..9cc49844943 100644 --- a/.gitignore +++ b/.gitignore @@ -119,3 +119,10 @@ compile_commands.json /addons/misra.spec /htmlreport/cppcheck-htmlreport.spec /htmlreport/dist + +# ccache folder in CI +/.ccache + +# PCRE Windows files +/externals/pcre.h +/externals/pcre64.lib \ No newline at end of file diff --git a/test/cli/clang-import_test.py b/test/cli/clang-import_test.py index 077a9009dab..af1acf5cd5f 100644 --- a/test/cli/clang-import_test.py +++ b/test/cli/clang-import_test.py @@ -49,7 +49,6 @@ def __check_symbol_database(tmpdir, code): f.write(code) ret1, stdout1, _ = cppcheck(['--clang', '--debug', '-v', testfile]) ret2, stdout2, _ = cppcheck(['--debug', '-v', testfile]) - os.remove(testfile) assert 0 == ret1, stdout1 assert 0 == ret2, stdout2 assert __get_debug_section('### Symbol database', stdout1) == __get_debug_section('### Symbol database', stdout2) @@ -61,7 +60,6 @@ def __check_ast(tmpdir, code): f.write(code) ret1, stdout1, _ = cppcheck(['--clang', '--debug', '-v', testfile]) ret2, stdout2, _ = cppcheck(['--debug', '-v', testfile]) - os.remove(testfile) assert 0 == ret1, stdout1 assert 0 == ret2, stdout1 assert __get_debug_section('##AST', stdout1) == __get_debug_section('##AST', stdout2) diff --git a/test/cli/helloworld_test.py b/test/cli/helloworld_test.py index 7d269694972..011d9175e4d 100644 --- a/test/cli/helloworld_test.py +++ b/test/cli/helloworld_test.py @@ -110,6 +110,7 @@ def test_addon_relative_path(): def test_addon_with_gui_project(): project_file = os.path.join('helloworld', 'test.cppcheck') + # TODO: generate in temporary folder create_gui_project_file(os.path.join(__script_dir, project_file), paths=['.'], addon='misra') args = [ '--template=cppcheck1', @@ -117,6 +118,7 @@ def test_addon_with_gui_project(): '--project=' + project_file ] ret, stdout, stderr = cppcheck(args, cwd=__script_dir) + os.remove(os.path.join(__script_dir, project_file)) # TODO: do not remove explicitly filename = os.path.join('helloworld', 'main.c') assert ret == 0, stdout assert stdout == 'Checking %s ...\n' % filename @@ -230,6 +232,7 @@ def test_suppress_command_line_absolute(): def test_suppress_project_relative(): project_file = os.path.join('helloworld', 'test.cppcheck') + # TODO: generate in temporary folder create_gui_project_file(os.path.join(__script_dir, project_file), paths=['.'], suppressions=[{'fileName':'main.c', 'id':'zerodiv'}]) @@ -239,12 +242,14 @@ def test_suppress_project_relative(): ] ret, stdout, stderr = cppcheck(args, cwd=__script_dir) + os.remove(os.path.join(__script_dir, project_file)) # TODO: do not remove explicitly assert ret == 0, stdout assert stderr == '' def test_suppress_project_absolute(): project_file = os.path.join('helloworld', 'test.cppcheck') + # TODO: generate in temporary folder create_gui_project_file(os.path.join(__script_dir, project_file), paths=['.'], suppressions=[{'fileName':'main.c', 'id':'zerodiv'}]) @@ -254,6 +259,7 @@ def test_suppress_project_absolute(): ] ret, stdout, stderr = cppcheck(args) + os.remove(os.path.join(__script_dir, project_file)) # TODO: do not remove explicitly assert ret == 0, stdout assert stderr == '' diff --git a/test/cli/proj2_test.py b/test/cli/proj2_test.py index 2fdecbb07b3..2c7affa0651 100644 --- a/test/cli/proj2_test.py +++ b/test/cli/proj2_test.py @@ -85,10 +85,12 @@ def test_gui_project_loads_compile_commands_1(): def test_gui_project_loads_compile_commands_2(): __create_compile_commands() exclude_path_1 = 'proj2/b' + # TODO: generate in temporary folder create_gui_project_file(os.path.join(__proj_dir, 'test.cppcheck'), import_project='compile_commands.json', exclude_paths=[exclude_path_1]) ret, stdout, _ = cppcheck(['--project=' + os.path.join('proj2','test.cppcheck')], cwd=__script_dir) + os.remove(os.path.join(__proj_dir, 'test.cppcheck')) # TODO: do not remove explicitly file1 = os.path.join('proj2', 'a', 'a.c') file2 = os.path.join('proj2', 'b', 'b.c') # Excluded by test.cppcheck assert ret == 0, stdout @@ -97,8 +99,9 @@ def test_gui_project_loads_compile_commands_2(): def test_gui_project_loads_relative_vs_solution(): - create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), import_project='proj2/proj2.sln') + create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), import_project='proj2/proj2.sln') # TODO: generate in temporary folder ret, stdout, _ = cppcheck(['--project=test.cppcheck'], cwd=__script_dir) + os.remove(os.path.join(__script_dir, 'test.cppcheck')) # TODO: do not remove explicitly file1 = os.path.join('proj2', 'a', 'a.c') file2 = os.path.join('proj2', 'b', 'b.c') assert ret == 0, stdout @@ -112,8 +115,9 @@ def test_gui_project_loads_relative_vs_solution(): assert stdout.find('Checking %s Release|x64...' % file2) >= 0 def test_gui_project_loads_absolute_vs_solution(): - create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), import_project=os.path.join(__proj_dir, 'proj2.sln')) + create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), import_project=os.path.join(__proj_dir, 'proj2.sln')) # TODO: generate in temporary folder ret, stdout, _ = cppcheck(['--project=test.cppcheck'], cwd=__script_dir) + os.remove(os.path.join(__script_dir, 'test.cppcheck')) # TODO: do not remove explicitly file1 = os.path.join(__proj_dir, 'a', 'a.c') file2 = os.path.join(__proj_dir, 'b', 'b.c') assert ret == 0, stdout @@ -127,21 +131,25 @@ def test_gui_project_loads_absolute_vs_solution(): assert stdout.find('Checking %s Release|x64...' % file2) >= 0 def test_gui_project_loads_relative_vs_solution_2(): - create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), root_path='proj2', import_project='proj2/proj2.sln') + create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), root_path='proj2', import_project='proj2/proj2.sln') # TODO: generate in temporary folder ret, stdout, stderr = cppcheck(['--project=test.cppcheck'], cwd=__script_dir) + os.remove(os.path.join(__script_dir, 'test.cppcheck')) # TODO: do not remove explicitly assert ret == 0, stdout assert stderr == __ERR_A + __ERR_B def test_gui_project_loads_relative_vs_solution_with_exclude(): - create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), root_path='proj2', import_project='proj2/proj2.sln', exclude_paths=['b']) + create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), root_path='proj2', import_project='proj2/proj2.sln', exclude_paths=['b']) # TODO: generate in temporary folder ret, stdout, stderr = cppcheck(['--project=test.cppcheck'], cwd=__script_dir) + os.remove(os.path.join(__script_dir, 'test.cppcheck')) # TODO: do not remove explicitly assert ret == 0, stdout assert stderr == __ERR_A def test_gui_project_loads_absolute_vs_solution_2(): + # TODO: generate in temporary folder create_gui_project_file(os.path.join(__script_dir, 'test.cppcheck'), root_path=__proj_dir, import_project=os.path.join(__proj_dir, 'proj2.sln')) ret, stdout, stderr = cppcheck(['--project=test.cppcheck'], cwd=__script_dir) + os.remove(os.path.join(__script_dir, 'test.cppcheck')) # TODO: do not remove explicitly assert ret == 0, stdout assert stderr == __ERR_A + __ERR_B diff --git a/test/tools/htmlreport/test_htmlreport.py b/test/tools/htmlreport/test_htmlreport.py index 31ac670110d..bb2ab86fd05 100755 --- a/test/tools/htmlreport/test_htmlreport.py +++ b/test/tools/htmlreport/test_htmlreport.py @@ -3,7 +3,6 @@ import os import contextlib -import shutil import subprocess import sys import tempfile @@ -37,7 +36,7 @@ def checkReportError(self, xml_version): self.assertIn('Memory leak:', report) self.assertIn('bad.c', report) - detail_filename = os.path.join(output_directory, '0.html') + detail_filename = os.path.join(output_directory.name, '0.html') self.assertTrue( os.path.exists(detail_filename)) @@ -46,6 +45,8 @@ def checkReportError(self, xml_version): self.assertIn('