[clang-tools-extra] r208883 - Change the behavior of clang-tidy -checks=, remove -disable-checks.

Alexander Kornienko alexfh at google.com
Thu May 15 07:27:37 PDT 2014


Author: alexfh
Date: Thu May 15 09:27:36 2014
New Revision: 208883

URL: http://llvm.org/viewvc/llvm-project?rev=208883&view=rev
Log:
Change the behavior of clang-tidy -checks=, remove -disable-checks.

Summary:
Make checks filtering more intuitive and easy to use. Remove
-disable-checks and change the format of -checks= to a comma-separated list of
globs with optional '-' prefix to denote exclusion. The -checks= option is now
cumulative, so it modifies defaults, not overrides them. Each glob adds or
removes to the current set of checks, so the filter can be refined or overriden
by adding globs.

Example:
  The default value for -checks= is
  '*,-clang-analyzer-alpha*,-llvm-include-order,-llvm-namespace-comment,-google-*',
  which allows all checks except for the ones named clang-analyzer-alpha* and
  others specified with the leading '-'. To allow all google-* checks one can
  write:
    clang-tidy -checks=google-* ...
  If one needs only google-* checks, we first need to remove everything (-*):
    clang-tidy -checks=-*,google-*
  etc.

I'm not sure if we need to change something here, so I didn't touch the docs
yet.

Reviewers: klimek, alexfh

Reviewed By: alexfh

Subscribers: cfe-commits

Differential Revision: http://reviews.llvm.org/D3770

Modified:
    clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
    clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h
    clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.h
    clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
    clang-tools-extra/trunk/test/clang-tidy/arg-comments.cpp
    clang-tools-extra/trunk/test/clang-tidy/basic.cpp
    clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy_fix.sh
    clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy_output.sh
    clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp
    clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp
    clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp
    clang-tools-extra/trunk/test/clang-tidy/fix.cpp
    clang-tools-extra/trunk/test/clang-tidy/macros.cpp
    clang-tools-extra/trunk/test/clang-tidy/nolint.cpp
    clang-tools-extra/trunk/test/clang-tidy/select-checks.cpp
    clang-tools-extra/trunk/test/clang-tidy/static-analyzer.cpp
    clang-tools-extra/trunk/test/clang-tidy/temporaries.cpp
    clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.cpp Thu May 15 09:27:36 2014
