@@ -67,6 +67,8 @@ class TestImportProject : public TestFixture {
6767 TEST_CASE (importCompileCommands13); // #13333: duplicate file entries
6868 TEST_CASE (importCompileCommandsArgumentsSection); // Handle arguments section
6969 TEST_CASE (importCompileCommandsNoCommandSection); // gracefully handles malformed json
70+ TEST_CASE (importCompileCommandsDirectoryMissing); // 'directory' field missing
71+ TEST_CASE (importCompileCommandsDirectoryInvalid); // 'directory' field not a string
7072 TEST_CASE (importCppcheckGuiProject);
7173 TEST_CASE (ignorePaths);
7274 }
@@ -384,6 +386,27 @@ class TestImportProject : public TestFixture {
384386 ASSERT_EQUALS (" cppcheck: error: no 'arguments' or 'command' field found in compilation database entry\n " , GET_REDIRECT_OUTPUT);
385387 }
386388
389+ void importCompileCommandsDirectoryMissing () const {
390+ REDIRECT;
391+ constexpr char json[] = " [ { \" file\" : \" src.mm\" } ]" ;
392+ std::istringstream istr (json);
393+ TestImporter importer;
394+ ASSERT_EQUALS (false , importer.importCompileCommands (istr));
395+ ASSERT_EQUALS (0 , importer.fileSettings .size ());
396+ ASSERT_EQUALS (" cppcheck: error: 'directory' field in compilation database entry missing\n " , GET_REDIRECT_OUTPUT);
397+ }
398+
399+ void importCompileCommandsDirectoryInvalid () const {
400+ REDIRECT;
401+ constexpr char json[] = " [ { \" directory\" : 123,"
402+ " \" file\" : \" src.mm\" } ]" ;
403+ std::istringstream istr (json);
404+ TestImporter importer;
405+ ASSERT_EQUALS (false , importer.importCompileCommands (istr));
406+ ASSERT_EQUALS (0 , importer.fileSettings .size ());
407+ ASSERT_EQUALS (" cppcheck: error: 'directory' field in compilation database entry is not a string\n " , GET_REDIRECT_OUTPUT);
408+ }
409+
387410 void importCppcheckGuiProject () const {
388411 REDIRECT;
389412 constexpr char xml[] = " <?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n "
0 commit comments