How to exclude test paths from cppcheck analysis?
Asked Answered
F

3

6

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?

Frieder answered 21/5, 2015 at 13:25 Comment(1)
Can you please provide exactly the command line you're attempting to use?Malnutrition
C
2

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.

Caudex answered 25/5, 2015 at 13:41 Comment(0)
H
1

This is a late response to an old question, but perhaps this will help other latecomers like myself.

Disclaimer: This answer is for Windows.

It seems as if v1.79 has remedied the OP's issue. The following command line syntax has worked for me:

cppcheck -itest code

In this example, "-itest" weeds out any occurrence of the "test" directory, as originally (and correctly) assumed by the OP. In addition, the code folder is found next to the cppcheck.exe. This will be the root of the recursive source-code scan.

Horsecar answered 20/6, 2017 at 12:48 Comment(0)
S
0

I'd use something like:

cppcheck /code/module_1/src /code/module_2/src  /code/module_3/src
Sulfatize answered 23/5, 2015 at 13:5 Comment(1)
Sorry I was a bit quick. There is no advantage. However with my approach if the command line allows it, it is possible to use normal command line expansion: "cppcheck /code/*/src" while it is not possible to use "cppcheck -i /code/*/test".Achromat

© 2022 - 2024 — McMap. All rights reserved.