2020#include " settings.h"
2121#include " filesettings.h"
2222#include " fixture.h"
23+ #include " redirect.h"
2324
2425#include < list>
2526#include < map>
@@ -112,6 +113,7 @@ class TestImportProject : public TestFixture {
112113 }
113114
114115 void importCompileCommands1 () const {
116+ REDIRECT;
115117 constexpr char json[] = R"( [{
116118 "directory": "/tmp",
117119 "command": "gcc -DTEST1 -DTEST2=2 -o /tmp/src.o -c /tmp/src.c",
@@ -125,6 +127,7 @@ class TestImportProject : public TestFixture {
125127 }
126128
127129 void importCompileCommands2 () const {
130+ REDIRECT;
128131 // Absolute file path
129132#ifdef _WIN32
130133 const char json[] = R"( [{
@@ -152,6 +155,7 @@ class TestImportProject : public TestFixture {
152155 }
153156
154157 void importCompileCommands3 () const {
158+ REDIRECT;
155159 const char json[] = R"( [{
156160 "directory": "/tmp/",
157161 "command": "gcc -c src.c",
@@ -165,6 +169,7 @@ class TestImportProject : public TestFixture {
165169 }
166170
167171 void importCompileCommands4 () const {
172+ REDIRECT;
168173 constexpr char json[] = R"( [{
169174 "directory": "/tmp/",
170175 "command": "gcc -c src.mm",
@@ -177,6 +182,7 @@ class TestImportProject : public TestFixture {
177182 }
178183
179184 void importCompileCommands5 () const {
185+ REDIRECT;
180186 constexpr char json[] =
181187 R"( [{
182188 "directory": "C:/Users/dan/git/build-test-cppcheck-Desktop_Qt_5_15_0_MSVC2019_64bit-Debug",
@@ -196,6 +202,7 @@ class TestImportProject : public TestFixture {
196202 }
197203
198204 void importCompileCommands6 () const {
205+ REDIRECT;
199206 constexpr char json[] =
200207 R"( [{
201208 "directory": "C:/Users/dan/git/build-test-cppcheck-Desktop_Qt_5_15_0_MSVC2019_64bit-Debug",
@@ -217,6 +224,7 @@ class TestImportProject : public TestFixture {
217224
218225
219226 void importCompileCommands7 () const {
227+ REDIRECT;
220228 // cmake -DFILESDIR="/some/path" ..
221229 constexpr char json[] =
222230 R"( [{
@@ -237,6 +245,7 @@ class TestImportProject : public TestFixture {
237245 }
238246
239247 void importCompileCommands8 () const {
248+ REDIRECT;
240249 // cmake -DFILESDIR="C:\Program Files\Cppcheck" -G"NMake Makefiles" ..
241250 constexpr char json[] =
242251 R"( [{
@@ -250,6 +259,7 @@ class TestImportProject : public TestFixture {
250259 }
251260
252261 void importCompileCommands9 () const {
262+ REDIRECT;
253263 // IAR output (https://sourceforge.net/p/cppcheck/discussion/general/thread/608af51e0a/)
254264 constexpr char json[] =
255265 R"( [{
@@ -266,6 +276,7 @@ class TestImportProject : public TestFixture {
266276 }
267277
268278 void importCompileCommands10 () const { // #10887
279+ REDIRECT;
269280 constexpr char json[] =
270281 R"( [{
271282 "file": "/home/danielm/cppcheck/1/test folder/1.c" ,
@@ -285,6 +296,7 @@ class TestImportProject : public TestFixture {
285296 }
286297
287298 void importCompileCommands11 () const { // include path order
299+ REDIRECT;
288300 constexpr char json[] =
289301 R"( [{
290302 "file": "1.c" ,
@@ -307,6 +319,7 @@ class TestImportProject : public TestFixture {
307319 }
308320
309321 void importCompileCommandsArgumentsSection () const {
322+ REDIRECT;
310323 constexpr char json[] = " [ { \" directory\" : \" /tmp/\" ,"
311324 " \" arguments\" : [\" gcc\" , \" -c\" , \" src.c\" ],"
312325 " \" file\" : \" src.c\" } ]" ;
@@ -318,15 +331,18 @@ class TestImportProject : public TestFixture {
318331 }
319332
320333 void importCompileCommandsNoCommandSection () const {
334+ REDIRECT;
321335 constexpr char json[] = " [ { \" directory\" : \" /tmp/\" ,"
322336 " \" file\" : \" src.mm\" } ]" ;
323337 std::istringstream istr (json);
324338 TestImporter importer;
325339 ASSERT_EQUALS (false , importer.importCompileCommands (istr));
326340 ASSERT_EQUALS (0 , importer.fileSettings .size ());
341+ ASSERT_EQUALS (" cppcheck: error: no 'arguments' or 'command' field found in compilation database entry\n " , GET_REDIRECT_OUTPUT);
327342 }
328343
329344 void importCppcheckGuiProject () const {
345+ REDIRECT;
330346 constexpr char xml[] = " <?xml version=\" 1.0\" encoding=\" UTF-8\" ?>\n "
331347 " <project version=\" 1\" >\n "
332348 " <root name=\" .\" />\n "
0 commit comments