diff --git a/clang/include/clang/ASTMatchers/GtestMatchers.h b/clang/include/clang/ASTMatchers/GtestMatchers.h deleted file mode 100644 index e19d91a674f2e..0000000000000 --- a/clang/include/clang/ASTMatchers/GtestMatchers.h +++ /dev/null @@ -1,87 +0,0 @@ -//===- GtestMatchers.h - AST Matchers for GTest -----------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file implements matchers specific to structures in the Googletest -// (gtest) framework. -// -//===----------------------------------------------------------------------===// - -#ifndef LLVM_CLANG_ASTMATCHERS_GTESTMATCHERS_H -#define LLVM_CLANG_ASTMATCHERS_GTESTMATCHERS_H - -#include "clang/AST/Stmt.h" -#include "clang/ASTMatchers/ASTMatchers.h" -#include "llvm/ADT/StringRef.h" - -namespace clang { -namespace ast_matchers { - -/// Gtest's comparison operations. -enum class GtestCmp { - Eq, - Ne, - Ge, - Gt, - Le, - Lt, -}; - -/// This enum indicates whether the mock method in the matched ON_CALL or -/// EXPECT_CALL macro has arguments. For example, `None` can be used to match -/// `ON_CALL(mock, TwoParamMethod)` whereas `Some` can be used to match -/// `ON_CALL(mock, TwoParamMethod(m1, m2))`. -enum class MockArgs { - None, - Some, -}; - -/// Matcher for gtest's ASSERT comparison macros including ASSERT_EQ, ASSERT_NE, -/// ASSERT_GE, ASSERT_GT, ASSERT_LE and ASSERT_LT. -internal::BindableMatcher gtestAssert(GtestCmp Cmp, StatementMatcher Left, - StatementMatcher Right); - -/// Matcher for gtest's ASSERT_THAT macro. -internal::BindableMatcher gtestAssertThat(StatementMatcher Actual, - StatementMatcher Matcher); - -/// Matcher for gtest's EXPECT comparison macros including EXPECT_EQ, EXPECT_NE, -/// EXPECT_GE, EXPECT_GT, EXPECT_LE and EXPECT_LT. -internal::BindableMatcher gtestExpect(GtestCmp Cmp, StatementMatcher Left, - StatementMatcher Right); - -/// Matcher for gtest's EXPECT_THAT macro. -internal::BindableMatcher gtestExpectThat(StatementMatcher Actual, - StatementMatcher Matcher); - -/// Matcher for gtest's EXPECT_CALL macro. `MockObject` matches the mock -/// object and `MockMethodName` is the name of the method invoked on the mock -/// object. -internal::BindableMatcher gtestExpectCall(StatementMatcher MockObject, - llvm::StringRef MockMethodName, - MockArgs Args); - -/// Matcher for gtest's EXPECT_CALL macro. `MockCall` matches the whole mock -/// member method call. This API is more flexible but requires more knowledge of -/// the AST structure of EXPECT_CALL macros. -internal::BindableMatcher gtestExpectCall(StatementMatcher MockCall, - MockArgs Args); - -/// Like the first `gtestExpectCall` overload but for `ON_CALL`. -internal::BindableMatcher gtestOnCall(StatementMatcher MockObject, - llvm::StringRef MockMethodName, - MockArgs Args); - -/// Like the second `gtestExpectCall` overload but for `ON_CALL`. -internal::BindableMatcher gtestOnCall(StatementMatcher MockCall, - MockArgs Args); - -} // namespace ast_matchers -} // namespace clang - -#endif // LLVM_CLANG_ASTMATCHERS_GTESTMATCHERS_H - diff --git a/clang/lib/ASTMatchers/CMakeLists.txt b/clang/lib/ASTMatchers/CMakeLists.txt index 7769fd656ac06..29ad27dfcd761 100644 --- a/clang/lib/ASTMatchers/CMakeLists.txt +++ b/clang/lib/ASTMatchers/CMakeLists.txt @@ -8,7 +8,6 @@ set(LLVM_LINK_COMPONENTS add_clang_library(clangASTMatchers ASTMatchFinder.cpp ASTMatchersInternal.cpp - GtestMatchers.cpp LowLevelHelpers.cpp LINK_LIBS diff --git a/clang/lib/ASTMatchers/GtestMatchers.cpp b/clang/lib/ASTMatchers/GtestMatchers.cpp deleted file mode 100644 index 7c135bbfe7cb0..0000000000000 --- a/clang/lib/ASTMatchers/GtestMatchers.cpp +++ /dev/null @@ -1,228 +0,0 @@ -//===- GtestMatchers.cpp - AST Matchers for Gtest ---------------*- C++ -*-===// -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// -// -// This file implements several matchers for popular gtest macros. In general, -// AST matchers cannot match calls to macros. However, we can simulate such -// matches if the macro definition has identifiable elements that themselves can -// be matched. In that case, we can match on those elements and then check that -// the match occurs within an expansion of the desired macro. The more uncommon -// the identified elements, the more efficient this process will be. -// -//===----------------------------------------------------------------------===// - -#include "clang/ASTMatchers/GtestMatchers.h" -#include "llvm/ADT/StringRef.h" - -namespace clang { -namespace ast_matchers { -namespace { - -enum class MacroType { - Expect, - Assert, - On, -}; - -} // namespace - -static DeclarationMatcher getComparisonDecl(GtestCmp Cmp) { - switch (Cmp) { - case GtestCmp::Eq: - return cxxMethodDecl(hasName("Compare"), - ofClass(cxxRecordDecl(isSameOrDerivedFrom( - hasName("::testing::internal::EqHelper"))))); - case GtestCmp::Ne: - return functionDecl(hasName("::testing::internal::CmpHelperNE")); - case GtestCmp::Ge: - return functionDecl(hasName("::testing::internal::CmpHelperGE")); - case GtestCmp::Gt: - return functionDecl(hasName("::testing::internal::CmpHelperGT")); - case GtestCmp::Le: - return functionDecl(hasName("::testing::internal::CmpHelperLE")); - case GtestCmp::Lt: - return functionDecl(hasName("::testing::internal::CmpHelperLT")); - } - llvm_unreachable("Unhandled GtestCmp enum"); -} - -static llvm::StringRef getMacroTypeName(MacroType Macro) { - switch (Macro) { - case MacroType::Expect: - return "EXPECT"; - case MacroType::Assert: - return "ASSERT"; - case MacroType::On: - return "ON"; - } - llvm_unreachable("Unhandled MacroType enum"); -} - -static llvm::StringRef getComparisonTypeName(GtestCmp Cmp) { - switch (Cmp) { - case GtestCmp::Eq: - return "EQ"; - case GtestCmp::Ne: - return "NE"; - case GtestCmp::Ge: - return "GE"; - case GtestCmp::Gt: - return "GT"; - case GtestCmp::Le: - return "LE"; - case GtestCmp::Lt: - return "LT"; - } - llvm_unreachable("Unhandled GtestCmp enum"); -} - -static std::string getMacroName(MacroType Macro, GtestCmp Cmp) { - return (getMacroTypeName(Macro) + "_" + getComparisonTypeName(Cmp)).str(); -} - -static std::string getMacroName(MacroType Macro, llvm::StringRef Operation) { - return (getMacroTypeName(Macro) + "_" + Operation).str(); -} - -// Under the hood, ON_CALL is expanded to a call to `InternalDefaultActionSetAt` -// to set a default action spec to the underlying function mocker, while -// EXPECT_CALL is expanded to a call to `InternalExpectedAt` to set a new -// expectation spec. -static llvm::StringRef getSpecSetterName(MacroType Macro) { - switch (Macro) { - case MacroType::On: - return "InternalDefaultActionSetAt"; - case MacroType::Expect: - return "InternalExpectedAt"; - default: - llvm_unreachable("Unhandled MacroType enum"); - } - llvm_unreachable("Unhandled MacroType enum"); -} - -// In general, AST matchers cannot match calls to macros. However, we can -// simulate such matches if the macro definition has identifiable elements that -// themselves can be matched. In that case, we can match on those elements and -// then check that the match occurs within an expansion of the desired -// macro. The more uncommon the identified elements, the more efficient this -// process will be. -// -// We use this approach to implement the derived matchers gtestAssert and -// gtestExpect. -static internal::BindableMatcher -gtestComparisonInternal(MacroType Macro, GtestCmp Cmp, StatementMatcher Left, - StatementMatcher Right) { - return callExpr(isExpandedFromMacro(getMacroName(Macro, Cmp)), - callee(getComparisonDecl(Cmp)), hasArgument(2, Left), - hasArgument(3, Right)); -} - -static internal::BindableMatcher -gtestThatInternal(MacroType Macro, StatementMatcher Actual, - StatementMatcher Matcher) { - return cxxOperatorCallExpr( - isExpandedFromMacro(getMacroName(Macro, "THAT")), - hasOverloadedOperatorName("()"), hasArgument(2, Actual), - hasArgument( - 0, expr(hasType(classTemplateSpecializationDecl(hasName( - "::testing::internal::PredicateFormatterFromMatcher"))), - ignoringImplicit( - callExpr(callee(functionDecl(hasName( - "::testing::internal::" - "MakePredicateFormatterFromMatcher"))), - hasArgument(0, ignoringImplicit(Matcher))))))); -} - -static internal::BindableMatcher -gtestCallInternal(MacroType Macro, StatementMatcher MockCall, MockArgs Args) { - // A ON_CALL or EXPECT_CALL macro expands to different AST structures - // depending on whether the mock method has arguments or not. - switch (Args) { - // For example, - // `ON_CALL(mock, TwoParamMethod)` is expanded to - // `mock.gmock_TwoArgsMethod(WithoutMatchers(), - // nullptr).InternalDefaultActionSetAt(...)`. - // EXPECT_CALL is the same except - // that it calls `InternalExpectedAt` instead of `InternalDefaultActionSetAt` - // in the end. - case MockArgs::None: - return cxxMemberCallExpr( - isExpandedFromMacro(getMacroName(Macro, "CALL")), - callee(functionDecl(hasName(getSpecSetterName(Macro)))), - onImplicitObjectArgument(ignoringImplicit(MockCall))); - // For example, - // `ON_CALL(mock, TwoParamMethod(m1, m2))` is expanded to - // `mock.gmock_TwoParamMethod(m1,m2)(WithoutMatchers(), - // nullptr).InternalDefaultActionSetAt(...)`. - // EXPECT_CALL is the same except that it calls `InternalExpectedAt` instead - // of `InternalDefaultActionSetAt` in the end. - case MockArgs::Some: - return cxxMemberCallExpr( - isExpandedFromMacro(getMacroName(Macro, "CALL")), - callee(functionDecl(hasName(getSpecSetterName(Macro)))), - onImplicitObjectArgument(ignoringImplicit(cxxOperatorCallExpr( - hasOverloadedOperatorName("()"), argumentCountIs(3), - hasArgument(0, ignoringImplicit(MockCall)))))); - } - llvm_unreachable("Unhandled MockArgs enum"); -} - -static internal::BindableMatcher -gtestCallInternal(MacroType Macro, StatementMatcher MockObject, - llvm::StringRef MockMethodName, MockArgs Args) { - return gtestCallInternal( - Macro, - cxxMemberCallExpr( - onImplicitObjectArgument(MockObject), - callee(functionDecl(hasName(("gmock_" + MockMethodName).str())))), - Args); -} - -internal::BindableMatcher gtestAssert(GtestCmp Cmp, StatementMatcher Left, - StatementMatcher Right) { - return gtestComparisonInternal(MacroType::Assert, Cmp, Left, Right); -} - -internal::BindableMatcher gtestExpect(GtestCmp Cmp, StatementMatcher Left, - StatementMatcher Right) { - return gtestComparisonInternal(MacroType::Expect, Cmp, Left, Right); -} - -internal::BindableMatcher gtestAssertThat(StatementMatcher Actual, - StatementMatcher Matcher) { - return gtestThatInternal(MacroType::Assert, Actual, Matcher); -} - -internal::BindableMatcher gtestExpectThat(StatementMatcher Actual, - StatementMatcher Matcher) { - return gtestThatInternal(MacroType::Expect, Actual, Matcher); -} - -internal::BindableMatcher gtestOnCall(StatementMatcher MockObject, - llvm::StringRef MockMethodName, - MockArgs Args) { - return gtestCallInternal(MacroType::On, MockObject, MockMethodName, Args); -} - -internal::BindableMatcher gtestOnCall(StatementMatcher MockCall, - MockArgs Args) { - return gtestCallInternal(MacroType::On, MockCall, Args); -} - -internal::BindableMatcher gtestExpectCall(StatementMatcher MockObject, - llvm::StringRef MockMethodName, - MockArgs Args) { - return gtestCallInternal(MacroType::Expect, MockObject, MockMethodName, Args); -} - -internal::BindableMatcher gtestExpectCall(StatementMatcher MockCall, - MockArgs Args) { - return gtestCallInternal(MacroType::Expect, MockCall, Args); -} - -} // end namespace ast_matchers -} // end namespace clang diff --git a/clang/unittests/ASTMatchers/CMakeLists.txt b/clang/unittests/ASTMatchers/CMakeLists.txt index 47bd5c108bb5a..955566cf650e8 100644 --- a/clang/unittests/ASTMatchers/CMakeLists.txt +++ b/clang/unittests/ASTMatchers/CMakeLists.txt @@ -3,7 +3,6 @@ add_clang_unittest(ASTMatchersTests ASTMatchersNodeTest.cpp ASTMatchersNarrowingTest.cpp ASTMatchersTraversalTest.cpp - GtestMatchersTest.cpp CLANG_LIBS clangAST clangASTMatchers diff --git a/clang/unittests/ASTMatchers/GtestMatchersTest.cpp b/clang/unittests/ASTMatchers/GtestMatchersTest.cpp deleted file mode 100644 index 5ee67a9e54844..0000000000000 --- a/clang/unittests/ASTMatchers/GtestMatchersTest.cpp +++ /dev/null @@ -1,418 +0,0 @@ -//===- unittests/ASTMatchers/GTestMatchersTest.cpp - GTest matcher unit tests // -// -// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. -// See https://llvm.org/LICENSE.txt for license information. -// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception -// -//===----------------------------------------------------------------------===// - -#include "ASTMatchersTest.h" -#include "clang/ASTMatchers/ASTMatchers.h" -#include "clang/ASTMatchers/GtestMatchers.h" - -namespace clang { -namespace ast_matchers { - -constexpr llvm::StringLiteral GtestMockDecls = R"cc( - static int testerr; - -#define GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - switch (0) \ - case 0: \ - default: // NOLINT - -#define GTEST_NONFATAL_FAILURE_(code) testerr = code - -#define GTEST_FATAL_FAILURE_(code) testerr = code - -#define GTEST_ASSERT_(expression, on_failure) \ - GTEST_AMBIGUOUS_ELSE_BLOCKER_ \ - if (const int gtest_ar = (expression)) \ - ; \ - else \ - on_failure(gtest_ar) - - // Internal macro for implementing {EXPECT|ASSERT}_PRED_FORMAT2. - // Don't use this in your code. -#define GTEST_PRED_FORMAT2_(pred_format, v1, v2, on_failure) \ - GTEST_ASSERT_(pred_format(#v1, #v2, v1, v2), on_failure) - -#define ASSERT_PRED_FORMAT2(pred_format, v1, v2) \ - GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_FATAL_FAILURE_) -#define EXPECT_PRED_FORMAT2(pred_format, v1, v2) \ - GTEST_PRED_FORMAT2_(pred_format, v1, v2, GTEST_NONFATAL_FAILURE_) - -#define GTEST_PRED_FORMAT1_(pred_format, v1, on_failure) \ - GTEST_ASSERT_(pred_format(#v1, v1), on_failure) - -#define EXPECT_PRED_FORMAT1(pred_format, v1) \ - GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_NONFATAL_FAILURE_) -#define ASSERT_PRED_FORMAT1(pred_format, v1) \ - GTEST_PRED_FORMAT1_(pred_format, v1, GTEST_FATAL_FAILURE_) - -#define EXPECT_EQ(val1, val2) \ - EXPECT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2) -#define EXPECT_NE(val1, val2) \ - EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2) -#define EXPECT_GE(val1, val2) \ - EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGE, val1, val2) -#define EXPECT_GT(val1, val2) \ - EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperGT, val1, val2) -#define EXPECT_LE(val1, val2) \ - EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLE, val1, val2) -#define EXPECT_LT(val1, val2) \ - EXPECT_PRED_FORMAT2(::testing::internal::CmpHelperLT, val1, val2) - -#define ASSERT_THAT(value, matcher) \ - ASSERT_PRED_FORMAT1( \ - ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value) -#define EXPECT_THAT(value, matcher) \ - EXPECT_PRED_FORMAT1( \ - ::testing::internal::MakePredicateFormatterFromMatcher(matcher), value) - -#define ASSERT_EQ(val1, val2) \ - ASSERT_PRED_FORMAT2(::testing::internal::EqHelper::Compare, val1, val2) -#define ASSERT_NE(val1, val2) \ - ASSERT_PRED_FORMAT2(::testing::internal::CmpHelperNE, val1, val2) - -#define GMOCK_ON_CALL_IMPL_(mock_expr, Setter, call) \ - ((mock_expr).gmock_##call)(::testing::internal::GetWithoutMatchers(), \ - nullptr) \ - .Setter(nullptr, 0, #mock_expr, #call) - -#define ON_CALL(obj, call) \ - GMOCK_ON_CALL_IMPL_(obj, InternalDefaultActionSetAt, call) - -#define EXPECT_CALL(obj, call) \ - GMOCK_ON_CALL_IMPL_(obj, InternalExpectedAt, call) - - namespace testing { - namespace internal { - class EqHelper { - public: - // This templatized version is for the general case. - template - static int Compare(const char* lhs_expression, const char* rhs_expression, - const T1& lhs, const T2& rhs) { - return 0; - } - }; - template - int CmpHelperNE(const char* expr1, const char* expr2, const T1& val1, - const T2& val2) { - return 0; - } - template - int CmpHelperGE(const char* expr1, const char* expr2, const T1& val1, - const T2& val2) { - return 0; - } - template - int CmpHelperGT(const char* expr1, const char* expr2, const T1& val1, - const T2& val2) { - return 0; - } - template - int CmpHelperLE(const char* expr1, const char* expr2, const T1& val1, - const T2& val2) { - return 0; - } - template - int CmpHelperLT(const char* expr1, const char* expr2, const T1& val1, - const T2& val2) { - return 0; - } - - // For implementing ASSERT_THAT() and EXPECT_THAT(). The template - // argument M must be a type that can be converted to a matcher. - template - class PredicateFormatterFromMatcher { - public: - explicit PredicateFormatterFromMatcher(M m) : matcher_(m) {} - - // This template () operator allows a PredicateFormatterFromMatcher - // object to act as a predicate-formatter suitable for using with - // Google Test's EXPECT_PRED_FORMAT1() macro. - template - int operator()(const char* value_text, const T& x) const { - return 0; - } - - private: - const M matcher_; - }; - - template - inline PredicateFormatterFromMatcher MakePredicateFormatterFromMatcher( - M matcher) { - return PredicateFormatterFromMatcher(matcher); - } - - bool GetWithoutMatchers() { return false; } - - template - class MockSpec { - public: - MockSpec() {} - - bool InternalDefaultActionSetAt( - const char* file, int line, const char* obj, const char* call) { - return false; - } - - bool InternalExpectedAt( - const char* file, int line, const char* obj, const char* call) { - return false; - } - - MockSpec operator()(bool, void*) { - return *this; - } - }; // class MockSpec - - } // namespace internal - - template - int StrEq(T val) { - return 0; - } - template - int Eq(T val) { - return 0; - } - - } // namespace testing - - class Mock { - public: - Mock() {} - testing::internal::MockSpec gmock_TwoArgsMethod(int, int) { - return testing::internal::MockSpec(); - } - testing::internal::MockSpec gmock_TwoArgsMethod(bool, void*) { - return testing::internal::MockSpec(); - } - }; // class Mock -)cc"; - -static std::string wrapGtest(llvm::StringRef Input) { - return (GtestMockDecls + Input).str(); -} - -TEST(GtestAssertTest, ShouldMatchAssert) { - std::string Input = R"cc( - void Test() { ASSERT_EQ(1010, 4321); } - )cc"; - EXPECT_TRUE(matches(wrapGtest(Input), - gtestAssert(GtestCmp::Eq, integerLiteral(equals(1010)), - integerLiteral(equals(4321))))); -} - -TEST(GtestAssertTest, ShouldNotMatchExpect) { - std::string Input = R"cc( - void Test() { EXPECT_EQ(2, 3); } - )cc"; - EXPECT_TRUE( - notMatches(wrapGtest(Input), gtestAssert(GtestCmp::Eq, expr(), expr()))); -} - -TEST(GtestAssertTest, ShouldMatchNestedAssert) { - std::string Input = R"cc( - #define WRAPPER(a, b) ASSERT_EQ(a, b) - void Test() { WRAPPER(2, 3); } - )cc"; - EXPECT_TRUE( - matches(wrapGtest(Input), gtestAssert(GtestCmp::Eq, expr(), expr()))); -} - -TEST(GtestExpectTest, ShouldMatchExpect) { - std::string Input = R"cc( - void Test() { EXPECT_EQ(1010, 4321); } - )cc"; - EXPECT_TRUE(matches(wrapGtest(Input), - gtestExpect(GtestCmp::Eq, integerLiteral(equals(1010)), - integerLiteral(equals(4321))))); -} - -TEST(GtestExpectTest, ShouldNotMatchAssert) { - std::string Input = R"cc( - void Test() { ASSERT_EQ(2, 3); } - )cc"; - EXPECT_TRUE( - notMatches(wrapGtest(Input), gtestExpect(GtestCmp::Eq, expr(), expr()))); -} - -TEST(GtestExpectTest, NeShouldMatchExpectNe) { - std::string Input = R"cc( - void Test() { EXPECT_NE(2, 3); } - )cc"; - EXPECT_TRUE( - matches(wrapGtest(Input), gtestExpect(GtestCmp::Ne, expr(), expr()))); -} - -TEST(GtestExpectTest, LeShouldMatchExpectLe) { - std::string Input = R"cc( - void Test() { EXPECT_LE(2, 3); } - )cc"; - EXPECT_TRUE( - matches(wrapGtest(Input), gtestExpect(GtestCmp::Le, expr(), expr()))); -} - -TEST(GtestExpectTest, LtShouldMatchExpectLt) { - std::string Input = R"cc( - void Test() { EXPECT_LT(2, 3); } - )cc"; - EXPECT_TRUE( - matches(wrapGtest(Input), gtestExpect(GtestCmp::Lt, expr(), expr()))); -} - -TEST(GtestExpectTest, GeShouldMatchExpectGe) { - std::string Input = R"cc( - void Test() { EXPECT_GE(2, 3); } - )cc"; - EXPECT_TRUE( - matches(wrapGtest(Input), gtestExpect(GtestCmp::Ge, expr(), expr()))); -} - -TEST(GtestExpectTest, GtShouldMatchExpectGt) { - std::string Input = R"cc( - void Test() { EXPECT_GT(2, 3); } - )cc"; - EXPECT_TRUE( - matches(wrapGtest(Input), gtestExpect(GtestCmp::Gt, expr(), expr()))); -} - -TEST(GtestExpectTest, ThatShouldMatchAssertThat) { - std::string Input = R"cc( - using ::testing::Eq; - void Test() { ASSERT_THAT(2, Eq(2)); } - )cc"; - EXPECT_TRUE(matches( - wrapGtest(Input), - gtestAssertThat( - expr(), callExpr(callee(functionDecl(hasName("::testing::Eq"))))))); -} - -TEST(GtestExpectTest, ThatShouldMatchExpectThat) { - std::string Input = R"cc( - using ::testing::Eq; - void Test() { EXPECT_THAT(2, Eq(2)); } - )cc"; - EXPECT_TRUE(matches( - wrapGtest(Input), - gtestExpectThat( - expr(), callExpr(callee(functionDecl(hasName("::testing::Eq"))))))); -} - -TEST(GtestOnCallTest, CallShouldMatchOnCallWithoutParams1) { - std::string Input = R"cc( - void Test() { - Mock mock; - ON_CALL(mock, TwoArgsMethod); - } - )cc"; - EXPECT_TRUE(matches(wrapGtest(Input), - gtestOnCall(expr(hasType(cxxRecordDecl(hasName("Mock")))), - "TwoArgsMethod", MockArgs::None))); -} - -TEST(GtestOnCallTest, CallShouldMatchOnCallWithoutParams2) { - std::string Input = R"cc( - void Test() { - Mock mock; - ON_CALL(mock, TwoArgsMethod); - } - )cc"; - EXPECT_TRUE(matches( - wrapGtest(Input), - gtestOnCall(cxxMemberCallExpr( - callee(functionDecl(hasName("gmock_TwoArgsMethod")))) - .bind("mock_call"), - MockArgs::None))); -} - -TEST(GtestOnCallTest, CallShouldMatchOnCallWithParams1) { - std::string Input = R"cc( - void Test() { - Mock mock; - ON_CALL(mock, TwoArgsMethod(1, 2)); - } - )cc"; - EXPECT_TRUE(matches(wrapGtest(Input), - gtestOnCall(expr(hasType(cxxRecordDecl(hasName("Mock")))), - "TwoArgsMethod", MockArgs::Some))); -} - -TEST(GtestOnCallTest, CallShouldMatchOnCallWithParams2) { - std::string Input = R"cc( - void Test() { - Mock mock; - ON_CALL(mock, TwoArgsMethod(1, 2)); - } - )cc"; - EXPECT_TRUE(matches( - wrapGtest(Input), - gtestOnCall(cxxMemberCallExpr( - callee(functionDecl(hasName("gmock_TwoArgsMethod")))) - .bind("mock_call"), - MockArgs::Some))); -} - -TEST(GtestExpectCallTest, CallShouldMatchExpectCallWithoutParams1) { - std::string Input = R"cc( - void Test() { - Mock mock; - EXPECT_CALL(mock, TwoArgsMethod); - } - )cc"; - EXPECT_TRUE( - matches(wrapGtest(Input), - gtestExpectCall(expr(hasType(cxxRecordDecl(hasName("Mock")))), - "TwoArgsMethod", MockArgs::None))); -} - -TEST(GtestExpectCallTest, CallShouldMatchExpectCallWithoutParams2) { - std::string Input = R"cc( - void Test() { - Mock mock; - EXPECT_CALL(mock, TwoArgsMethod); - } - )cc"; - EXPECT_TRUE(matches( - wrapGtest(Input), - gtestExpectCall(cxxMemberCallExpr( - callee(functionDecl(hasName("gmock_TwoArgsMethod")))) - .bind("mock_call"), - MockArgs::None))); -} - -TEST(GtestExpectCallTest, CallShouldMatchExpectCallWithParams1) { - std::string Input = R"cc( - void Test() { - Mock mock; - EXPECT_CALL(mock, TwoArgsMethod(1, 2)); - } - )cc"; - EXPECT_TRUE( - matches(wrapGtest(Input), - gtestExpectCall(expr(hasType(cxxRecordDecl(hasName("Mock")))), - "TwoArgsMethod", MockArgs::Some))); -} - -TEST(GtestExpectCallTest, CallShouldMatchExpectCallWithParams2) { - std::string Input = R"cc( - void Test() { - Mock mock; - EXPECT_CALL(mock, TwoArgsMethod(1, 2)); - } - )cc"; - EXPECT_TRUE(matches( - wrapGtest(Input), - gtestExpectCall(cxxMemberCallExpr( - callee(functionDecl(hasName("gmock_TwoArgsMethod")))) - .bind("mock_call"), - MockArgs::Some))); -} - -} // end namespace ast_matchers -} // end namespace clang diff --git a/llvm/utils/gn/secondary/clang/lib/ASTMatchers/BUILD.gn b/llvm/utils/gn/secondary/clang/lib/ASTMatchers/BUILD.gn index 63bf7268db306..8fe30b8a5f26e 100644 --- a/llvm/utils/gn/secondary/clang/lib/ASTMatchers/BUILD.gn +++ b/llvm/utils/gn/secondary/clang/lib/ASTMatchers/BUILD.gn @@ -9,7 +9,6 @@ static_library("ASTMatchers") { sources = [ "ASTMatchFinder.cpp", "ASTMatchersInternal.cpp", - "GtestMatchers.cpp", "LowLevelHelpers.cpp", ] } diff --git a/llvm/utils/gn/secondary/clang/unittests/ASTMatchers/BUILD.gn b/llvm/utils/gn/secondary/clang/unittests/ASTMatchers/BUILD.gn index 10f540b5e60ab..56d3484110aab 100644 --- a/llvm/utils/gn/secondary/clang/unittests/ASTMatchers/BUILD.gn +++ b/llvm/utils/gn/secondary/clang/unittests/ASTMatchers/BUILD.gn @@ -17,6 +17,5 @@ unittest("ASTMatchersTests") { "ASTMatchersNarrowingTest.cpp", "ASTMatchersNodeTest.cpp", "ASTMatchersTraversalTest.cpp", - "GtestMatchersTest.cpp", ] }