How to verify clang-tidy checks applied to headers?

Hi,

I'm trying to write a test for this bug:
<https://bugs.llvm.org/show_bug.cgi?id=26332&gt;

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:

Maybe you could first generate the preprocessed file, use the
preprocessed file as the test input and add the "CHECK-MESSAGES" lines
to the preprocessed file?

You probably need to extend the test framework to accept
the -header-filter command line and pass it through.

Thanks,

Stephen.

[Please reply *only* to the list and do not include my email directly
in the To: or Cc: of your reply; otherwise I will not see your reply.
Thanks.]

In article <q02pmi$6qf$1@blaine.gmane.org>,
    Stephen Kelly via cfe-dev <cfe-dev@lists.llvm.org> writes:

You probably need to extend the test framework to accept
the -header-filter command line and pass it through.

Yeah, I think check_clang_tidy.py will need to be augmented in order
to support that. However, that's just a wrapper around running
clang-tidy in a convenient manner, so I thought I could prototype it
with // RUN: clang-tidy ..., but didn't manage to find the right
incantation. I find it hard to believe I'm the first person to try
and do this, so I was hoping there was an accepted recipe for doing
this.

[Just hit 'reply', not 'reply all', please.]

In article <CAJ0ZJHTd=4RwyU3Nh+wNfETYO7D=dd4kCnL5QTRqX9qEL8vq1Q@mail.gmail.com>,
    Hongbin Zheng <etherzhhb@gmail.com> writes:

Maybe you could first generate the preprocessed file, use the
preprocessed file as the test input and add the "CHECK-MESSAGES" lines
to the preprocessed file?

If I do that, then I'm not testing the actual mechanism.

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.

Hi,

did you try something similar to `// RUN: clang-tidy -checks='-*,
abseil-no-namespace' -header-filter='.*' %s -- -I %S/Inputs 2>&1 |
FileCheck %s`?

This pattern occurs multiple times in the test-framework: `git grep "|
FileCheck" *.cpp` shows quite a view places, maybe there are other
places that are more specific to your requirement?

Best, Jonas

[Please reply *only* to the list and do not include my email directly
in the To: or Cc: of your reply; otherwise I will not see your reply.

In other words, use 'Reply' not 'Reply All'.

Thanks.]

In article <bdfd9306-7233-6712-ad2c-85cfe61c47ab@jonas-toth.eu>,
    Jonas Toth via cfe-dev <cfe-dev@lists.llvm.org> writes:

did you try something similar to `// RUN: clang-tidy -checks='-*,
abseil-no-namespace' -header-filter='.*' %s -- -I %S/Inputs 2>&1 |
FileCheck %s`?

Yeah, I tried something like that, but I didn't get it to work
properly. I will look at it again to see if I can get the right
command-line. It's been a couple years since I worked on clang-tidy
and some of my clang-fu has decayed away. If I can find a pattern that
works, I'll enhance the helper script to support this directly.

This pattern occurs multiple times in the test-framework: `git grep "|
FileCheck" *.cpp` shows quite a view places, maybe there are other
places that are more specific to your requirement?

Thanks for the pointer.

[Please reply *only* to the list and do not include my email directly
in the To: or Cc: of your reply; otherwise I will not see your reply.

Thanks.]

In article <bdfd9306-7233-6712-ad2c-85cfe61c47ab@jonas-toth.eu>,
    Jonas Toth via cfe-dev <cfe-dev@lists.llvm.org> writes:

did you try something similar to `// RUN: clang-tidy -checks='-*,
abseil-no-namespace' -header-filter='.*' %s -- -I %S/Inputs 2>&1 |
FileCheck %s`?

This pattern occurs multiple times in the test-framework: `git grep "|
FileCheck" *.cpp` shows quite a view places, maybe there are other
places that are more specific to your requirement?

Well, it seems that I already had a patch that did this from 2 years
ago that never made it through the exhausting process that is
phabricator.

Right now I have a Compose Method refactor in phabricator that needs
approval. After that, I'll rebase my old changes on top of that.

So I need a little review love in phabricator, please...