summaryrefslogtreecommitdiffstats
path: root/clang-tools-extra/unittests/clang-tidy
diff options
context:
space:
mode:
authorHaojian Wu <hokein@google.com>2016-10-12 08:19:44 +0000
committerHaojian Wu <hokein@google.com>2016-10-12 08:19:44 +0000
commit4900c18d666b3c475cfc13d361f5cf1532948961 (patch)
treed62460a5aaf88831505099ff41c3a3708e289a21 /clang-tools-extra/unittests/clang-tidy
parentc958d8d621c3eccd9d0b7799471b8d060fed66df (diff)
downloadbcm5719-llvm-4900c18d666b3c475cfc13d361f5cf1532948961.tar.gz
bcm5719-llvm-4900c18d666b3c475cfc13d361f5cf1532948961.zip
Revert "[ClangTidy] Add UsingInserter and NamespaceAliaser"
This reverts commit r283981. This patch breaks the buildbot. llvm-svn: 283985
Diffstat (limited to 'clang-tools-extra/unittests/clang-tidy')
-rw-r--r--clang-tools-extra/unittests/clang-tidy/NamespaceAliaserTest.cpp124
-rw-r--r--clang-tools-extra/unittests/clang-tidy/UsingInserterTest.cpp115
2 files changed, 0 insertions, 239 deletions
diff --git a/clang-tools-extra/unittests/clang-tidy/NamespaceAliaserTest.cpp b/clang-tools-extra/unittests/clang-tidy/NamespaceAliaserTest.cpp
deleted file mode 100644
index 9102298a9b3..00000000000
--- a/clang-tools-extra/unittests/clang-tidy/NamespaceAliaserTest.cpp
+++ /dev/null
@@ -1,124 +0,0 @@
-//===---- NamespaceAliaserTest.cpp - clang-tidy
-//----------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "../clang-tidy/utils/NamespaceAliaser.h"
-
-#include "ClangTidyTest.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/ASTMatchers/ASTMatchers.h"
-#include "gtest/gtest.h"
-
-namespace clang {
-namespace tidy {
-namespace utils {
-// This checker is for testing only. It can only run on one test case
-// (e.g. with one SourceManager).
-class InsertAliasCheck : public ClangTidyCheck {
-public:
- using ClangTidyCheck::ClangTidyCheck;
- void registerMatchers(ast_matchers::MatchFinder *Finder) override {
- Finder->addMatcher(ast_matchers::callExpr().bind("foo"), this);
- }
- void
- check(const ast_matchers::MatchFinder::MatchResult &Result) override {
- if (!Aliaser)
- Aliaser.reset(new NamespaceAliaser(*Result.SourceManager));
-
- const CallExpr *Call =
- Result.Nodes.getNodeAs<CallExpr>("foo");
- assert(Call != nullptr && "Did not find node \"foo\"");
- auto Hint = Aliaser->createAlias(*Result.Context, *Call, "::foo::bar",
- {"b", "some_alias"});
- if (Hint.hasValue())
- diag(Call->getLocStart(), "Fix for testing") << Hint.getValue();
-
- diag(Call->getLocStart(), "insert call")
- << FixItHint::CreateInsertion(
- Call->getLocStart(),
- Aliaser->getNamespaceName(*Result.Context, *Call, "::foo::bar") +
- "::");
- }
-
-private:
- std::unique_ptr<NamespaceAliaser> Aliaser;
-};
-
-template <typename Check>
-std::string runChecker(StringRef Code, int ExpectedWarningCount) {
- std::map<StringRef, StringRef> AdditionalFileContents = {{"foo.h",
- "namespace foo {\n"
- "namespace bar {\n"
- "}\n"
- "void func() { }\n"
- "}"}};
- std::vector<ClangTidyError> errors;
-
- std::string result =
- test::runCheckOnCode<Check>(Code, &errors, "foo.cc", None,
- ClangTidyOptions(), AdditionalFileContents);
-
- EXPECT_EQ(ExpectedWarningCount, errors.size());
- return result;
-}
-
-TEST(NamespaceAliaserTest, AddNewAlias) {
- EXPECT_EQ("#include \"foo.h\"\n"
- "void f() {\n"
- "namespace b = ::foo::bar;"
- " b::f(); }",
- runChecker<InsertAliasCheck>("#include \"foo.h\"\n"
- "void f() { f(); }",
- 2));
-}
-
-TEST(NamespaceAliaserTest, ReuseAlias) {
- EXPECT_EQ(
- "#include \"foo.h\"\n"
- "void f() { namespace x = foo::bar; x::f(); }",
- runChecker<InsertAliasCheck>("#include \"foo.h\"\n"
- "void f() { namespace x = foo::bar; f(); }",
- 1));
-}
-
-TEST(NamespaceAliaserTest, AddsOnlyOneAlias) {
- EXPECT_EQ("#include \"foo.h\"\n"
- "void f() {\n"
- "namespace b = ::foo::bar;"
- " b::f(); b::f(); }",
- runChecker<InsertAliasCheck>("#include \"foo.h\"\n"
- "void f() { f(); f(); }",
- 3));
-}
-
-TEST(NamespaceAliaserTest, LocalConflict) {
- EXPECT_EQ("#include \"foo.h\"\n"
- "void f() {\n"
- "namespace some_alias = ::foo::bar;"
- " namespace b = foo; some_alias::f(); }",
- runChecker<InsertAliasCheck>("#include \"foo.h\"\n"
- "void f() { namespace b = foo; f(); }",
- 2));
-}
-
-TEST(NamespaceAliaserTest, GlobalConflict) {
- EXPECT_EQ("#include \"foo.h\"\n"
- "namespace b = foo;\n"
- "void f() {\n"
- "namespace some_alias = ::foo::bar;"
- " some_alias::f(); }",
- runChecker<InsertAliasCheck>("#include \"foo.h\"\n"
- "namespace b = foo;\n"
- "void f() { f(); }",
- 2));
-}
-
-} // namespace utils
-} // namespace tidy
-} // namespace clang
diff --git a/clang-tools-extra/unittests/clang-tidy/UsingInserterTest.cpp b/clang-tools-extra/unittests/clang-tidy/UsingInserterTest.cpp
deleted file mode 100644
index 5932bd3a0d2..00000000000
--- a/clang-tools-extra/unittests/clang-tidy/UsingInserterTest.cpp
+++ /dev/null
@@ -1,115 +0,0 @@
-//===---- UsingInserterTest.cpp - clang-tidy ----------------------------===//
-//
-// The LLVM Compiler Infrastructure
-//
-// This file is distributed under the University of Illinois Open Source
-// License. See LICENSE.TXT for details.
-//
-//===----------------------------------------------------------------------===//
-
-#include "../clang-tidy/utils/UsingInserter.h"
-
-#include "ClangTidyTest.h"
-#include "clang/ASTMatchers/ASTMatchFinder.h"
-#include "clang/ASTMatchers/ASTMatchers.h"
-#include "gtest/gtest.h"
-
-namespace clang {
-namespace tidy {
-namespace utils {
-
-// Replace all function calls with calls to foo::func. Inserts using
-// declarations as necessary. This checker is for testing only. It
-// can only run on one test case (e.g. wih one SourceManager).
-class InsertUsingCheck : public clang::tidy::ClangTidyCheck {
-public:
- using clang::tidy::ClangTidyCheck::ClangTidyCheck;
- void registerMatchers(clang::ast_matchers::MatchFinder *Finder) override {
- Finder->addMatcher(clang::ast_matchers::callExpr().bind("foo"), this);
- }
- void
- check(const clang::ast_matchers::MatchFinder::MatchResult &Result) override {
- if (!Inserter)
- Inserter.reset(new UsingInserter(*Result.SourceManager,
- Result.Context->getLangOpts()));
-
- const clang::CallExpr *Call =
- Result.Nodes.getNodeAs<clang::CallExpr>("foo");
- assert(Call != nullptr && "Did not find node \"foo\"");
- auto Hint =
- Inserter->createUsingDeclaration(*Result.Context, *Call, "::foo::func");
-
- if (Hint.hasValue())
- diag(Call->getLocStart(), "Fix for testing") << Hint.getValue();
-
- diag(Call->getLocStart(), "insert call")
- << clang::FixItHint::CreateReplacement(
- Call->getCallee()->getSourceRange(),
- Inserter->getShortName(*Result.Context, *Call, "::foo::func"));
- }
-
-private:
- std::unique_ptr<UsingInserter> Inserter;
-};
-
-template <typename Check>
-std::string runChecker(StringRef Code, int ExpectedWarningCount) {
- std::map<StringRef, StringRef> AdditionalFileContents = {{"foo.h",
- "namespace foo {\n"
- "namespace bar {\n"
- "}\n"
- "void func() { }\n"
- "}"}};
- std::vector<ClangTidyError> errors;
-
- std::string result =
- test::runCheckOnCode<Check>(Code, &errors, "foo.cc", None,
- ClangTidyOptions(), AdditionalFileContents);
-
- EXPECT_EQ(ExpectedWarningCount, errors.size());
- return result;
-}
-
-TEST(UsingInserterTest, ReusesExisting) {
- EXPECT_EQ("#include \"foo.h\"\n"
- "namespace {"
- "using ::foo::func;\n"
- "void f() { func(); }"
- "}",
- runChecker<InsertUsingCheck>("#include \"foo.h\"\n"
- "namespace {"
- "using ::foo::func;\n"
- "void f() { f(); }"
- "}",
- 1));
-}
-
-TEST(UsingInserterTest, ReusesExistingGlobal) {
- EXPECT_EQ("#include \"foo.h\"\n"
- "using ::foo::func;\n"
- "namespace {"
- "void f() { func(); }"
- "}",
- runChecker<InsertUsingCheck>("#include \"foo.h\"\n"
- "using ::foo::func;\n"
- "namespace {"
- "void f() { f(); }"
- "}",
- 1));
-}
-
-TEST(UsingInserterTest, AvoidsConflict) {
- EXPECT_EQ("#include \"foo.h\"\n"
- "namespace {"
- "void f() { int func; ::foo::func(); }"
- "}",
- runChecker<InsertUsingCheck>("#include \"foo.h\"\n"
- "namespace {"
- "void f() { int func; f(); }"
- "}",
- 1));
-}
-
-} // namespace utils
-} // namespace tidy
-} // namespace clang
OpenPOWER on IntegriCloud