[PATCH] Exit with error when no checks enabled.

Alexander Kornienko alexfh at google.com
Sat May 31 16:05:55 PDT 2014


Hi klimek,

This seems like a more appropriate reaction to the user specifying a
single check with a wrong name, for example.

http://reviews.llvm.org/D3981

Files:
  clang-tidy/tool/ClangTidyMain.cpp
  test/clang-tidy/diagnostic.cpp
  test/clang-tidy/select-checks.cpp

Index: clang-tidy/tool/ClangTidyMain.cpp
===================================================================
--- clang-tidy/tool/ClangTidyMain.cpp
+++ clang-tidy/tool/ClangTidyMain.cpp
@@ -119,15 +119,23 @@
     return 1;
   }
 
+  std::vector<std::string> EnabledChecks = clang::tidy::getCheckNames(Options);
+
   // FIXME: Allow using --list-checks without positional arguments.
   if (ListChecks) {
     llvm::outs() << "Enabled checks:";
-    for (auto CheckName : clang::tidy::getCheckNames(Options))
+    for (auto CheckName : EnabledChecks)
       llvm::outs() << "\n    " << CheckName;
     llvm::outs() << "\n\n";
     return 0;
   }
 
+  if (EnabledChecks.empty()) {
+    llvm::errs() << "Error: no checks enabled.\n";
+    llvm::cl::PrintHelpMessage(/*Hidden=*/false, /*Categorized=*/true);
+    return 1;
+  }
+
   std::vector<clang::tidy::ClangTidyError> Errors;
   clang::tidy::ClangTidyStats Stats =
       clang::tidy::runClangTidy(Options, OptionsParser.getCompilations(),
Index: test/clang-tidy/diagnostic.cpp
===================================================================
--- test/clang-tidy/diagnostic.cpp
+++ test/clang-tidy/diagnostic.cpp
@@ -1,7 +1,7 @@
 // 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
+// RUN: clang-tidy -checks='-*,misc-use-override,clang-diagnostic-macro-redefined' %s -- -DMACRO_FROM_COMMAND_LINE | FileCheck -check-prefix=CHECK4 %s
 
 // CHECK1-NOT: warning
 // CHECK2-NOT: warning
Index: test/clang-tidy/select-checks.cpp
===================================================================
--- test/clang-tidy/select-checks.cpp
+++ test/clang-tidy/select-checks.cpp
@@ -1,6 +1,9 @@
 // RUN: grep -Ev "// *[A-Z-]+:" %s > %t.cpp
 // RUN: clang-tidy %t.cpp -fix -checks='-*,llvm-*' --
 // RUN: FileCheck -input-file=%t.cpp %s
+// RUN: clang-tidy %s -checks='-*,an-unknown-check' -- 2>&1 | FileCheck -check-prefix=CHECK2 %s
+
+// CHECK2: Error: no checks enabled.
 
 namespace i {
 }
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D3981.9993.patch
Type: text/x-patch
Size: 2374 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140531/46f2c13b/attachment.bin>


More information about the cfe-commits mailing list