Made the ClangTidyTest helper class independent of the testing framework.

Reviewers: klimek

Reviewed By: klimek

CC: cfe-commits

Differential Revision: http://llvm-reviews.chandlerc.com/D2895

llvm-svn: 202399
diff --git a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h b/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
index 9cd8bcd..1be5f82 100644
--- a/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
+++ b/clang-tools-extra/unittests/clang-tidy/ClangTidyTest.h
@@ -17,59 +17,53 @@
 #include "clang/Frontend/FrontendActions.h"
 #include "clang/Tooling/Refactoring.h"
 #include "clang/Tooling/Tooling.h"
-#include "gtest/gtest.h"
 
 namespace clang {
 namespace tidy {
+namespace test {
 
-template <typename T> class ClangTidyTest : public ::testing::Test {
-protected:
-  ClangTidyTest() : Check(new T), Context(&Errors) {}
-
-  std::string runCheckOn(StringRef Code) {
-    ClangTidyDiagnosticConsumer DiagConsumer(Context);
-    Check->setContext(&Context);
-    EXPECT_TRUE(
-        tooling::runToolOnCode(new TestPPAction(*Check, &Context), Code));
-    ast_matchers::MatchFinder Finder;
-    Check->registerMatchers(&Finder);
-    OwningPtr<tooling::FrontendActionFactory> Factory(
-        tooling::newFrontendActionFactory(&Finder));
-    EXPECT_TRUE(tooling::runToolOnCode(Factory->create(), Code));
-    DiagConsumer.finish();
-    tooling::Replacements Fixes;
-    for (SmallVector<ClangTidyError, 16>::const_iterator I = Errors.begin(),
-                                                         E = Errors.end();
-         I != E; ++I)
-      Fixes.insert(I->Fix.begin(), I->Fix.end());
-    return tooling::applyAllReplacements(Code, Fixes);
-  }
-
-  void expectNoChanges(StringRef Code) { EXPECT_EQ(Code, runCheckOn(Code)); }
+class TestPPAction : public PreprocessOnlyAction {
+public:
+  TestPPAction(ClangTidyCheck &Check, ClangTidyContext *Context)
+      : Check(Check), Context(Context) {}
 
 private:
-  class TestPPAction : public PreprocessOnlyAction {
-  public:
-    TestPPAction(ClangTidyCheck &Check, ClangTidyContext *Context)
-        : Check(Check), Context(Context) {}
+  bool BeginSourceFileAction(CompilerInstance &Compiler,
+                             llvm::StringRef file_name) LLVM_OVERRIDE {
+    Context->setSourceManager(&Compiler.getSourceManager());
+    Check.registerPPCallbacks(Compiler);
+    return true;
+  }
 
-  private:
-    virtual bool BeginSourceFileAction(CompilerInstance &Compiler,
-                                       llvm::StringRef file_name) {
-      Context->setSourceManager(&Compiler.getSourceManager());
-      Check.registerPPCallbacks(Compiler);
-      return true;
-    }
-
-    ClangTidyCheck &Check;
-    ClangTidyContext *Context;
-  };
-
-  OwningPtr<ClangTidyCheck> Check;
-  SmallVector<ClangTidyError, 16> Errors;
-  ClangTidyContext Context;
+  ClangTidyCheck &Check;
+  ClangTidyContext *Context;
 };
 
+template <typename T> std::string runCheckOnCode(StringRef Code) {
+  T Check;
+  SmallVector<ClangTidyError, 16> Errors;
+  ClangTidyContext Context(&Errors);
+  ClangTidyDiagnosticConsumer DiagConsumer(Context);
+  Check.setContext(&Context);
+
+  if (!tooling::runToolOnCode(new TestPPAction(Check, &Context), Code))
+    return "";
+  ast_matchers::MatchFinder Finder;
+  Check.registerMatchers(&Finder);
+  OwningPtr<tooling::FrontendActionFactory> Factory(
+      tooling::newFrontendActionFactory(&Finder));
+  if (!tooling::runToolOnCode(Factory->create(), Code))
+    return "";
+  DiagConsumer.finish();
+  tooling::Replacements Fixes;
+  for (SmallVector<ClangTidyError, 16>::const_iterator I = Errors.begin(),
+                                                       E = Errors.end();
+       I != E; ++I)
+    Fixes.insert(I->Fix.begin(), I->Fix.end());
+  return tooling::applyAllReplacements(Code, Fixes);
+}
+
+} // namespace test
 } // namespace tidy
 } // namespace clang