@@ -111,16 +111,49 @@ ClangTidyMessage::ClangTidyMessage(Strin
 
 ClangTidyError::ClangTidyError(StringRef CheckName) : CheckName(CheckName) {}
 
-ChecksFilter::ChecksFilter(const ClangTidyOptions &Options)
-    : EnableChecks(Options.EnableChecksRegex),
-      DisableChecks(Options.DisableChecksRegex) {}
+// Returns true if GlobList starts with the negative indicator ('-'), removes it
+// from the GlobList.
+static bool ConsumeNegativeIndicator(StringRef &GlobList) {
+  if (GlobList.startswith("-")) {
+    GlobList = GlobList.substr(1);
+    return true;
+  }
+  return false;
+}
+// Converts first glob from the comma-separated list of globs to Regex and
+// removes it and the trailing comma from the GlobList.
+static llvm::Regex ConsumeGlob(StringRef &GlobList) {
+  StringRef Glob = GlobList.substr(0, GlobList.find(','));
+  GlobList = GlobList.substr(Glob.size() + 1);
+  llvm::SmallString<128> RegexText("^");
+  StringRef MetaChars("()^$|*+?.[]\\{}");
+  for (char C : Glob) {
+    if (C == '*')
+      RegexText.push_back('.');
+    else if (MetaChars.find(C))
+      RegexText.push_back('\\');
+    RegexText.push_back(C);
+  }
+  RegexText.push_back('$');
+  return llvm::Regex(RegexText);
+}
+
+ChecksFilter::ChecksFilter(StringRef GlobList)
+    : Positive(!ConsumeNegativeIndicator(GlobList)),
+      Regex(ConsumeGlob(GlobList)),
+      NextFilter(GlobList.empty() ? nullptr : new ChecksFilter(GlobList)) {}
+
+bool ChecksFilter::isCheckEnabled(StringRef Name, bool Enabled) {
+  if (Regex.match(Name))
+    Enabled = Positive;
 
-bool ChecksFilter::isCheckEnabled(StringRef Name) {
-  return EnableChecks.match(Name) && !DisableChecks.match(Name);
+  if (NextFilter)
+    Enabled = NextFilter->isCheckEnabled(Name, Enabled);
+  return Enabled;
 }
 
 ClangTidyContext::ClangTidyContext(const ClangTidyOptions &Options)
-    : DiagEngine(nullptr), Options(Options), Filter(Options) {}
+    : DiagEngine(nullptr), Options(Options), Filter(Options.Checks) {}
 
 DiagnosticBuilder ClangTidyContext::diag(
     StringRef CheckName, SourceLocation Loc, StringRef Description,

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyDiagnosticConsumer.h Thu May 15 09:27:36 2014
@@ -60,12 +60,20 @@ struct ClangTidyError {
 /// \brief Filters checks by name.
 class ChecksFilter {
 public:
-  ChecksFilter(const ClangTidyOptions& Options);
-  bool isCheckEnabled(StringRef Name);
+  // GlobList is a comma-separated list of globs (only '*' metacharacter is
+  // supported) with optional '-' prefix to denote exclusion.
+  ChecksFilter(StringRef GlobList);
+  // Returns true if the check with the specified Name should be enabled.
+  // The result is the last matching glob's Positive flag. If Name is not
+  // matched by any globs, the check is not enabled.
+  bool isCheckEnabled(StringRef Name) { return isCheckEnabled(Name, false); }
 
 private:
-  llvm::Regex EnableChecks;
-  llvm::Regex DisableChecks;
+  bool isCheckEnabled(StringRef Name, bool Enabled);
+
+  bool Positive;
+  llvm::Regex Regex;
+  std::unique_ptr<ChecksFilter> NextFilter;
 };
 
 struct ClangTidyStats {

Modified: clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.h?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.h (original)
+++ clang-tools-extra/trunk/clang-tidy/ClangTidyOptions.h Thu May 15 09:27:36 2014
@@ -17,9 +17,8 @@ namespace tidy {
 
 /// \brief Contains options for clang-tidy.
 struct ClangTidyOptions {
-  ClangTidyOptions() : EnableChecksRegex(".*"), AnalyzeTemporaryDtors(false) {}
-  std::string EnableChecksRegex;
-  std::string DisableChecksRegex;
+  ClangTidyOptions() : Checks("*"), AnalyzeTemporaryDtors(false) {}
+  std::string Checks;
   // Output warnings from headers matching this filter. Warnings from main files
   // will always be displayed.
   std::string HeaderFilterRegex;

Modified: clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp (original)
+++ clang-tools-extra/trunk/clang-tidy/tool/ClangTidyMain.cpp Thu May 15 09:27:36 2014
@@ -27,18 +27,17 @@ static cl::OptionCategory ClangTidyCateg
 
 static cl::extrahelp CommonHelp(CommonOptionsParser::HelpMessage);
 
-static cl::opt<std::string> Checks(
-    "checks",
-    cl::desc("Regular expression matching the names of the checks to be run."),
-    cl::init(".*"), cl::cat(ClangTidyCategory));
-static cl::opt<std::string> DisableChecks(
-    "disable-checks",
-    cl::desc("Regular expression matching the names of the checks to disable."),
-    cl::init("(clang-analyzer-alpha.*" // Too many false positives.
-             "|llvm-include-order"     // Not implemented yet.
-             "|llvm-namespace-comment" // Not complete.
-             "|google-.*)"),           // Doesn't apply to LLVM.
-    cl::cat(ClangTidyCategory));
+const char DefaultChecks[] =
+    "*,"                       // Enable all checks, except these:
+    "-clang-analyzer-alpha*,"  // Too many false positives.
+    "-llvm-include-order,"     // Not implemented yet.
+    "-llvm-namespace-comment," // Not complete.
+    "-google-*,";              // Doesn't apply to LLVM.
+static cl::opt<std::string>
+Checks("checks",
+       cl::desc("Comma-separated list of positive and negative globs matching\n"
+                "the names of the checks to be run."),
+       cl::init(""), cl::cat(ClangTidyCategory));
 static cl::opt<std::string> HeaderFilter(
     "header-filter",
     cl::desc("Regular expression matching the names of the headers to output\n"
@@ -88,8 +87,7 @@ int main(int argc, const char **argv) {
   CommonOptionsParser OptionsParser(argc, argv, ClangTidyCategory);
 
   clang::tidy::ClangTidyOptions Options;
-  Options.EnableChecksRegex = Checks;
-  Options.DisableChecksRegex = DisableChecks;
+  Options.Checks = DefaultChecks + Checks;
   Options.HeaderFilterRegex = HeaderFilter;
   Options.AnalyzeTemporaryDtors = AnalyzeTemporaryDtors;
 

Modified: clang-tools-extra/trunk/test/clang-tidy/arg-comments.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/arg-comments.cpp?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/arg-comments.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/arg-comments.cpp Thu May 15 09:27:36 2014
@@ -1,4 +1,4 @@
-// RUN: clang-tidy --checks=misc-argument-comment %s -- | FileCheck %s
+// RUN: clang-tidy --checks='-*,misc-argument-comment' %s -- | FileCheck %s
 
 // FIXME: clang-tidy should provide a -verify mode to make writing these checks
 // easier and more accurate.

Modified: clang-tools-extra/trunk/test/clang-tidy/basic.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/basic.cpp?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/basic.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/basic.cpp Thu May 15 09:27:36 2014
@@ -1,5 +1,5 @@
 // RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
-// RUN: clang-tidy %t.cpp -checks='llvm-namespace-comment' -disable-checks='' -- > %t2.cpp
+// RUN: clang-tidy %t.cpp -checks='-*,llvm-namespace-comment' -- > %t2.cpp
 // RUN: FileCheck -input-file=%t2.cpp %s
 
 namespace i {

Modified: clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy_fix.sh
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy_fix.sh?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy_fix.sh (original)
+++ clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy_fix.sh Thu May 15 09:27:36 2014
@@ -7,6 +7,5 @@ CHECK_TO_RUN=$2
 TEMPORARY_FILE=$3.cpp
 
 grep -Ev "// *[A-Z-]+:" ${INPUT_FILE} > ${TEMPORARY_FILE}
-clang-tidy ${TEMPORARY_FILE} -fix --checks=${CHECK_TO_RUN} \
-    --disable-checks="" -- --std=c++11
+clang-tidy ${TEMPORARY_FILE} -fix --checks="-*,${CHECK_TO_RUN}" -- --std=c++11
 FileCheck -input-file=${TEMPORARY_FILE} ${INPUT_FILE}

Modified: clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy_output.sh
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy_output.sh?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy_output.sh (original)
+++ clang-tools-extra/trunk/test/clang-tidy/check_clang_tidy_output.sh Thu May 15 09:27:36 2014
@@ -5,6 +5,5 @@
 INPUT_FILE=$1
 CHECK_TO_RUN=$2
 
-clang-tidy --checks=${CHECK_TO_RUN} --disable-checks="" ${INPUT_FILE} \
-    -- --std=c++11 -x c++ \
+clang-tidy --checks="-*,${CHECK_TO_RUN}" ${INPUT_FILE} -- --std=c++11 -x c++ \
   | FileCheck ${INPUT_FILE}

Modified: clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/deduplication.cpp Thu May 15 09:27:36 2014
@@ -1,4 +1,4 @@
-// RUN: clang-tidy -checks=google-explicit-constructor -disable-checks='' %s -- | FileCheck %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' %s -- | FileCheck %s
 
 template<typename T>
 class A { A(T); };

Modified: clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/diagnostic.cpp Thu May 15 09:27:36 2014
@@ -1,7 +1,7 @@
-// RUN: clang-tidy -disable-checks='' %s.nonexistent.cpp -- | FileCheck -check-prefix=CHECK1 %s
-// RUN: clang-tidy -disable-checks='' %s -- -fan-unknown-option | FileCheck -check-prefix=CHECK2 %s
-// RUN: clang-tidy -checks='(google-explicit-constructor|clang-diagnostic-literal-conversion)' -disable-checks='' %s -- -fan-unknown-option | FileCheck -check-prefix=CHECK3 %s
-// RUN: clang-tidy -checks='clang-diagnostic-macro-redefined' -disable-checks='' %s -- -DMACRO_FROM_COMMAND_LINE | FileCheck -check-prefix=CHECK4 %s
+// RUN: clang-tidy %s.nonexistent.cpp -- | FileCheck -check-prefix=CHECK1 %s
+// RUN: clang-tidy -checks='google-explicit-constructor' %s -- -fan-unknown-option | FileCheck -check-prefix=CHECK2 %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor,clang-diagnostic-literal-conversion' %s -- -fan-unknown-option | FileCheck -check-prefix=CHECK3 %s
+// RUN: clang-tidy -checks='-*,clang-diagnostic-macro-redefined' %s -- -DMACRO_FROM_COMMAND_LINE | FileCheck -check-prefix=CHECK4 %s
 
 // CHECK1-NOT: warning
 // CHECK2-NOT: warning

Modified: clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/file-filter.cpp Thu May 15 09:27:36 2014
@@ -1,6 +1,6 @@
-// RUN: clang-tidy -checks=google-explicit-constructor -disable-checks='' -header-filter='' %s -- -I %S/Inputs/file-filter 2>&1 | FileCheck %s
-// RUN: clang-tidy -checks=google-explicit-constructor -disable-checks='' -header-filter='.*' %s -- -I %S/Inputs/file-filter 2>&1 | FileCheck --check-prefix=CHECK2 %s
-// RUN: clang-tidy -checks=google-explicit-constructor -disable-checks='' -header-filter='header2\.h' %s -- -I %S/Inputs/file-filter 2>&1 | FileCheck --check-prefix=CHECK3 %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='' %s -- -I %S/Inputs/file-filter 2>&1 | FileCheck %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='.*' %s -- -I %S/Inputs/file-filter 2>&1 | FileCheck --check-prefix=CHECK2 %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' -header-filter='header2\.h' %s -- -I %S/Inputs/file-filter 2>&1 | FileCheck --check-prefix=CHECK3 %s
 
 #include "header1.h"
 // CHECK-NOT: warning:

Modified: clang-tools-extra/trunk/test/clang-tidy/fix.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/fix.cpp?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/fix.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/fix.cpp Thu May 15 09:27:36 2014
@@ -1,5 +1,5 @@
 // RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
-// RUN: clang-tidy %t.cpp -checks='(google-explicit-constructor|llvm-namespace-comment)' -disable-checks='' -fix -- > %t.msg 2>&1
+// RUN: clang-tidy %t.cpp -checks='-*,google-explicit-constructor,llvm-namespace-comment' -fix -- > %t.msg 2>&1
 // RUN: FileCheck -input-file=%t.cpp %s
 // RUN: FileCheck -input-file=%t.msg -check-prefix=CHECK-MESSAGES %s
 

Modified: clang-tools-extra/trunk/test/clang-tidy/macros.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/macros.cpp?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/macros.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/macros.cpp Thu May 15 09:27:36 2014
@@ -1,4 +1,4 @@
-// RUN: clang-tidy -checks=google-explicit-constructor -disable-checks='' %s -- | FileCheck %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' %s -- | FileCheck %s
 
 #define Q(name) class name { name(int i); }
 

Modified: clang-tools-extra/trunk/test/clang-tidy/nolint.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/nolint.cpp?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/nolint.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/nolint.cpp Thu May 15 09:27:36 2014
@@ -1,4 +1,4 @@
-// RUN: clang-tidy -checks=google-explicit-constructor -disable-checks='' %s -- 2>&1 | FileCheck %s
+// RUN: clang-tidy -checks='-*,google-explicit-constructor' %s -- 2>&1 | FileCheck %s
 
 class A { A(int i); };
 // CHECK: :[[@LINE-1]]:11: warning: Single-argument constructors must be explicit [google-explicit-constructor]

Modified: clang-tools-extra/trunk/test/clang-tidy/select-checks.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/select-checks.cpp?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/select-checks.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/select-checks.cpp Thu May 15 09:27:36 2014
@@ -1,5 +1,5 @@
 // RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
-// RUN: clang-tidy %t.cpp -fix -checks=^llvm-.* -disable-checks='' --
+// RUN: clang-tidy %t.cpp -fix -checks='-*,llvm-*' --
 // RUN: FileCheck -input-file=%t.cpp %s
 
 namespace i {

Modified: clang-tools-extra/trunk/test/clang-tidy/static-analyzer.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/static-analyzer.cpp?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/static-analyzer.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/static-analyzer.cpp Thu May 15 09:27:36 2014
@@ -1,4 +1,4 @@
-// RUN: clang-tidy %s -checks='clang-analyzer-.*' -disable-checks='alpha' -- | FileCheck %s
+// RUN: clang-tidy %s -checks='-*,clang-analyzer-*,-clang-analyzer-alpha*' -- | FileCheck %s
 extern void *malloc(unsigned long);
 extern void free(void *);
 

Modified: clang-tools-extra/trunk/test/clang-tidy/temporaries.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/test/clang-tidy/temporaries.cpp?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/test/clang-tidy/temporaries.cpp (original)
+++ clang-tools-extra/trunk/test/clang-tidy/temporaries.cpp Thu May 15 09:27:36 2014
@@ -1,4 +1,4 @@
-// RUN: clang-tidy -checks=clang-analyzer-core.NullDereference -disable-checks='' -analyze-temporary-dtors %s -- | FileCheck %s
+// RUN: clang-tidy -checks='-*,clang-analyzer-core.NullDereference' -analyze-temporary-dtors %s -- | FileCheck %s
 
 struct NoReturnDtor {
   ~NoReturnDtor() __attribute__((noreturn));

Modified: clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp?rev=208883&r1=208882&r2=208883&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyDiagnosticConsumerTest.cpp Thu May 15 09:27:36 2014
@@ -28,6 +28,59 @@ TEST(ClangTidyDiagnosticConsumer, SortsE
   EXPECT_EQ("variable []", Errors[1].Message.Message);
 }
 
+TEST(ChecksFilter, Empty) {
+  ChecksFilter Filter("");
+
+  EXPECT_TRUE(Filter.isCheckEnabled(""));
+  EXPECT_FALSE(Filter.isCheckEnabled("aaa"));
+}
+
+TEST(ChecksFilter, Nothing) {
+  ChecksFilter Filter("-*");
+
+  EXPECT_FALSE(Filter.isCheckEnabled(""));
+  EXPECT_FALSE(Filter.isCheckEnabled("a"));
+  EXPECT_FALSE(Filter.isCheckEnabled("-*"));
+  EXPECT_FALSE(Filter.isCheckEnabled("-"));
+  EXPECT_FALSE(Filter.isCheckEnabled("*"));
+}
+
+TEST(ChecksFilter, Everything) {
+  ChecksFilter Filter("*");
+
+  EXPECT_TRUE(Filter.isCheckEnabled(""));
+  EXPECT_TRUE(Filter.isCheckEnabled("aaaa"));
+  EXPECT_TRUE(Filter.isCheckEnabled("-*"));
+  EXPECT_TRUE(Filter.isCheckEnabled("-"));
+  EXPECT_TRUE(Filter.isCheckEnabled("*"));
+}
+
+TEST(ChecksFilter, Simple) {
+  ChecksFilter Filter("aaa");
+
+  EXPECT_TRUE(Filter.isCheckEnabled("aaa"));
+  EXPECT_FALSE(Filter.isCheckEnabled(""));
+  EXPECT_FALSE(Filter.isCheckEnabled("aa"));
+  EXPECT_FALSE(Filter.isCheckEnabled("aaaa"));
+  EXPECT_FALSE(Filter.isCheckEnabled("bbb"));
+}
+
+TEST(ChecksFilter, Complex) {
+  ChecksFilter Filter("*,-a.*,-b.*,a.a.*,-a.a.a.*,-..,-...,-..+,-*$,-*qwe*");
+
+  EXPECT_TRUE(Filter.isCheckEnabled("aaa"));
+  EXPECT_TRUE(Filter.isCheckEnabled("qqq"));
+  EXPECT_FALSE(Filter.isCheckEnabled("a."));
+  EXPECT_FALSE(Filter.isCheckEnabled("a.b"));
+  EXPECT_FALSE(Filter.isCheckEnabled("b."));
+  EXPECT_FALSE(Filter.isCheckEnabled("b.b"));
+  EXPECT_TRUE(Filter.isCheckEnabled("a.a.b"));
+  EXPECT_FALSE(Filter.isCheckEnabled("a.a.a.a"));
+  EXPECT_FALSE(Filter.isCheckEnabled("qwe"));
+  EXPECT_FALSE(Filter.isCheckEnabled("asdfqweasdf"));
+  EXPECT_TRUE(Filter.isCheckEnabled("asdfqwEasdf"));
+}
+
 } // namespace test
 } // namespace tidy
 } // namespace clang





More information about the cfe-commits mailing list