[PATCH] Made the ClangTidyTest helper class independent of the testing framework.
Alexander Kornienko
alexfh at google.com
Thu Feb 27 05:44:40 PST 2014
Hi klimek,
http://llvm-reviews.chandlerc.com/D2895
Files:
unittests/clang-tidy/ClangTidyTest.h
unittests/clang-tidy/GoogleModuleTest.cpp
unittests/clang-tidy/LLVMModuleTest.cpp
Index: unittests/clang-tidy/ClangTidyTest.h
===================================================================
--- unittests/clang-tidy/ClangTidyTest.h
+++ unittests/clang-tidy/ClangTidyTest.h
@@ -17,25 +17,23 @@
#include "clang/Frontend/FrontendActions.h"
#include "clang/Tooling/Refactoring.h"
#include "clang/Tooling/Tooling.h"
-#include "gtest/gtest.h"
namespace clang {
namespace tidy {
-template <typename T> class ClangTidyTest : public ::testing::Test {
-protected:
+template <typename T> class ClangTidyTest {
+public:
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));
+ 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));
+ tooling::runToolOnCode(Factory->create(), Code);
DiagConsumer.finish();
tooling::Replacements Fixes;
for (SmallVector<ClangTidyError, 16>::const_iterator I = Errors.begin(),
@@ -45,17 +43,15 @@
return tooling::applyAllReplacements(Code, Fixes);
}
- void expectNoChanges(StringRef Code) { EXPECT_EQ(Code, runCheckOn(Code)); }
-
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) {
+ bool BeginSourceFileAction(CompilerInstance &Compiler,
+ llvm::StringRef file_name) LLVM_OVERRIDE {
Context->setSourceManager(&Compiler.getSourceManager());
Check.registerPPCallbacks(Compiler);
return true;
Index: unittests/clang-tidy/GoogleModuleTest.cpp
===================================================================
--- unittests/clang-tidy/GoogleModuleTest.cpp
+++ unittests/clang-tidy/GoogleModuleTest.cpp
@@ -1,29 +1,34 @@
#include "ClangTidyTest.h"
#include "google/GoogleTidyModule.h"
+#include "gtest/gtest.h"
namespace clang {
namespace tidy {
-typedef ClangTidyTest<ExplicitConstructorCheck> ExplicitConstructorCheckTest;
+#define EXPECT_NO_CHANGES(test, code) EXPECT_EQ(code, test.runCheckOn(code))
-TEST_F(ExplicitConstructorCheckTest, SingleArgumentConstructorsOnly) {
- expectNoChanges("class C { C(); };");
- expectNoChanges("class C { C(int i, int j); };");
+TEST(ExplicitConstructorCheckTest, SingleArgumentConstructorsOnly) {
+ ClangTidyTest<ExplicitConstructorCheck> test;
+ EXPECT_NO_CHANGES(test, "class C { C(); };");
+ EXPECT_NO_CHANGES(test, "class C { C(int i, int j); };");
}
-TEST_F(ExplicitConstructorCheckTest, Basic) {
+TEST(ExplicitConstructorCheckTest, Basic) {
+ ClangTidyTest<ExplicitConstructorCheck> test;
EXPECT_EQ("class C { explicit C(int i); };",
- runCheckOn("class C { C(int i); };"));
+ test.runCheckOn("class C { C(int i); };"));
}
-TEST_F(ExplicitConstructorCheckTest, DefaultParameters) {
+TEST(ExplicitConstructorCheckTest, DefaultParameters) {
+ ClangTidyTest<ExplicitConstructorCheck> test;
EXPECT_EQ("class C { explicit C(int i, int j = 0); };",
- runCheckOn("class C { C(int i, int j = 0); };"));
+ test.runCheckOn("class C { C(int i, int j = 0); };"));
}
-TEST_F(ExplicitConstructorCheckTest, OutOfLineDefinitions) {
+TEST(ExplicitConstructorCheckTest, OutOfLineDefinitions) {
+ ClangTidyTest<ExplicitConstructorCheck> test;
EXPECT_EQ("class C { explicit C(int i); }; C::C(int i) {}",
- runCheckOn("class C { C(int i); }; C::C(int i) {}"));
+ test.runCheckOn("class C { C(int i); }; C::C(int i) {}"));
}
} // namespace tidy
Index: unittests/clang-tidy/LLVMModuleTest.cpp
===================================================================
--- unittests/clang-tidy/LLVMModuleTest.cpp
+++ unittests/clang-tidy/LLVMModuleTest.cpp
@@ -1,13 +1,14 @@
#include "ClangTidyTest.h"
#include "llvm/LLVMTidyModule.h"
+#include "gtest/gtest.h"
namespace clang {
namespace tidy {
-typedef ClangTidyTest<NamespaceCommentCheck> NamespaceCommentCheckTest;
-
-TEST_F(NamespaceCommentCheckTest, Basic) {
- EXPECT_EQ("namespace i {\n} // namespace i", runCheckOn("namespace i {\n}"));
+TEST(NamespaceCommentCheckTest, Basic) {
+ ClangTidyTest<NamespaceCommentCheck> test;
+ EXPECT_EQ("namespace i {\n} // namespace i",
+ test.runCheckOn("namespace i {\n}"));
}
} // namespace tidy
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D2895.1.patch
Type: text/x-patch
Size: 4853 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20140227/e7568f35/attachment.bin>
More information about the cfe-commits
mailing list