Skip to content

Commit

Permalink
[include-cleaner] Check emptiness instead of occurences (#79154)
Browse files Browse the repository at this point in the history
Our internal integration relies on injecting some default values to
ignore/keep lists.
That means we can have filters, despite of not having occurences
for the flag.
  • Loading branch information
kadircet committed Jan 24, 2024
1 parent bc182ea commit 7e3fb37
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
8 changes: 8 additions & 0 deletions clang-tools-extra/include-cleaner/test/tool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,18 @@ int x = foo();
// IGNORE2-NOT: - "foobar.h"
// IGNORE2: + "foo.h"

// RUN: clang-include-cleaner -print=changes %s --ignore-headers= -- -I%S/Inputs/ | FileCheck --allow-empty --check-prefix=IGNORE3 %s
// IGNORE3: - "foobar.h"
// IGNORE3: + "foo.h"

// RUN: clang-include-cleaner -print=changes %s --only-headers="foo\.h" -- -I%S/Inputs/ | FileCheck --match-full-lines --allow-empty --check-prefix=ONLY %s
// ONLY-NOT: - "foobar.h"
// ONLY: + "foo.h"

// RUN: clang-include-cleaner -print=changes %s --only-headers= -- -I%S/Inputs/ | FileCheck --allow-empty --check-prefix=ONLY2 %s
// ONLY2: - "foobar.h"
// ONLY2: + "foo.h"

// RUN: clang-include-cleaner -print %s -- -I%S/Inputs/ | FileCheck --match-full-lines --check-prefix=PRINT %s
// PRINT: #include "foo.h"
// PRINT-NOT: {{^}}#include "foobar.h"{{$}}
Expand Down
4 changes: 2 additions & 2 deletions clang-tools-extra/include-cleaner/tool/IncludeCleaner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,9 +262,9 @@ std::function<bool(llvm::StringRef)> headerFilter() {
return nullptr;

return [OnlyMatches, IgnoreMatches](llvm::StringRef Header) {
if (OnlyHeaders.getNumOccurrences() && !OnlyMatches(Header))
if (!OnlyHeaders.empty() && !OnlyMatches(Header))
return true;
if (IgnoreHeaders.getNumOccurrences() && IgnoreMatches(Header))
if (!IgnoreHeaders.empty() && IgnoreMatches(Header))
return true;
return false;
};
Expand Down

0 comments on commit 7e3fb37

Please sign in to comment.