Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to exclude test paths from cppcheck analysis?

Tags:

c++

cppcheck

I try to run a cppcheck analysis over my code, which has the following file structure:

/code/module_1/src/a.cpp
/code/module_1/src/b.cpp
/code/module_1/test/c.cpp
/code/module_2/src/d.cpp
/code/module_2/src/e.cpp
/code/module_3/test/f.cpp

I'd like to run an analysis excluding all test code. Is this possible with a command like "cppcheck -itest"? It doesn't work for me, although I think it should, according to the docs:

...Directory name is matched to all parts of the path.

I'm using version 1.69. I know I could mention all test directories separately (which does work, I checked), but the number of modules is too high to do this for many analyses reasonably.

Is this possible?

like image 311
Martin Avatar asked Nov 01 '22 03:11

Martin


1 Answers

I installed Cppcheck to do some tests and it seems the -i implementation is a bit bonkers. However, I managed to achieve what you want.

Solution: use -itest\ instead of -itest (this was in Windows; maybe Linux needs -itest/)

Rationale: in my tests, -itest worked only if there was a .\test\ directory, in which case even .\a\test\a.cpp was excluded. With -itest\, however, such exclusion took place regardless of the presence of .\test\ directory.

This seems like a bug which the developers ought to weed out, but, in the meantime, you can succeed using the above workaround.

like image 177
André Chalella Avatar answered Nov 15 '22 04:11

André Chalella