From c1da4314aa67e686d32124e5112678e6eaf96baf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Oliver=20St=C3=B6neberg?= Date: Sat, 13 Jan 2024 16:12:34 +0100 Subject: [PATCH] fixed #12308 - adjusted Python test files to match pytest conventions (#5870) This allows the tests to be picked up automatically instead of specifying patterns or filenames. --- .github/workflows/CI-unixish.yml | 4 ++-- .github/workflows/CI-windows.yml | 8 +------- .github/workflows/asan.yml | 2 +- .github/workflows/scriptcheck.yml | 10 +++++----- .github/workflows/tsan.yml | 2 +- .github/workflows/ubsan.yml | 2 +- addons/test/{test-misra.py => misra_test.py} | 0 addons/test/{test-y2038.py => y2038_test.py} | 0 lib/importproject.cpp | 4 +++- .../cli/{test-clang-import.py => clang-import_test.py} | 9 ++++++++- test/cli/{test-helloworld.py => helloworld_test.py} | 0 ...test-inline-suppress.py => inline-suppress_test.py} | 0 .../{test-more-projects.py => more-projects_test.py} | 0 test/cli/{test-other.py => other_test.py} | 0 test/cli/{test-performance.py => performance_test.py} | 0 test/cli/{test-proj2.py => proj2_test.py} | 0 test/cli/{test-project.py => project_test.py} | 7 ++++++- test/cli/{test-qml.py => qml_test.py} | 0 ...ess-syntaxError.py => suppress-syntaxError_test.py} | 0 .../{test_donate_cpu_lib.py => donate_cpu_lib_test.py} | 0 ..._donate_cpu_server.py => donate_cpu_server_test.py} | 0 tools/{test_reduce.py => reduce_test.py} | 0 22 files changed, 28 insertions(+), 20 deletions(-) rename addons/test/{test-misra.py => misra_test.py} (100%) rename addons/test/{test-y2038.py => y2038_test.py} (100%) rename test/cli/{test-clang-import.py => clang-import_test.py} (95%) rename test/cli/{test-helloworld.py => helloworld_test.py} (100%) rename test/cli/{test-inline-suppress.py => inline-suppress_test.py} (100%) rename test/cli/{test-more-projects.py => more-projects_test.py} (100%) rename test/cli/{test-other.py => other_test.py} (100%) rename test/cli/{test-performance.py => performance_test.py} (100%) rename test/cli/{test-proj2.py => proj2_test.py} (100%) rename test/cli/{test-project.py => project_test.py} (95%) rename test/cli/{test-qml.py => qml_test.py} (100%) rename test/cli/{test-suppress-syntaxError.py => suppress-syntaxError_test.py} (100%) rename tools/{test_donate_cpu_lib.py => donate_cpu_lib_test.py} (100%) rename tools/{test_donate_cpu_server.py => donate_cpu_server_test.py} (100%) rename tools/{test_reduce.py => reduce_test.py} (100%) diff --git a/.github/workflows/CI-unixish.yml b/.github/workflows/CI-unixish.yml index e28f435fd85..89d734a730c 100644 --- a/.github/workflows/CI-unixish.yml +++ b/.github/workflows/CI-unixish.yml @@ -391,11 +391,11 @@ jobs: - name: Run test/cli run: | cd test/cli - python3 -m pytest -Werror --strict-markers -vv test-*.py + python3 -m pytest -Werror --strict-markers -vv cd ../../.. ln -s cppcheck 'cpp check' cd 'cpp check/test/cli' - python3 -m pytest -Werror --strict-markers -vv test-*.py + python3 -m pytest -Werror --strict-markers -vv - name: Run cfg tests if: matrix.os != 'ubuntu-22.04' diff --git a/.github/workflows/CI-windows.yml b/.github/workflows/CI-windows.yml index 1de7af8d99d..510b2cf4645 100644 --- a/.github/workflows/CI-windows.yml +++ b/.github/workflows/CI-windows.yml @@ -168,13 +168,7 @@ 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 -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! + python -m pytest -Werror --strict-markers -vv || exit /b !errorlevel! - name: Test addons if: matrix.config == 'release' diff --git a/.github/workflows/asan.yml b/.github/workflows/asan.yml index cc2f4a405e8..a1210b9b94e 100644 --- a/.github/workflows/asan.yml +++ b/.github/workflows/asan.yml @@ -98,7 +98,7 @@ jobs: run: | pwd=$(pwd) cd test/cli - TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test-*.py + TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv - name: Generate dependencies if: false diff --git a/.github/workflows/scriptcheck.yml b/.github/workflows/scriptcheck.yml index 1850d855b4a..2e8d6efa173 100644 --- a/.github/workflows/scriptcheck.yml +++ b/.github/workflows/scriptcheck.yml @@ -143,14 +143,14 @@ jobs: - name: test addons if: matrix.python-version == '3.9' || matrix.python-version == '3.10' run: | - python -m pytest --strict-markers -vv addons/test/test-*.py + python -m pytest --strict-markers -vv addons/test 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 + python -m pytest -Werror --strict-markers -vv addons/test env: PYTHONPATH: ./addons @@ -162,21 +162,21 @@ jobs: - name: test reduce run: | - python -m pytest -Werror --strict-markers -vv tools/test_reduce.py + python -m pytest -Werror --strict-markers -vv tools/reduce_test.py env: PYTHONPATH: ./tools - name: test donate_cpu_lib if: matrix.python-version != '2.7' run: | - python -m pytest -Werror --strict-markers -vv tools/test_donate_cpu_lib.py + python -m pytest -Werror --strict-markers -vv tools/donate_cpu_lib_test.py env: PYTHONPATH: ./tools - name: test donate_cpu_server if: matrix.python-version != '2.7' run: | - python -m pytest -Werror --strict-markers -vv tools/test_donate_cpu_server.py + python -m pytest -Werror --strict-markers -vv tools/donate_cpu_server_test.py env: PYTHONPATH: ./tools diff --git a/.github/workflows/tsan.yml b/.github/workflows/tsan.yml index 8c76c507d0d..949fd7b7552 100644 --- a/.github/workflows/tsan.yml +++ b/.github/workflows/tsan.yml @@ -97,7 +97,7 @@ jobs: run: | pwd=$(pwd) cd test/cli - TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test-*.py + TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv - name: Generate dependencies if: false diff --git a/.github/workflows/ubsan.yml b/.github/workflows/ubsan.yml index a48fcb4a501..8dbae3238da 100644 --- a/.github/workflows/ubsan.yml +++ b/.github/workflows/ubsan.yml @@ -97,7 +97,7 @@ jobs: run: | pwd=$(pwd) cd test/cli - TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv test-*.py + TEST_CPPCHECK_EXE_LOOKUP_PATH="$pwd/cmake.output" python3 -m pytest -Werror --strict-markers -vv - name: Generate dependencies run: | diff --git a/addons/test/test-misra.py b/addons/test/misra_test.py similarity index 100% rename from addons/test/test-misra.py rename to addons/test/misra_test.py diff --git a/addons/test/test-y2038.py b/addons/test/y2038_test.py similarity index 100% rename from addons/test/test-y2038.py rename to addons/test/y2038_test.py diff --git a/lib/importproject.cpp b/lib/importproject.cpp index 16bcc2e471f..39818d0c0ce 100644 --- a/lib/importproject.cpp +++ b/lib/importproject.cpp @@ -455,9 +455,11 @@ bool ImportProject::importSln(std::istream &istr, const std::string &path, const if (pos1 == std::string::npos) continue; std::string vcxproj(line.substr(pos1+1, pos-pos1+7)); + vcxproj = Path::toNativeSeparators(std::move(vcxproj)); if (!Path::isAbsolute(vcxproj)) vcxproj = path + vcxproj; - if (!importVcxproj(Path::fromNativeSeparators(vcxproj), variables, emptyString, fileFilters)) { + vcxproj = Path::fromNativeSeparators(std::move(vcxproj)); + if (!importVcxproj(vcxproj, variables, emptyString, fileFilters)) { printError("failed to load '" + vcxproj + "' from Visual Studio solution"); return false; } diff --git a/test/cli/test-clang-import.py b/test/cli/clang-import_test.py similarity index 95% rename from test/cli/test-clang-import.py rename to test/cli/clang-import_test.py index b18ec348e45..fc98a4cf773 100644 --- a/test/cli/test-clang-import.py +++ b/test/cli/clang-import_test.py @@ -4,6 +4,8 @@ import os import re import subprocess +import sys + import pytest from testutils import cppcheck, assert_cppcheck @@ -13,6 +15,11 @@ pytest.skip("'clang' does not exist", allow_module_level=True) +# the IDs differ with Visual Studio +if sys.platform == 'win32': + pytest.skip(allow_module_level=True) + + def get_debug_section(title, stdout): s = re.sub(r'0x[0-9a-fA-F]+', '0x12345678', stdout) s = re.sub(r'nestedIn: Struct', 'nestedIn: Class', s) @@ -129,7 +136,7 @@ def test_log(tmpdir): args = ['--clang', test_file] out_lines = [ - 'Checking {} ...'.format(test_file), + 'Checking {} ...'.format(test_file).replace('\\', '/'), ] assert_cppcheck(args, ec_exp=0, err_exp=[], out_exp=out_lines) \ No newline at end of file diff --git a/test/cli/test-helloworld.py b/test/cli/helloworld_test.py similarity index 100% rename from test/cli/test-helloworld.py rename to test/cli/helloworld_test.py diff --git a/test/cli/test-inline-suppress.py b/test/cli/inline-suppress_test.py similarity index 100% rename from test/cli/test-inline-suppress.py rename to test/cli/inline-suppress_test.py diff --git a/test/cli/test-more-projects.py b/test/cli/more-projects_test.py similarity index 100% rename from test/cli/test-more-projects.py rename to test/cli/more-projects_test.py diff --git a/test/cli/test-other.py b/test/cli/other_test.py similarity index 100% rename from test/cli/test-other.py rename to test/cli/other_test.py diff --git a/test/cli/test-performance.py b/test/cli/performance_test.py similarity index 100% rename from test/cli/test-performance.py rename to test/cli/performance_test.py diff --git a/test/cli/test-proj2.py b/test/cli/proj2_test.py similarity index 100% rename from test/cli/test-proj2.py rename to test/cli/proj2_test.py diff --git a/test/cli/test-project.py b/test/cli/project_test.py similarity index 95% rename from test/cli/test-project.py rename to test/cli/project_test.py index 8f6e221f765..8ac243007ba 100644 --- a/test/cli/test-project.py +++ b/test/cli/project_test.py @@ -3,6 +3,7 @@ import pytest import os import json +import sys from testutils import cppcheck @@ -49,6 +50,8 @@ def test_json_entry_file_not_found(tmpdir): ] expected = "'{}' from compilation database does not exist".format(os.path.join(tmpdir, "bug1.cpp")) + if sys.platform == "win32": + expected = expected.replace('\\', '/') _test_project_error(tmpdir, "json", json.dumps(compilation_db), expected) @@ -117,7 +120,9 @@ def test_sln_project_file_not_found(tmpdir): "EndProject\r\n" expected = "Visual Studio project file is not a valid XML - XML_ERROR_FILE_NOT_FOUND\n" \ - "cppcheck: error: failed to load '{}' from Visual Studio solution".format(os.path.join(tmpdir, "cli\\cli.vcxproj")) + "cppcheck: error: failed to load '{}' from Visual Studio solution".format(os.path.join(tmpdir, "cli/cli.vcxproj")) + if sys.platform == "win32": + expected = expected.replace('\\', '/') _test_project_error(tmpdir, "sln", content, expected) diff --git a/test/cli/test-qml.py b/test/cli/qml_test.py similarity index 100% rename from test/cli/test-qml.py rename to test/cli/qml_test.py diff --git a/test/cli/test-suppress-syntaxError.py b/test/cli/suppress-syntaxError_test.py similarity index 100% rename from test/cli/test-suppress-syntaxError.py rename to test/cli/suppress-syntaxError_test.py diff --git a/tools/test_donate_cpu_lib.py b/tools/donate_cpu_lib_test.py similarity index 100% rename from tools/test_donate_cpu_lib.py rename to tools/donate_cpu_lib_test.py diff --git a/tools/test_donate_cpu_server.py b/tools/donate_cpu_server_test.py similarity index 100% rename from tools/test_donate_cpu_server.py rename to tools/donate_cpu_server_test.py diff --git a/tools/test_reduce.py b/tools/reduce_test.py similarity index 100% rename from tools/test_reduce.py rename to tools/reduce_test.py