From 394b457b4d50f8a22753634c3587f2eb9e33697c Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 9 Sep 2024 12:35:47 +0200 Subject: [PATCH 01/12] CI-unixish.yml: fail `build` step if changed and unversioned files exist afterwards --- .github/workflows/CI-unixish.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index ebb2950733a..4cf9187c479 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -469,6 +469,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 From a6b937a823d958ced4bd7a695a516d169aaca0f5 Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 30 Oct 2024 14:56:47 +0100 Subject: [PATCH 02/12] updated `.gitignore` --- .gitignore | 7 +++++++ 1 file changed, 7 insertions(+) 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 From 7a0043bc2c0e203b67c444d1e1e0ba6117eebe33 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 1 Nov 2024 16:10:09 +0100 Subject: [PATCH 03/12] CI-unixish.yml: do not re-use a CMake output folder --- .github/workflows/CI-unixish.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index 4cf9187c479..217ee69b91c 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -410,9 +410,9 @@ jobs: - 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 cmake.output.stack -G "Unix Makefiles" -DBUILD_TESTS=On + cmake --build cmake.output.stack --target test-stacktrace -- -j$(nproc) + cp cmake.output.stack/bin/test-s* . python3 -m pytest -Werror --strict-markers -vv test/signal/test-stacktrace.py # TODO: move to scriptcheck.yml so these are tested with all Python versions? From cd9713919a20293eab5f733d223cbf42ee0a85a6 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 1 Nov 2024 16:12:09 +0100 Subject: [PATCH 04/12] CI-unixish.yml: renamed output directory to be covered by existing ignore --- .github/workflows/CI-unixish.yml | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index 217ee69b91c..7d6af0933f4 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -401,18 +401,20 @@ jobs: - 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 # no unix backtrace support on MacOs - name: Test Stacktrace if: contains(matrix.os, 'ubuntu') run: | - cmake -S . -B cmake.output.stack -G "Unix Makefiles" -DBUILD_TESTS=On - cmake --build cmake.output.stack --target test-stacktrace -- -j$(nproc) - cp cmake.output.stack/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 # TODO: move to scriptcheck.yml so these are tested with all Python versions? From b951edefda8a578226873d6d87495815cbfb2186 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 1 Nov 2024 16:13:10 +0100 Subject: [PATCH 05/12] CI-unixish.yml: delete files copied to root folder --- .github/workflows/CI-unixish.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index 7d6af0933f4..34d3a63cf06 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -406,6 +406,7 @@ jobs: # 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 @@ -416,6 +417,7 @@ jobs: # 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 From 8c4f617dff96fdf788cc04074d8b842eebb1534b Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 1 Nov 2024 16:18:16 +0100 Subject: [PATCH 06/12] do not explicitly remove files in Python tests --- test/cli/clang-import_test.py | 2 -- test/tools/htmlreport/test_htmlreport.py | 3 --- 2 files changed, 5 deletions(-) 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/tools/htmlreport/test_htmlreport.py b/test/tools/htmlreport/test_htmlreport.py index 31ac670110d..5e07442f8e2 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 @@ -108,8 +107,6 @@ def runCheck(source_filename=None, xml_version='1', xml_filename=None): yield index_contents, output_directory - shutil.rmtree(output_directory) - if __name__ == '__main__': unittest.main() From 3b3648e2848db8a77cdbeb8631bc494b9a44664d Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 1 Nov 2024 16:22:20 +0100 Subject: [PATCH 07/12] test_htmlreport.py: use `tempfile.TemporaryDirectory` instead of `tempfile.mkdtemp()` for automatic cleanup --- test/tools/htmlreport/test_htmlreport.py | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/test/tools/htmlreport/test_htmlreport.py b/test/tools/htmlreport/test_htmlreport.py index 5e07442f8e2..bb2ab86fd05 100755 --- a/test/tools/htmlreport/test_htmlreport.py +++ b/test/tools/htmlreport/test_htmlreport.py @@ -36,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)) @@ -45,6 +45,8 @@ def checkReportError(self, xml_version): self.assertIn(' Date: Mon, 2 Dec 2024 09:40:17 +0100 Subject: [PATCH 08/12] explicitly remove some test files generated in the source tree for now --- test/cli/helloworld_test.py | 6 ++++++ test/cli/proj2_test.py | 16 ++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) 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 From b851332f8c5af2b89f9188deab4a243f36665f38 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 2 Dec 2024 09:48:17 +0100 Subject: [PATCH 09/12] scriptcheck.yml: fail `scriptcheck` step if changed and unversioned files exist afterwards --- .github/workflows/scriptcheck.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/.github/workflows/scriptcheck.yml b/.github/workflows/scriptcheck.yml index df25c41688f..36f9cdf3197 100644 --- a/.github/workflows/scriptcheck.yml +++ b/.github/workflows/scriptcheck.yml @@ -190,6 +190,17 @@ jobs: 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: From 3c938eb39b53dde3729095eb3c1fd79bf99b24c9 Mon Sep 17 00:00:00 2001 From: firewave Date: Mon, 2 Dec 2024 09:49:59 +0100 Subject: [PATCH 10/12] CI-windows.yml: fail `build` step if changed and unversioned files exist afterwards --- .github/workflows/CI-windows.yml | 12 ++++++++++++ 1 file changed, 12 insertions(+) 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' From b2cd12a72be8677526ead3fd0fd876033f2f312e Mon Sep 17 00:00:00 2001 From: firewave Date: Wed, 11 Dec 2024 15:48:47 +0100 Subject: [PATCH 11/12] scriptcheck.yml: explicitly remove left-over donate-cpu-server log --- .github/workflows/scriptcheck.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/scriptcheck.yml b/.github/workflows/scriptcheck.yml index 36f9cdf3197..53f51288f0e 100644 --- a/.github/workflows/scriptcheck.yml +++ b/.github/workflows/scriptcheck.yml @@ -187,6 +187,8 @@ 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 From e58759569615770458dc25a61937ccb2141afd39 Mon Sep 17 00:00:00 2001 From: firewave Date: Fri, 13 Dec 2024 16:00:33 +0100 Subject: [PATCH 12/12] CI-unixish.yml: explicitly delete folder from install test --- .github/workflows/CI-unixish.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index 34d3a63cf06..ba8a1492b15 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -398,6 +398,7 @@ 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: |