@@ -62,6 +62,7 @@ class TestImportProject : public TestFixture {
6262 TEST_CASE (importCompileCommands9);
6363 TEST_CASE (importCompileCommands10); // #10887: include path with space
6464 TEST_CASE (importCompileCommands11); // include path order
65+ TEST_CASE (importCompileCommands12); // #13040: "directory" is parent directory, relative include paths
6566 TEST_CASE (importCompileCommandsArgumentsSection); // Handle arguments section
6667 TEST_CASE (importCompileCommandsNoCommandSection); // gracefully handles malformed json
6768 TEST_CASE (importCppcheckGuiProject);
@@ -319,6 +320,23 @@ class TestImportProject : public TestFixture {
319320 ASSERT_EQUALS (" /x/abc/" , fs.includePaths .back ());
320321 }
321322
323+ void importCompileCommands12 () const { // #13040
324+ REDIRECT;
325+ constexpr char json[] =
326+ R"( [{
327+ "file": "/x/src/1.c" ,
328+ "directory": "/x",
329+ "command": "cc -c -I. src/1.c"
330+ }])" ;
331+ std::istringstream istr (json);
332+ TestImporter importer;
333+ ASSERT_EQUALS (true , importer.importCompileCommands (istr));
334+ ASSERT_EQUALS (1 , importer.fileSettings .size ());
335+ const FileSettings &fs = importer.fileSettings .front ();
336+ ASSERT_EQUALS (1 , fs.includePaths .size ());
337+ ASSERT_EQUALS (" /x/" , fs.includePaths .front ());
338+ }
339+
322340 void importCompileCommandsArgumentsSection () const {
323341 REDIRECT;
324342 constexpr char json[] = " [ { \" directory\" : \" /tmp/\" ,"
0 commit comments