@@ -59,6 +59,7 @@ class TestImportProject : public TestFixture {
5959 TEST_CASE (importCompileCommands8); // Windows: "C:\Users\danielm\cppcheck"
6060 TEST_CASE (importCompileCommands9);
6161 TEST_CASE (importCompileCommands10); // #10887: include path with space
62+ TEST_CASE (importCompileCommands11); // include path order
6263 TEST_CASE (importCompileCommandsArgumentsSection); // Handle arguments section
6364 TEST_CASE (importCompileCommandsNoCommandSection); // gracefully handles malformed json
6465 TEST_CASE (importCppcheckGuiProject);
@@ -210,7 +211,8 @@ class TestImportProject : public TestFixture {
210211 TestImporter importer;
211212 ASSERT_EQUALS (true , importer.importCompileCommands (istr));
212213 ASSERT_EQUALS (2 , importer.fileSettings .size ());
213- ASSERT_EQUALS (" C:/Users/dan/git/test-cppcheck/mylib/second src/" , importer.fileSettings .begin ()->includePaths .front ());
214+ ASSERT_EQUALS (" C:/Users/dan/git/test-cppcheck/mylib/src/" , importer.fileSettings .begin ()->includePaths .front ());
215+ ASSERT_EQUALS (" C:/Users/dan/git/test-cppcheck/mylib/second src/" , importer.fileSettings .begin ()->includePaths .back ());
214216 }
215217
216218
@@ -282,6 +284,28 @@ class TestImportProject : public TestFixture {
282284 ASSERT_EQUALS (" /home/danielm/cppcheck/test folder/" , fs.includePaths .front ());
283285 }
284286
287+ void importCompileCommands11 () const { // include path order
288+ const char json[] =
289+ R"( [{
290+ "file": "1.c" ,
291+ "directory": "/x",
292+ "arguments": [
293+ "cc",
294+ "-I",
295+ "def",
296+ "-I",
297+ "abc"
298+ ]
299+ }])" ;
300+ std::istringstream istr (json);
301+ TestImporter importer;
302+ ASSERT_EQUALS (true , importer.importCompileCommands (istr));
303+ ASSERT_EQUALS (1 , importer.fileSettings .size ());
304+ const ImportProject::FileSettings &fs = importer.fileSettings .front ();
305+ ASSERT_EQUALS (" /x/def/" , fs.includePaths .front ());
306+ ASSERT_EQUALS (" /x/abc/" , fs.includePaths .back ());
307+ }
308+
285309 void importCompileCommandsArgumentsSection () const {
286310 const char json[] = " [ { \" directory\" : \" /tmp/\" ,"
287311 " \" arguments\" : [\" gcc\" , \" -c\" , \" src.c\" ],"
0 commit comments