From c0bb44dc95e759eb1eddc7ea0b88e98b5708aa03 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Fri, 27 Jun 2025 10:36:27 +0200 Subject: [PATCH 1/3] add test --- test/cli/other_test.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/test/cli/other_test.py b/test/cli/other_test.py index 8008e2fc862..ddb8c8ba54b 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -243,6 +243,30 @@ def test_execute_addon_failure_json_notexist(tmpdir): assert stderr == "{}:0:0: error: Bailing out from analysis: Checking file failed: Failed to execute addon 'addon.json' - exitcode is {} [internalError]\n\n^\n".format(test_file, ec) +@pytest.mark.skipif(sys.platform != "win32", reason="Windows specific issue") +def test_execute_addon_path_with_spaces(tmpdir): + addon_json = os.path.join(tmpdir, 'addon.json') + addon_executable = os.path.join(tmpdir, 'A Folder', 'addon.exe') + with open(addon_json, 'wt') as f: + f.write(json.dumps({'executable': addon_executable })) + + test_file = os.path.join(tmpdir, 'test.cpp') + with open(test_file, 'wt') as f: + pass + + args = [ + '--addon={}'.format(addon_json), + test_file, + '--verbose', + '--debug' + ] + + _, _, stderr = cppcheck(args) + + # Make sure the full command is used + assert 'The system cannot find the path specified. [internalError]' in stderr + + def test_execute_addon_failure_json_ctu_notexist(tmpdir): # specify non-existent python executable so execution of addon fails addon_json = os.path.join(tmpdir, 'addon.json') From a69d5ddbb68051e51a70c997985bbb0179001f61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Fri, 27 Jun 2025 10:23:11 +0200 Subject: [PATCH 2/3] fix #13968 --- cli/cppcheckexecutor.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/cli/cppcheckexecutor.cpp b/cli/cppcheckexecutor.cpp index c61534b0881..0e30939a77e 100644 --- a/cli/cppcheckexecutor.cpp +++ b/cli/cppcheckexecutor.cpp @@ -712,9 +712,10 @@ int CppCheckExecutor::executeCommand(std::string exe, std::vector a joinedArgs += arg; } - const std::string cmd = exe + " " + joinedArgs + " " + redirect; + std::string cmd = exe + " " + joinedArgs + " " + redirect; #ifdef _WIN32 + cmd = "\"" + cmd + "\""; FILE* p = _popen(cmd.c_str(), "r"); #else FILE *p = popen(cmd.c_str(), "r"); From f21a29d79069ca898a0e972642af85335f381b76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludvig=20Gunne=20Lindstr=C3=B6m?= Date: Wed, 2 Jul 2025 09:55:16 +0200 Subject: [PATCH 3/3] update test --- test/cli/other_test.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/test/cli/other_test.py b/test/cli/other_test.py index ddb8c8ba54b..e430dc3fd06 100644 --- a/test/cli/other_test.py +++ b/test/cli/other_test.py @@ -246,9 +246,16 @@ def test_execute_addon_failure_json_notexist(tmpdir): @pytest.mark.skipif(sys.platform != "win32", reason="Windows specific issue") def test_execute_addon_path_with_spaces(tmpdir): addon_json = os.path.join(tmpdir, 'addon.json') - addon_executable = os.path.join(tmpdir, 'A Folder', 'addon.exe') + addon_dir = os.path.join(tmpdir, 'A Folder') + addon_script = os.path.join(addon_dir, 'addon.bat') + with open(addon_json, 'wt') as f: - f.write(json.dumps({'executable': addon_executable })) + f.write(json.dumps({'executable': addon_script })) + + os.makedirs(addon_dir, exist_ok=True) + + with open(addon_script, 'wt') as f: + f.write('@echo {"file":"1.c","linenr":1,"column":1,"severity":"error","message":"hello world","errorId":"hello","addon":"test"}') test_file = os.path.join(tmpdir, 'test.cpp') with open(test_file, 'wt') as f: @@ -257,14 +264,12 @@ def test_execute_addon_path_with_spaces(tmpdir): args = [ '--addon={}'.format(addon_json), test_file, - '--verbose', - '--debug' ] _, _, stderr = cppcheck(args) # Make sure the full command is used - assert 'The system cannot find the path specified. [internalError]' in stderr + assert '1.c:1:1: error: hello world [test-hello]\n' in stderr def test_execute_addon_failure_json_ctu_notexist(tmpdir):