njames93 created this revision.
njames93 added a reviewer: aaron.ballman.
Herald added subscribers: cfe-commits, xazax.hun.
Herald added a project: clang.

Motivated by a suspicously failing build, but also good to have anyway in 
general.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D82815

Files:
  clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h


Index: clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
===================================================================
--- clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
@@ -19,7 +19,6 @@
 #include "clang/Tooling/Core/Replacement.h"
 #include "clang/Tooling/Refactoring.h"
 #include "clang/Tooling/Tooling.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/Support/Path.h"
 #include <map>
 #include <memory>
@@ -67,7 +66,9 @@
     // that check constructors can access the context (for example, through
     // `getLangOpts()`).
     CheckFactory<CheckTypes...>::createChecks(&Context, Checks);
+    assert(!Checks.empty() && "No checks created");
     for (auto &Check : Checks) {
+      assert(Check.get() && "Checks can't be null");
       if (!Check->isLanguageVersionSupported(Context.getLangOpts()))
         continue;
       Check->registerMatchers(&Finder);
@@ -89,6 +90,7 @@
                const ClangTidyOptions &ExtraOptions = ClangTidyOptions(),
                std::map<StringRef, StringRef> PathsToContent =
                    std::map<StringRef, StringRef>()) {
+  static_assert(sizeof...(CheckTypes) > 0, "No checks specified");
   ClangTidyOptions Options = ExtraOptions;
   Options.Checks = "*";
   ClangTidyContext Context(std::make_unique<DefaultOptionsProvider>(
@@ -120,7 +122,7 @@
   llvm::IntrusiveRefCntPtr<FileManager> Files(
       new FileManager(FileSystemOptions(), InMemoryFileSystem));
 
-  SmallVector<std::unique_ptr<ClangTidyCheck>, 1> Checks;
+  SmallVector<std::unique_ptr<ClangTidyCheck>, sizeof...(CheckTypes)> Checks;
   tooling::ToolInvocation Invocation(
       Args,
       std::make_unique<TestClangTidyAction<CheckTypes...>>(Checks, Finder,


Index: clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
===================================================================
--- clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
+++ clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
@@ -19,7 +19,6 @@
 #include "clang/Tooling/Core/Replacement.h"
 #include "clang/Tooling/Refactoring.h"
 #include "clang/Tooling/Tooling.h"
-#include "llvm/ADT/Optional.h"
 #include "llvm/Support/Path.h"
 #include <map>
 #include <memory>
@@ -67,7 +66,9 @@
     // that check constructors can access the context (for example, through
     // `getLangOpts()`).
     CheckFactory<CheckTypes...>::createChecks(&Context, Checks);
+    assert(!Checks.empty() && "No checks created");
     for (auto &Check : Checks) {
+      assert(Check.get() && "Checks can't be null");
       if (!Check->isLanguageVersionSupported(Context.getLangOpts()))
         continue;
       Check->registerMatchers(&Finder);
@@ -89,6 +90,7 @@
                const ClangTidyOptions &ExtraOptions = ClangTidyOptions(),
                std::map<StringRef, StringRef> PathsToContent =
                    std::map<StringRef, StringRef>()) {
+  static_assert(sizeof...(CheckTypes) > 0, "No checks specified");
   ClangTidyOptions Options = ExtraOptions;
   Options.Checks = "*";
   ClangTidyContext Context(std::make_unique<DefaultOptionsProvider>(
@@ -120,7 +122,7 @@
   llvm::IntrusiveRefCntPtr<FileManager> Files(
       new FileManager(FileSystemOptions(), InMemoryFileSystem));
 
-  SmallVector<std::unique_ptr<ClangTidyCheck>, 1> Checks;
+  SmallVector<std::unique_ptr<ClangTidyCheck>, sizeof...(CheckTypes)> Checks;
   tooling::ToolInvocation Invocation(
       Args,
       std::make_unique<TestClangTidyAction<CheckTypes...>>(Checks, Finder,
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to