Fixed #10887 (compile database: include path with space is not handled)
This commit is contained in:
parent
355866f0cf
commit
760436c56e
|
@ -414,7 +414,10 @@ bool ImportProject::importCompileCommands(std::istream &istr)
|
|||
if (obj["arguments"].is<picojson::array>()) {
|
||||
for (const picojson::value& arg : obj["arguments"].get<picojson::array>()) {
|
||||
if (arg.is<std::string>()) {
|
||||
command += arg.get<std::string>() + " ";
|
||||
std::string str = arg.get<std::string>();
|
||||
if (str.find(" ") != std::string::npos)
|
||||
str = "\"" + str + "\"";
|
||||
command += str + " ";
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -59,6 +59,7 @@ private:
|
|||
TEST_CASE(importCompileCommands7); // linux: "/home/danielm/cppcheck 2"
|
||||
TEST_CASE(importCompileCommands8); // Windows: "C:\Users\danielm\cppcheck"
|
||||
TEST_CASE(importCompileCommands9);
|
||||
TEST_CASE(importCompileCommands10); // #10887: include path with space
|
||||
TEST_CASE(importCompileCommandsArgumentsSection); // Handle arguments section
|
||||
TEST_CASE(importCompileCommandsNoCommandSection); // gracefully handles malformed json
|
||||
TEST_CASE(importCppcheckGuiProject);
|
||||
|
@ -255,13 +256,33 @@ private:
|
|||
"powershell.exe -WindowStyle Hidden -NoProfile -ExecutionPolicy Bypass -File d:\\Projekte\\xyz\\firmware\\app\\xyz-lib\\build.ps1 -IAR -COMPILER_PATH \"c:\\Program Files (x86)\\IAR Systems\\Embedded Workbench 9.0\" -CONTROLLER CC1310F128 -LIB LIB_PERMANENT -COMPILER_DEFINES \"CC1310_HFXO_FREQ=24000000 DEBUG\""
|
||||
],
|
||||
"directory" : "d:\\Projekte\\xyz\\firmware\\app",
|
||||
"type" : "PRE"
|
||||
"type" : "PRE",
|
||||
"file": "1.c"
|
||||
}])";
|
||||
std::istringstream istr(json);
|
||||
TestImporter importer;
|
||||
importer.importCompileCommands(istr);
|
||||
}
|
||||
|
||||
void importCompileCommands10() const { // #10887
|
||||
const char json[] =
|
||||
R"([{
|
||||
"file": "/home/danielm/cppcheck/1/test folder/1.c" ,
|
||||
"directory": "",
|
||||
"arguments": [
|
||||
"iccavr.exe",
|
||||
"-I",
|
||||
"/home/danielm/cppcheck/test folder"
|
||||
]
|
||||
}])";
|
||||
std::istringstream istr(json);
|
||||
TestImporter importer;
|
||||
ASSERT_EQUALS(true, importer.importCompileCommands(istr));
|
||||
ASSERT_EQUALS(1, importer.fileSettings.size());
|
||||
const ImportProject::FileSettings &fs = importer.fileSettings.front();
|
||||
ASSERT_EQUALS("/home/danielm/cppcheck/test folder/", fs.includePaths.front());
|
||||
}
|
||||
|
||||
void importCompileCommandsArgumentsSection() const {
|
||||
const char json[] = "[ { \"directory\": \"/tmp/\","
|
||||
"\"arguments\": [\"gcc\", \"-c\", \"src.c\"],"
|
||||
|
|
Loading…
Reference in New Issue