clang  14.0.0git
GtestMatchers.h
Go to the documentation of this file.
1 //===- GtestMatchers.h - AST Matchers for GTest -----------------*- C++ -*-===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
8 //
9 // This file implements matchers specific to structures in the Googletest
10 // (gtest) framework.
11 //
12 //===----------------------------------------------------------------------===//
13 
14 #ifndef LLVM_CLANG_ASTMATCHERS_GTESTMATCHERS_H
15 #define LLVM_CLANG_ASTMATCHERS_GTESTMATCHERS_H
16 
17 #include "clang/AST/Stmt.h"
19 #include "llvm/ADT/StringRef.h"
20 
21 namespace clang {
22 namespace ast_matchers {
23 
24 /// Gtest's comparison operations.
25 enum class GtestCmp {
26  Eq,
27  Ne,
28  Ge,
29  Gt,
30  Le,
31  Lt,
32 };
33 
34 /// This enum indicates whether the mock method in the matched ON_CALL or
35 /// EXPECT_CALL macro has arguments. For example, `None` can be used to match
36 /// `ON_CALL(mock, TwoParamMethod)` whereas `Some` can be used to match
37 /// `ON_CALL(mock, TwoParamMethod(m1, m2))`.
38 enum class MockArgs {
39  None,
40  Some,
41 };
42 
43 /// Matcher for gtest's ASSERT comparison macros including ASSERT_EQ, ASSERT_NE,
44 /// ASSERT_GE, ASSERT_GT, ASSERT_LE and ASSERT_LT.
45 internal::BindableMatcher<Stmt> gtestAssert(GtestCmp Cmp, StatementMatcher Left,
46  StatementMatcher Right);
47 
48 /// Matcher for gtest's ASSERT_THAT macro.
49 internal::BindableMatcher<Stmt> gtestAssertThat(StatementMatcher Actual,
50  StatementMatcher Matcher);
51 
52 /// Matcher for gtest's EXPECT comparison macros including EXPECT_EQ, EXPECT_NE,
53 /// EXPECT_GE, EXPECT_GT, EXPECT_LE and EXPECT_LT.
54 internal::BindableMatcher<Stmt> gtestExpect(GtestCmp Cmp, StatementMatcher Left,
55  StatementMatcher Right);
56 
57 /// Matcher for gtest's EXPECT_THAT macro.
58 internal::BindableMatcher<Stmt> gtestExpectThat(StatementMatcher Actual,
59  StatementMatcher Matcher);
60 
61 /// Matcher for gtest's EXPECT_CALL macro. `MockObject` matches the mock
62 /// object and `MockMethodName` is the name of the method invoked on the mock
63 /// object.
64 internal::BindableMatcher<Stmt> gtestExpectCall(StatementMatcher MockObject,
65  llvm::StringRef MockMethodName,
66  MockArgs Args);
67 
68 /// Matcher for gtest's EXPECT_CALL macro. `MockCall` matches the whole mock
69 /// member method call. This API is more flexible but requires more knowledge of
70 /// the AST structure of EXPECT_CALL macros.
71 internal::BindableMatcher<Stmt> gtestExpectCall(StatementMatcher MockCall,
72  MockArgs Args);
73 
74 /// Like the first `gtestExpectCall` overload but for `ON_CALL`.
75 internal::BindableMatcher<Stmt> gtestOnCall(StatementMatcher MockObject,
76  llvm::StringRef MockMethodName,
77  MockArgs Args);
78 
79 /// Like the second `gtestExpectCall` overload but for `ON_CALL`.
80 internal::BindableMatcher<Stmt> gtestOnCall(StatementMatcher MockCall,
81  MockArgs Args);
82 
83 } // namespace ast_matchers
84 } // namespace clang
85 
86 #endif // LLVM_CLANG_ASTMATCHERS_GTESTMATCHERS_H
87 
clang::ast_matchers::GtestCmp::Eq
@ Eq
clang::ast_matchers::StatementMatcher
internal::Matcher< Stmt > StatementMatcher
Definition: ASTMatchers.h:142
clang::ast_matchers::MockArgs::None
@ None
clang::ast_matchers::GtestCmp::Lt
@ Lt
clang::ast_matchers::MockArgs::Some
@ Some
clang::ast_matchers::MockArgs
MockArgs
This enum indicates whether the mock method in the matched ON_CALL or EXPECT_CALL macro has arguments...
Definition: GtestMatchers.h:38
clang::ast_matchers::GtestCmp
GtestCmp
Gtest's comparison operations.
Definition: GtestMatchers.h:25
ASTMatchers.h
clang::ast_matchers::gtestExpectThat
internal::BindableMatcher< Stmt > gtestExpectThat(StatementMatcher Actual, StatementMatcher Matcher)
Matcher for gtest's EXPECT_THAT macro.
Definition: GtestMatchers.cpp:206
clang::ast_matchers::gtestAssertThat
internal::BindableMatcher< Stmt > gtestAssertThat(StatementMatcher Actual, StatementMatcher Matcher)
Matcher for gtest's ASSERT_THAT macro.
Definition: GtestMatchers.cpp:201
clang::ast_matchers::gtestAssert
internal::BindableMatcher< Stmt > gtestAssert(GtestCmp Cmp, StatementMatcher Left, StatementMatcher Right)
Matcher for gtest's ASSERT comparison macros including ASSERT_EQ, ASSERT_NE, ASSERT_GE,...
Definition: GtestMatchers.cpp:191
clang::ast_matchers::GtestCmp::Le
@ Le
clang::ast_matchers::gtestExpectCall
internal::BindableMatcher< Stmt > gtestExpectCall(StatementMatcher MockObject, llvm::StringRef MockMethodName, MockArgs Args)
Matcher for gtest's EXPECT_CALL macro.
Definition: GtestMatchers.cpp:222
clang::ast_matchers::GtestCmp::Gt
@ Gt
clang::ast_matchers::GtestCmp::Ne
@ Ne
clang::ast_matchers::GtestCmp::Ge
@ Ge
clang::ast_matchers::gtestOnCall
internal::BindableMatcher< Stmt > gtestOnCall(StatementMatcher MockObject, llvm::StringRef MockMethodName, MockArgs Args)
Like the first gtestExpectCall overload but for ON_CALL.
Definition: GtestMatchers.cpp:211
clang
Definition: CalledOnceCheck.h:17
Stmt.h
clang::ast_matchers::gtestExpect
internal::BindableMatcher< Stmt > gtestExpect(GtestCmp Cmp, StatementMatcher Left, StatementMatcher Right)
Matcher for gtest's EXPECT comparison macros including EXPECT_EQ, EXPECT_NE, EXPECT_GE,...
Definition: GtestMatchers.cpp:196