@@ -67,6 +67,8 @@ class TestImportProject : public TestFixture {
67
67
TEST_CASE (importCompileCommands13); // #13333: duplicate file entries
68
68
TEST_CASE (importCompileCommandsArgumentsSection); // Handle arguments section
69
69
TEST_CASE (importCompileCommandsNoCommandSection); // gracefully handles malformed json
70
+ TEST_CASE (importCompileCommandsDirectoryMissing); // 'directory' field missing
71
+ TEST_CASE (importCompileCommandsDirectoryInvalid); // 'directory' field not a string
70
72
TEST_CASE (importCppcheckGuiProject);
71
73
TEST_CASE (ignorePaths);
72
74
}
@@ -384,6 +386,27 @@ class TestImportProject : public TestFixture {
384
386
ASSERT_EQUALS (" cppcheck: error: no 'arguments' or 'command' field found in compilation database entry\n " , GET_REDIRECT_OUTPUT);
385
387
}
386
388
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
+
387
410
void importCppcheckGuiProject () const {
388
411
REDIRECT;
389
412
constexpr char xml[] = " <?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n "
0 commit comments