fix trailing / from CMAKE JSON file and update unittests to cover both (w and w/o cases) (#1592)
* fix for CMake compile_commands.json input - director does not include trailing / which makes include directories wrong - so add it if it doesnt exist * fix the bugfix for trailing / in the directory name of CMAKE JSON file, add also new test case to see if it works in both cases (with and without trailing /) * revert adding accidental new line
This commit is contained in:
parent
0c93e0c8cb
commit
45def06d59
|
@ -260,7 +260,14 @@ void ImportProject::importCompileCommands(std::istream &istr)
|
|||
|
||||
for (const picojson::value &fileInfo : v.get<picojson::array>()) {
|
||||
picojson::object obj = fileInfo.get<picojson::object>();
|
||||
const std::string directory = Path::fromNativeSeparators(obj["directory"].get<std::string>());
|
||||
std::string dirpath = obj["directory"].get<std::string>();
|
||||
|
||||
/* CMAKE produces the directory without trailing / so add it if not
|
||||
* there - it is needed by setIncludePaths() */
|
||||
if(!endsWith(dirpath, '/'))
|
||||
dirpath += '/';
|
||||
|
||||
const std::string directory = Path::fromNativeSeparators(dirpath);
|
||||
const std::string command = obj["command"].get<std::string>();
|
||||
const std::string file = Path::fromNativeSeparators(obj["file"].get<std::string>());
|
||||
|
||||
|
|
|
@ -45,6 +45,7 @@ private:
|
|||
TEST_CASE(setIncludePaths3); // macro names are case insensitive
|
||||
TEST_CASE(importCompileCommands1);
|
||||
TEST_CASE(importCompileCommands2); // #8563
|
||||
TEST_CASE(importCompileCommands3); // check with existing trailing / in directory
|
||||
}
|
||||
|
||||
void setDefines() const {
|
||||
|
@ -113,6 +114,17 @@ private:
|
|||
ASSERT_EQUALS(1, importer.fileSettings.size());
|
||||
ASSERT_EQUALS("/tmp/src.c", importer.fileSettings.begin()->filename);
|
||||
}
|
||||
|
||||
void importCompileCommands3() const {
|
||||
const char json[] = "[ { \"directory\": \"/tmp/\","
|
||||
"\"command\": \"gcc -c src.c\","
|
||||
"\"file\": \"src.c\" } ]";
|
||||
std::istringstream istr(json);
|
||||
TestImporter importer;
|
||||
importer.importCompileCommands(istr);
|
||||
ASSERT_EQUALS(1, importer.fileSettings.size());
|
||||
ASSERT_EQUALS("/tmp/src.c", importer.fileSettings.begin()->filename);
|
||||
}
|
||||
};
|
||||
|
||||
REGISTER_TEST(TestImportProject)
|
||||
|
|
Loading…
Reference in New Issue