Skip to content

Commit

Permalink
avoid cut off string in verbose command execution failure
Browse files Browse the repository at this point in the history
  • Loading branch information
firewave committed Sep 15, 2023
1 parent 9f1b44b commit 85836bd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
4 changes: 3 additions & 1 deletion lib/cppcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,9 @@ static std::vector<picojson::value> executeAddon(const AddonInfo &addonInfo,
if (result.size() > 2) {
details += "\nOutput:\n";
details += result;
details.resize(details.find_last_not_of("\n\r"));
const auto pos = details.find_last_not_of("\n\r");
if (pos != std::string::npos)
details.resize(pos + 1);
}
throw InternalError(nullptr, message, details);
}
Expand Down
3 changes: 0 additions & 3 deletions test/cli/test-other.py
Original file line number Diff line number Diff line change
Expand Up @@ -413,10 +413,7 @@ def test_invalid_addon_py_verbose(tmpdir):
Exceptio [internalError]
"""
# /tmp/pytest-of-user/pytest-10/test_invalid_addon_py_20/file.cpp:0:0: error: Bailing out from analysis: Checking file failed: Failed to execute addon 'addon1' - exitcode is 256.: python3 /home/user/CLionProjects/cppcheck/addons/runaddon.py /tmp/pytest-of-user/pytest-10/test_invalid_addon_py_20/addon1.py --cli /tmp/pytest-of-user/pytest-10/test_invalid_addon_py_20/file.cpp.24637.dump
# "C:\\Users\\Quotenjugendlicher\\AppData\\Local\\Temp\\pytest-of-Quotenjugendlicher\\pytest-15\\test_execute_addon_failure_20\\test.cpp:0:0: error: Bailing out from analysis: Checking file failed: Failed to execute addon (command: 'python5.x S:\\GitHub\\cppcheck-fw\\bin\\debug\\addons\\runaddon.py S:\\GitHub\\cppcheck-fw\\bin\\debug\\addons\\naming.py --cli C:\\Users\\Quotenjugendlicher\\AppData\\Local\\Temp\\pytest-of-Quotenjugendlicher\\pytest-15\\test_execute_addon_failure_20\\test.cpp.9892.dump'). Exitcode is nonzero. [internalError]\n\n^\n
print(stderr)
assert stderr.startswith("{}:0:0: error: Bailing out from analysis: Checking file failed: Failed to execute addon 'addon1' - exitcode is 1: ".format(test_file))
# TODO: string is cut off
assert stderr.count('Output:\nTraceback')
assert stderr.endswith('raise Exception()\nExceptio [internalError]\n\n^\n')

Expand Down

0 comments on commit 85836bd

Please sign in to comment.