From ebdb98f254f632b506109b9d20c6e8e19697765f Mon Sep 17 00:00:00 2001 From: Paula Toth Date: Tue, 10 Mar 2020 10:28:23 -0700 Subject: [PATCH] [clang-tidy] Move fuchsia-restrict-system-includes to portability module for general use. Summary: Created a general check for restrict-system-includes under portability as recommend in the comments under D75332. I also fleshed out the user facing documentation to show examples for common use-cases such as allow-list, block-list, and wild carding. Removed fuchsia's check as per phosek sugguestion. Reviewers: aaron.ballman, phosek, alexfh, hokein, njames93 Reviewed By: phosek Subscribers: Eugene.Zelenko, mgorny, xazax.hun, phosek, cfe-commits, MaskRay Tags: #clang-tools-extra, #clang Differential Revision: https://reviews.llvm.org/D75786 --- .../clang-tidy/fuchsia/CMakeLists.txt | 1 - .../clang-tidy/fuchsia/FuchsiaTidyModule.cpp | 3 -- .../clang-tidy/portability/CMakeLists.txt | 1 + .../portability/PortabilityTidyModule.cpp | 3 ++ .../RestrictSystemIncludesCheck.cpp | 6 +-- .../RestrictSystemIncludesCheck.h | 14 ++--- clang-tools-extra/docs/ReleaseNotes.rst | 3 ++ .../fuchsia-restrict-system-includes.rst | 32 ------------ .../docs/clang-tidy/checks/list.rst | 2 +- .../portability-restrict-system-includes.rst | 51 +++++++++++++++++++ .../a.h | 0 .../system/cstdarg.h | 0 .../system/cstdlib.h | 0 .../system/j.h | 0 .../system/r.h | 0 .../system/s.h | 0 .../system/t.h | 0 .../system/transitive.h | 0 .../transitive2.h | 0 .../fuchsia-restrict-system-includes-all.cpp | 10 ---- .../fuchsia-restrict-system-includes-glob.cpp | 9 ---- .../fuchsia-restrict-system-includes.cpp | 25 --------- ...ability-restrict-system-includes-allow.cpp | 9 ++++ ...lity-restrict-system-includes-disallow.cpp | 10 ++++ ...tability-restrict-system-includes-glob.cpp | 10 ++++ ...y-restrict-system-includes-transitive.cpp} | 10 ++-- 26 files changed, 103 insertions(+), 96 deletions(-) rename clang-tools-extra/clang-tidy/{fuchsia => portability}/RestrictSystemIncludesCheck.cpp (97%) rename clang-tools-extra/clang-tidy/{fuchsia => portability}/RestrictSystemIncludesCheck.h (74%) delete mode 100644 clang-tools-extra/docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst create mode 100644 clang-tools-extra/docs/clang-tidy/checks/portability-restrict-system-includes.rst rename clang-tools-extra/test/clang-tidy/checkers/Inputs/{fuchsia-restrict-system-includes => portability-restrict-system-includes}/a.h (100%) rename clang-tools-extra/test/clang-tidy/checkers/Inputs/{fuchsia-restrict-system-includes => portability-restrict-system-includes}/system/cstdarg.h (100%) rename clang-tools-extra/test/clang-tidy/checkers/Inputs/{fuchsia-restrict-system-includes => portability-restrict-system-includes}/system/cstdlib.h (100%) rename clang-tools-extra/test/clang-tidy/checkers/Inputs/{fuchsia-restrict-system-includes => portability-restrict-system-includes}/system/j.h (100%) rename clang-tools-extra/test/clang-tidy/checkers/Inputs/{fuchsia-restrict-system-includes => portability-restrict-system-includes}/system/r.h (100%) rename clang-tools-extra/test/clang-tidy/checkers/Inputs/{fuchsia-restrict-system-includes => portability-restrict-system-includes}/system/s.h (100%) rename clang-tools-extra/test/clang-tidy/checkers/Inputs/{fuchsia-restrict-system-includes => portability-restrict-system-includes}/system/t.h (100%) rename clang-tools-extra/test/clang-tidy/checkers/Inputs/{fuchsia-restrict-system-includes => portability-restrict-system-includes}/system/transitive.h (100%) rename clang-tools-extra/test/clang-tidy/checkers/Inputs/{fuchsia-restrict-system-includes => portability-restrict-system-includes}/transitive2.h (100%) delete mode 100644 clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-all.cpp delete mode 100644 clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-glob.cpp delete mode 100644 clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp create mode 100644 clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp rename clang-tools-extra/test/clang-tidy/checkers/{fuchsia-restrict-system-includes-headers.cpp => portability-restrict-system-includes-transitive.cpp} (54%) diff --git a/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt b/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt index 30b319e7e5aa..26e6719a6475 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/fuchsia/CMakeLists.txt @@ -6,7 +6,6 @@ add_clang_library(clangTidyFuchsiaModule FuchsiaTidyModule.cpp MultipleInheritanceCheck.cpp OverloadedOperatorCheck.cpp - RestrictSystemIncludesCheck.cpp StaticallyConstructedObjectsCheck.cpp TrailingReturnCheck.cpp VirtualInheritanceCheck.cpp diff --git a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp index c59ec85468c3..39872fa1c7d0 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/fuchsia/FuchsiaTidyModule.cpp @@ -14,7 +14,6 @@ #include "DefaultArgumentsDeclarationsCheck.h" #include "MultipleInheritanceCheck.h" #include "OverloadedOperatorCheck.h" -#include "RestrictSystemIncludesCheck.h" #include "StaticallyConstructedObjectsCheck.h" #include "TrailingReturnCheck.h" #include "VirtualInheritanceCheck.h" @@ -39,8 +38,6 @@ public: "fuchsia-multiple-inheritance"); CheckFactories.registerCheck( "fuchsia-overloaded-operator"); - CheckFactories.registerCheck( - "fuchsia-restrict-system-includes"); CheckFactories.registerCheck( "fuchsia-statically-constructed-objects"); CheckFactories.registerCheck( diff --git a/clang-tools-extra/clang-tidy/portability/CMakeLists.txt b/clang-tools-extra/clang-tidy/portability/CMakeLists.txt index 0420a18a2a68..d2e3564c840a 100644 --- a/clang-tools-extra/clang-tidy/portability/CMakeLists.txt +++ b/clang-tools-extra/clang-tidy/portability/CMakeLists.txt @@ -2,6 +2,7 @@ set(LLVM_LINK_COMPONENTS support) add_clang_library(clangTidyPortabilityModule PortabilityTidyModule.cpp + RestrictSystemIncludesCheck.cpp SIMDIntrinsicsCheck.cpp LINK_LIBS diff --git a/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp b/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp index e12821e3d74d..c87a119aa81f 100644 --- a/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp +++ b/clang-tools-extra/clang-tidy/portability/PortabilityTidyModule.cpp @@ -9,6 +9,7 @@ #include "../ClangTidy.h" #include "../ClangTidyModule.h" #include "../ClangTidyModuleRegistry.h" +#include "RestrictSystemIncludesCheck.h" #include "SIMDIntrinsicsCheck.h" namespace clang { @@ -18,6 +19,8 @@ namespace portability { class PortabilityModule : public ClangTidyModule { public: void addCheckFactories(ClangTidyCheckFactories &CheckFactories) override { + CheckFactories.registerCheck( + "portability-restrict-system-includes"); CheckFactories.registerCheck( "portability-simd-intrinsics"); } diff --git a/clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp similarity index 97% rename from clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp rename to clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp index 98d317bea37f..15076d01a771 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.cpp +++ b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.cpp @@ -1,4 +1,4 @@ -//===--- RestrictSystemIncludesCheck.cpp - clang-tidy----------------------===// +//===--- RestrictSystemIncludesCheck.cpp - clang-tidy ---------------------===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -18,7 +18,7 @@ namespace clang { namespace tidy { -namespace fuchsia { +namespace portability { class RestrictedIncludesPPCallbacks : public PPCallbacks { public: @@ -111,6 +111,6 @@ void RestrictSystemIncludesCheck::storeOptions( Options.store(Opts, "Includes", AllowedIncludes); } -} // namespace fuchsia +} // namespace portability } // namespace tidy } // namespace clang diff --git a/clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h similarity index 74% rename from clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h rename to clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h index a0fb9fa07613..db2f9935534b 100644 --- a/clang-tools-extra/clang-tidy/fuchsia/RestrictSystemIncludesCheck.h +++ b/clang-tools-extra/clang-tidy/portability/RestrictSystemIncludesCheck.h @@ -1,4 +1,4 @@ -//===--- RestrictSystemIncludesCheck.h - clang-tidy---------- ----*- C++-*-===// +//===--- RestrictSystemIncludesCheck.h - clang-tidy --------------*- C++-*-===// // // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. // See https://llvm.org/LICENSE.txt for license information. @@ -6,21 +6,21 @@ // //===----------------------------------------------------------------------===// -#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H -#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H +#ifndef LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_RESTRICTINCLUDESSCHECK_H +#define LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_RESTRICTINCLUDESSCHECK_H #include "../ClangTidyCheck.h" #include "../GlobList.h" namespace clang { namespace tidy { -namespace fuchsia { +namespace portability { /// Checks for allowed includes and suggests removal of any others. If no /// includes are specified, the check will exit without issuing any warnings. /// /// For the user-facing documentation see: -/// http://clang.llvm.org/extra/clang-tidy/checks/fuchsia-restrict-system-includes.html +/// http://clang.llvm.org/extra/clang-tidy/checks/portability-restrict-system-includes.html class RestrictSystemIncludesCheck : public ClangTidyCheck { public: RestrictSystemIncludesCheck(StringRef Name, ClangTidyContext *Context) @@ -40,8 +40,8 @@ private: GlobList AllowedIncludesGlobList; }; -} // namespace fuchsia +} // namespace portability } // namespace tidy } // namespace clang -#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_FUCHSIA_RESTRICTINCLUDESSCHECK_H +#endif // LLVM_CLANG_TOOLS_EXTRA_CLANG_TIDY_PORTABILITY_RESTRICTINCLUDESSCHECK_H \ No newline at end of file diff --git a/clang-tools-extra/docs/ReleaseNotes.rst b/clang-tools-extra/docs/ReleaseNotes.rst index 3a58649ea985..68ca5f61a4fa 100644 --- a/clang-tools-extra/docs/ReleaseNotes.rst +++ b/clang-tools-extra/docs/ReleaseNotes.rst @@ -133,6 +133,9 @@ Changes in existing checks Renamed checks ^^^^^^^^^^^^^^ +- The 'fuchsia-restrict-system-headers' check was renamed to :doc:`portability-restrict-system-includes + + Improvements to include-fixer ----------------------------- diff --git a/clang-tools-extra/docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst b/clang-tools-extra/docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst deleted file mode 100644 index 622e025d115c..000000000000 --- a/clang-tools-extra/docs/clang-tidy/checks/fuchsia-restrict-system-includes.rst +++ /dev/null @@ -1,32 +0,0 @@ -.. title:: clang-tidy - fuchsia-restrict-system-includes - -fuchsia-restrict-system-includes -================================ - -Checks for allowed system includes and suggests removal of any others. - -It is important to note that running this check with fixes may break code, as -the fix removes headers. Fixes are applied to source and header files, but not -to system headers. - -For example, given the allowed system includes 'a.h,b*': - -.. code-block:: c++ - - #include - #include - #include - #include // Warning, as c.h is not explicitly allowed - -All system includes can be allowed with '*', and all can be disallowed with an -empty string (''). - -Options -------- - -.. option:: Includes - - A string containing a comma separated glob list of allowed include filenames. - Similar to the -checks glob list for running clang-tidy itself, the two - wildcard characters are '*' and '-', to include and exclude globs, - respectively.The default is '*', which allows all includes. diff --git a/clang-tools-extra/docs/clang-tidy/checks/list.rst b/clang-tools-extra/docs/clang-tidy/checks/list.rst index 5a5140bcd429..6930f6e96de3 100644 --- a/clang-tools-extra/docs/clang-tidy/checks/list.rst +++ b/clang-tools-extra/docs/clang-tidy/checks/list.rst @@ -155,7 +155,6 @@ Clang-Tidy Checks `fuchsia-default-arguments-declarations `_, "Yes" `fuchsia-multiple-inheritance `_, `fuchsia-overloaded-operator `_, - `fuchsia-restrict-system-includes `_, "Yes" `fuchsia-statically-constructed-objects `_, `fuchsia-trailing-return `_, `fuchsia-virtual-inheritance `_, @@ -256,6 +255,7 @@ Clang-Tidy Checks `performance-type-promotion-in-math-fn `_, "Yes" `performance-unnecessary-copy-initialization `_, `performance-unnecessary-value-param `_, "Yes" + `portability-restrict-system-includes `_, "Yes" `portability-simd-intrinsics `_, `readability-avoid-const-params-in-decls `_, `readability-braces-around-statements `_, "Yes" diff --git a/clang-tools-extra/docs/clang-tidy/checks/portability-restrict-system-includes.rst b/clang-tools-extra/docs/clang-tidy/checks/portability-restrict-system-includes.rst new file mode 100644 index 000000000000..934550660223 --- /dev/null +++ b/clang-tools-extra/docs/clang-tidy/checks/portability-restrict-system-includes.rst @@ -0,0 +1,51 @@ +.. title:: clang-tidy - portability-restrict-system-includes + +portability-restrict-system-includes +==================================== + +Checks to selectively allow or disallow a configurable list of system headers. + +For example: + +In order to **only** allow `zlib.h` from the system you would set the options +to `-*,zlib.h`. + +.. code-block:: c++ + + #include // Bad: disallowed system header. + #include // Bad: disallowed system header. + #include // Good: allowed system header. + #include "src/myfile.h" // Good: non-system header always allowed. + +In order to allow everything **except** `zlib.h` from the system you would set +the options to `*,-zlib.h`. + +.. code-block:: c++ + + #include // Good: allowed system header. + #include // Good: allowed system header. + #include // Bad: disallowed system header. + #include "src/myfile.h" // Good: non-system header always allowed. + +Since the opions support globbing you can use wildcarding to allow groups of +headers. + +`-*,openssl/*.h` will allow all openssl headers but disallow any others. + +.. code-block:: c++ + + #include // Bad: disallowed system header. + #include // Good: allowed system header. + #include // Good: allowed system header. + #include // Bad: disallowed system header. + #include "src/myfile.h" // Good: non-system header always allowed. + +Options +------- + +.. option:: Includes + + A string containing a comma separated glob list of allowed include + filenames. Similar to the -checks glob list for running clang-tidy itself, + the two wildcard characters are `*` and `-`, to include and exclude globs, + respectively. The default is `*`, which allows all includes. diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/a.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/a.h similarity index 100% rename from clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/a.h rename to clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/a.h diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/cstdarg.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdarg.h similarity index 100% rename from clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/cstdarg.h rename to clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdarg.h diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/cstdlib.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdlib.h similarity index 100% rename from clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/cstdlib.h rename to clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/cstdlib.h diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/j.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/j.h similarity index 100% rename from clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/j.h rename to clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/j.h diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/r.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/r.h similarity index 100% rename from clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/r.h rename to clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/r.h diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/s.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/s.h similarity index 100% rename from clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/s.h rename to clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/s.h diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/t.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/t.h similarity index 100% rename from clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/t.h rename to clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/t.h diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/transitive.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/transitive.h similarity index 100% rename from clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/system/transitive.h rename to clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/system/transitive.h diff --git a/clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/transitive2.h b/clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/transitive2.h similarity index 100% rename from clang-tools-extra/test/clang-tidy/checkers/Inputs/fuchsia-restrict-system-includes/transitive2.h rename to clang-tools-extra/test/clang-tidy/checkers/Inputs/portability-restrict-system-includes/transitive2.h diff --git a/clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-all.cpp b/clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-all.cpp deleted file mode 100644 index d521c1358dba..000000000000 --- a/clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-all.cpp +++ /dev/null @@ -1,10 +0,0 @@ -// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \ -// RUN: -- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: ''}]}" \ -// RUN: -- -I %S/Inputs/fuchsia-restrict-system-includes -isystem %S/Inputs/fuchsia-restrict-system-includes/system - -#include -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include cstdlib.h not allowed -#include -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include cstdarg.h not allowed -#include -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed diff --git a/clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-glob.cpp b/clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-glob.cpp deleted file mode 100644 index 104f3689246c..000000000000 --- a/clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-glob.cpp +++ /dev/null @@ -1,9 +0,0 @@ -// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \ -// RUN: -- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 'cstd*'}]}" \ -// RUN: -- -I %S/Inputs/fuchsia-restrict-system-includes -isystem %S/Inputs/fuchsia-restrict-system-includes/system - -#include -#include -#include -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed -// CHECK-FIXES-NOT: #include diff --git a/clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes.cpp b/clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes.cpp deleted file mode 100644 index c36640822b44..000000000000 --- a/clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes.cpp +++ /dev/null @@ -1,25 +0,0 @@ -// RUN: %check_clang_tidy %s fuchsia-restrict-system-includes %t \ -// RUN: -- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 's.h'}]}" \ -// RUN: -- -I %S/Inputs/fuchsia-restrict-system-includes -isystem %S/Inputs/fuchsia-restrict-system-includes/system - -#include "a.h" - -#include -#include -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed -// CHECK-FIXES-NOT: #include - -#include "s.h" -#include "t.h" -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include t.h not allowed -// CHECK-FIXES-NOT: #include "t.h" - -#define foo - -#include foo -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include j.h not allowed -// CHECK-FIXES-NOT: #include foo - -#/* comment */ include /* comment */ foo -// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include j.h not allowed -// CHECK-FIXES-NOT: # /* comment */ include /* comment */ foo diff --git a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp new file mode 100644 index 000000000000..faab977ad340 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-allow.cpp @@ -0,0 +1,9 @@ +// RUN: %check_clang_tidy %s portability-restrict-system-includes %t \ +// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '*,-stdio.h'}]}" + +// Test block-list functionality: allow all but stdio.h. + +#include +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdio.h not allowed +#include +#include diff --git a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp new file mode 100644 index 000000000000..58c1d4396ee5 --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-disallow.cpp @@ -0,0 +1,10 @@ +// RUN: %check_clang_tidy %s portability-restrict-system-includes %t \ +// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '-*,stdio.h'}]}" + +// Test allow-list functionality: disallow all but stdio.h. + +#include +#include +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include stdlib.h not allowed +#include +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include string.h not allowed diff --git a/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp new file mode 100644 index 000000000000..ccde9438d93c --- /dev/null +++ b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-glob.cpp @@ -0,0 +1,10 @@ +// RUN: %check_clang_tidy %s portability-restrict-system-includes %t \ +// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: '-*,std*.h'}]}" + +// Test glob functionality: disallow all headers except those that match +// pattern "std*.h". + +#include +#include +#include +// CHECK-MESSAGES: :[[@LINE-1]]:1: warning: system include string.h not allowed diff --git a/clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-headers.cpp b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp similarity index 54% rename from clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-headers.cpp rename to clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp index b9c00e2a105a..0f68da31cd45 100644 --- a/clang-tools-extra/test/clang-tidy/checkers/fuchsia-restrict-system-includes-headers.cpp +++ b/clang-tools-extra/test/clang-tidy/checkers/portability-restrict-system-includes-transitive.cpp @@ -1,11 +1,11 @@ // RUN: rm -rf %T/Headers // RUN: mkdir %T/Headers -// RUN: cp -r %S/Inputs/fuchsia-restrict-system-includes %T/Headers/fuchsia-restrict-system-includes -// RUN: %check_clang_tidy -std=c++11 %s fuchsia-restrict-system-includes %t \ -// RUN: -- -config="{CheckOptions: [{key: fuchsia-restrict-system-includes.Includes, value: 'transitive.h,s.h'}]}" \ +// RUN: cp -r %S/Inputs/portability-restrict-system-includes %T/Headers/portability-restrict-system-includes +// RUN: %check_clang_tidy -std=c++11 %s portability-restrict-system-includes %t \ +// RUN: -- -config="{CheckOptions: [{key: portability-restrict-system-includes.Includes, value: 'transitive.h,s.h'}]}" \ // RUN: -system-headers -header-filter=.* \ -// RUN: -- -I %T/Headers/fuchsia-restrict-system-includes -isystem %T/Headers/fuchsia-restrict-system-includes/system -// RUN: FileCheck -input-file=%T/Headers/fuchsia-restrict-system-includes/transitive2.h %s -check-prefix=CHECK-FIXES +// RUN: -- -I %T/Headers/portability-restrict-system-includes -isystem %T/Headers/portability-restrict-system-includes/system +// RUN: FileCheck -input-file=%T/Headers/portability-restrict-system-includes/transitive2.h %s -check-prefix=CHECK-FIXES // RUN: rm -rf %T/Headers // FIXME: Make the test work in all language modes.