[clang-tools-extra] 833273a - [clang-tidy] Sanity checks in ClangTidyTest header.
Nathan James via cfe-commits
cfe-commits at lists.llvm.org
Tue Jun 30 08:19:23 PDT 2020
Author: Nathan James
Date: 2020-06-30T16:19:15+01:00
New Revision: 833273a81250213d3ba85ca5419d03155604ada2
URL: https://github.com/llvm/llvm-project/commit/833273a81250213d3ba85ca5419d03155604ada2
DIFF: https://github.com/llvm/llvm-project/commit/833273a81250213d3ba85ca5419d03155604ada2.diff
LOG: [clang-tidy] Sanity checks in ClangTidyTest header.
Motivated by a suspicously failing build, but also good to have anyway in general.
Reviewed By: aaron.ballman
Differential Revision: https://reviews.llvm.org/D82815
Added:
Modified:
clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
Removed:
################################################################################
diff --git a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h b/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
index 6166af3c42e7..b8ee9972f6f8 100644
--- a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
+++ b/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 @@ class TestClangTidyAction : public ASTFrontendAction {
// 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 @@ runCheckOnCode(StringRef Code, std::vector<ClangTidyError> *Errors = nullptr,
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 @@ runCheckOnCode(StringRef Code, std::vector<ClangTidyError> *Errors = nullptr,
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,
More information about the cfe-commits
mailing list