[clang-tools-extra] r202399 - Made the ClangTidyTest helper class independent of the testing framework.
Alexander Kornienko
alexfh at google.com
Thu Feb 27 06:28:02 PST 2014
Author: alexfh
Date: Thu Feb 27 08:28:02 2014
New Revision: 202399
URL: http://llvm.org/viewvc/llvm-project?rev=202399&view=rev
Log:
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
Modified:
clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h
clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp
clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp
Modified: clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h?rev=202399&r1=202398&r2=202399&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h (original)
+++ clang-tools-extra/trunk/unittests/clang-tidy/ClangTidyTest.h Thu Feb 27 08:28:02 2014
@@ -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) {}
-
- private:
- virtual bool BeginSourceFileAction(CompilerInstance &Compiler,
- llvm::StringRef file_name) {
- Context->setSourceManager(&Compiler.getSourceManager());
- Check.registerPPCallbacks(Compiler);
- return true;
- }
-
- ClangTidyCheck &Check;
- ClangTidyContext *Context;
- };
+ bool BeginSourceFileAction(CompilerInstance &Compiler,
+ llvm::StringRef file_name) LLVM_OVERRIDE {
+ Context->setSourceManager(&Compiler.getSourceManager());
+ Check.registerPPCallbacks(Compiler);
+ return true;
+ }
- 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
Modified: clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp?rev=202399&r1=202398&r2=202399&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-tidy/GoogleModuleTest.cpp Thu Feb 27 08:28:02 2014
@@ -1,30 +1,36 @@
#include "ClangTidyTest.h"
#include "google/GoogleTidyModule.h"
+#include "gtest/gtest.h"
namespace clang {
namespace tidy {
+namespace test {
-typedef ClangTidyTest<ExplicitConstructorCheck> ExplicitConstructorCheckTest;
+#define EXPECT_NO_CHANGES(Check, Code) \
+ EXPECT_EQ(Code, runCheckOnCode<Check>(Code))
-TEST_F(ExplicitConstructorCheckTest, SingleArgumentConstructorsOnly) {
- expectNoChanges("class C { C(); };");
- expectNoChanges("class C { C(int i, int j); };");
+TEST(ExplicitConstructorCheckTest, SingleArgumentConstructorsOnly) {
+ EXPECT_NO_CHANGES(ExplicitConstructorCheck, "class C { C(); };");
+ EXPECT_NO_CHANGES(ExplicitConstructorCheck, "class C { C(int i, int j); };");
}
-TEST_F(ExplicitConstructorCheckTest, Basic) {
+TEST(ExplicitConstructorCheckTest, Basic) {
EXPECT_EQ("class C { explicit C(int i); };",
- runCheckOn("class C { C(int i); };"));
+ runCheckOnCode<ExplicitConstructorCheck>("class C { C(int i); };"));
}
-TEST_F(ExplicitConstructorCheckTest, DefaultParameters) {
+TEST(ExplicitConstructorCheckTest, DefaultParameters) {
EXPECT_EQ("class C { explicit C(int i, int j = 0); };",
- runCheckOn("class C { C(int i, int j = 0); };"));
+ runCheckOnCode<ExplicitConstructorCheck>(
+ "class C { C(int i, int j = 0); };"));
}
-TEST_F(ExplicitConstructorCheckTest, OutOfLineDefinitions) {
+TEST(ExplicitConstructorCheckTest, OutOfLineDefinitions) {
EXPECT_EQ("class C { explicit C(int i); }; C::C(int i) {}",
- runCheckOn("class C { C(int i); }; C::C(int i) {}"));
+ runCheckOnCode<ExplicitConstructorCheck>(
+ "class C { C(int i); }; C::C(int i) {}"));
}
+} // namespace test
} // namespace tidy
} // namespace clang
Modified: clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp
URL: http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp?rev=202399&r1=202398&r2=202399&view=diff
==============================================================================
--- clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp (original)
+++ clang-tools-extra/trunk/unittests/clang-tidy/LLVMModuleTest.cpp Thu Feb 27 08:28:02 2014
@@ -1,14 +1,16 @@
#include "ClangTidyTest.h"
#include "llvm/LLVMTidyModule.h"
+#include "gtest/gtest.h"
namespace clang {
namespace tidy {
+namespace test {
-typedef ClangTidyTest<NamespaceCommentCheck> NamespaceCommentCheckTest;
-
-TEST_F(NamespaceCommentCheckTest, Basic) {
- EXPECT_EQ("namespace i {\n} // namespace i", runCheckOn("namespace i {\n}"));
+TEST(NamespaceCommentCheckTest, Basic) {
+ EXPECT_EQ("namespace i {\n} // namespace i",
+ runCheckOnCode<NamespaceCommentCheck>("namespace i {\n}"));
}
+} // namespace test
} // namespace tidy
} // namespace clang
More information about the cfe-commits
mailing list