clang: lib/ASTMatchers/GtestMatchers.cpp Source File (original) (raw)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
23#include "llvm/ADT/DenseMap.h"
24#include "llvm/ADT/StringRef.h"
25
27namespace ast_matchers {
28namespace {
29
30enum class MacroType {
31 Expect,
32 Assert,
33 On,
34};
35
36}
37
39 switch (Cmp) {
43 hasName("::testing::internal::EqHelper")))));
54 }
55 llvm_unreachable("Unhandled GtestCmp enum");
56}
57
59 switch (Macro) {
60 case MacroType::Expect:
61 return "EXPECT";
62 case MacroType::Assert:
63 return "ASSERT";
64 case MacroType::On:
65 return "ON";
66 }
67 llvm_unreachable("Unhandled MacroType enum");
68}
69
71 switch (Cmp) {
73 return "EQ";
75 return "NE";
77 return "GE";
79 return "GT";
81 return "LE";
83 return "LT";
84 }
85 llvm_unreachable("Unhandled GtestCmp enum");
86}
87
90}
91
92static std::string getMacroName(MacroType Macro, llvm::StringRef Operation) {
94}
95
96
97
98
99
101 switch (Macro) {
102 case MacroType::On:
103 return "InternalDefaultActionSetAt";
104 case MacroType::Expect:
105 return "InternalExpectedAt";
106 default:
107 llvm_unreachable("Unhandled MacroType enum");
108 }
109 llvm_unreachable("Unhandled MacroType enum");
110}
111
112
113
114
115
116
117
118
119
120
121static internal::BindableMatcher
126 hasArgument(3, Right));
127}
128
129static internal::BindableMatcher
133 isExpandedFromMacro(getMacroName(Macro, "THAT")),
135 hasArgument(
137 "::testing::internal::PredicateFormatterFromMatcher"))),
138 ignoringImplicit(
140 "::testing::internal::"
141 "MakePredicateFormatterFromMatcher"))),
142 hasArgument(0, ignoringImplicit(Matcher)))))));
143}
144
145static internal::BindableMatcher
147
148
149 switch (Args) {
150
151
152
153
154
155
156
159 isExpandedFromMacro(getMacroName(Macro, "CALL")),
161 onImplicitObjectArgument(ignoringImplicit(MockCall)));
162
163
164
165
166
167
170 isExpandedFromMacro(getMacroName(Macro, "CALL")),
174 hasArgument(0, ignoringImplicit(MockCall))))));
175 }
176 llvm_unreachable("Unhandled MockArgs enum");
177}
178
179static internal::BindableMatcher
181 llvm::StringRef MockMethodName, MockArgs Args) {
183 Macro,
185 onImplicitObjectArgument(MockObject),
187 Args);
188}
189
193}
194
198}
199
203}
204
208}
209
211 llvm::StringRef MockMethodName,
213 return gtestCallInternal(MacroType::On, MockObject, MockMethodName, Args);
214}
215
219}
220
222 llvm::StringRef MockMethodName,
224 return gtestCallInternal(MacroType::Expect, MockObject, MockMethodName, Args);
225}
226
230}
231
232}
233}
Defines the clang::ASTContext interface.
internal::BindableMatcher< Stmt > gtestAssert(GtestCmp Cmp, StatementMatcher Left, StatementMatcher Right)
Matcher for gtest's ASSERT comparison macros including ASSERT_EQ, ASSERT_NE, ASSERT_GE,...
static internal::BindableMatcher< Stmt > gtestComparisonInternal(MacroType Macro, GtestCmp Cmp, StatementMatcher Left, StatementMatcher Right)
MockArgs
This enum indicates whether the mock method in the matched ON_CALL or EXPECT_CALL macro has arguments...
static llvm::StringRef getComparisonTypeName(GtestCmp Cmp)
GtestCmp
Gtest's comparison operations.
internal::Matcher< Decl > DeclarationMatcher
Types of matchers for the top-level classes in the AST class hierarchy.
static DeclarationMatcher getComparisonDecl(GtestCmp Cmp)
internal::BindableMatcher< Stmt > gtestExpect(GtestCmp Cmp, StatementMatcher Left, StatementMatcher Right)
Matcher for gtest's EXPECT comparison macros including EXPECT_EQ, EXPECT_NE, EXPECT_GE,...
internal::Matcher< NamedDecl > hasName(StringRef Name)
Matches NamedDecl nodes that have the specified name.
const internal::VariadicDynCastAllOfMatcher< Stmt, CallExpr > callExpr
Matches call expressions.
static llvm::StringRef getMacroTypeName(MacroType Macro)
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXMemberCallExpr > cxxMemberCallExpr
Matches member call expressions.
internal::BindableMatcher< Stmt > gtestExpectThat(StatementMatcher Actual, StatementMatcher Matcher)
Matcher for gtest's EXPECT_THAT macro.
static internal::BindableMatcher< Stmt > gtestThatInternal(MacroType Macro, StatementMatcher Actual, StatementMatcher Matcher)
internal::Matcher< Stmt > StatementMatcher
internal::BindableMatcher< Stmt > gtestAssertThat(StatementMatcher Actual, StatementMatcher Matcher)
Matcher for gtest's ASSERT_THAT macro.
const internal::VariadicDynCastAllOfMatcher< Stmt, CXXOperatorCallExpr > cxxOperatorCallExpr
Matches overloaded operator calls.
internal::PolymorphicMatcher< internal::HasOverloadedOperatorNameMatcher, AST_POLYMORPHIC_SUPPORTED_TYPES(CXXOperatorCallExpr, FunctionDecl), std::vector< std::string > > hasOverloadedOperatorName(StringRef Name)
Matches overloaded operator names.
const internal::VariadicDynCastAllOfMatcher< Decl, ClassTemplateSpecializationDecl > classTemplateSpecializationDecl
Matches C++ class template specializations.
const internal::VariadicDynCastAllOfMatcher< Decl, FunctionDecl > functionDecl
Matches function declarations.
const internal::VariadicDynCastAllOfMatcher< Decl, CXXRecordDecl > cxxRecordDecl
Matches C++ class declarations.
internal::BindableMatcher< Stmt > gtestOnCall(StatementMatcher MockObject, llvm::StringRef MockMethodName, MockArgs Args)
Like the first gtestExpectCall overload but for ON_CALL.
static std::string getMacroName(MacroType Macro, GtestCmp Cmp)
internal::BindableMatcher< Stmt > gtestExpectCall(StatementMatcher MockObject, llvm::StringRef MockMethodName, MockArgs Args)
Matcher for gtest's EXPECT_CALL macro.
const internal::VariadicDynCastAllOfMatcher< Stmt, Expr > expr
Matches expressions.
static llvm::StringRef getSpecSetterName(MacroType Macro)
const internal::VariadicDynCastAllOfMatcher< Decl, CXXMethodDecl > cxxMethodDecl
Matches method declarations.
static internal::BindableMatcher< Stmt > gtestCallInternal(MacroType Macro, StatementMatcher MockCall, MockArgs Args)
The JSON file list parser is used to communicate input to InstallAPI.