[cfe-dev] How to verify clang-tidy checks applied to headers?

Artem Dergachev via cfe-dev cfe-dev at lists.llvm.org
Fri Dec 28 00:00:30 PST 2018


I don't know much about clang-tidy tests, but i had a quick look.

Because clang-tidy checks are FileCheck-based, it should be trivial to 
specify in the main file that the warning needs to come from another 
file, from a specific line, by simply matching the output. Matching that 
it *doesn't* appear in a certain file on a certain line is more fragile 
though, because the other file may change and you won't notice how your 
test breaks.

So, yeah, i guess it's better to put CHECK: lines into the header 
itself, and then tell FileCheck to use the *header* as the input file.

I'm not sure if %check_clang_tidy aka check_clang_tidy.py supports such 
behavior. If not, you should be able to do that manually, but of course 
you'll also need to pipe it into FileCheck manually for any checks to 
happen.


On 12/26/18 4:39 PM, Richard via cfe-dev wrote:
> Hi,
>
> I'm trying to write a test for this bug:
> <https://bugs.llvm.org/show_bug.cgi?id=26332>
>
> Namely, that clang-tidy check readability-simplify-boolean-expr
> doesn't apply to the user's header files correctly.
>
> So I wrote a cpp file like this:
>
> ====
> // RUN: %check_clang_tidy %s readability-simplify-boolean-expr %t
>
> #include "readability-simplify-bool-expr.h"
> ====
>
> and I copied readability-simplify-bool-expr.cpp to
> readability-simplify-bool-expr.h to cover all the same cases in a
> header as are covered in a source file.
>
> However, I encounter two problems.  First, I encounter the complaint
> from %check_clang_tidy that my source file contains no CHECK lines.
> If I add a bogus CHECK-MESSAGES comment to my source file, then I can
> continue, but the check still fails to report messages from the
> included header.
>
> I tried changing the run line to invoke clang-tidy directly so I could
> specify -header-filter, but that also failed to work.
>
> I can run clang-tidy manually with -header-filter and get the
> necessary diagnostics, but I need to run this under the test framework
> to verify that the diagnostic described in the bug is missing.
>
> How can I achieve this?
>
> Thanks.




More information about the cfe-dev mailing list