clang 20.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
21namespace clang {
22namespace ast_matchers {
23
24/// Gtest's comparison operations.
25enum 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))`.
38enum 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.
45internal::BindableMatcher<Stmt> gtestAssert(GtestCmp Cmp, StatementMatcher Left,
46 StatementMatcher Right);
47
48/// Matcher for gtest's ASSERT_THAT macro.
49internal::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.
54internal::BindableMatcher<Stmt> gtestExpect(GtestCmp Cmp, StatementMatcher Left,
55 StatementMatcher Right);
56
57/// Matcher for gtest's EXPECT_THAT macro.
58internal::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.
64internal::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.
71internal::BindableMatcher<Stmt> gtestExpectCall(StatementMatcher MockCall,
72 MockArgs Args);
73
74/// Like the first `gtestExpectCall` overload but for `ON_CALL`.
75internal::BindableMatcher<Stmt> gtestOnCall(StatementMatcher MockObject,
76 llvm::StringRef MockMethodName,
77 MockArgs Args);
78
79/// Like the second `gtestExpectCall` overload but for `ON_CALL`.
80internal::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
internal::BindableMatcher< Stmt > gtestAssert(GtestCmp Cmp, StatementMatcher Left, StatementMatcher Right)
Matcher for gtest's ASSERT comparison macros including ASSERT_EQ, ASSERT_NE, ASSERT_GE,...
MockArgs
This enum indicates whether the mock method in the matched ON_CALL or EXPECT_CALL macro has arguments...
Definition: GtestMatchers.h:38
GtestCmp
Gtest's comparison operations.
Definition: GtestMatchers.h:25
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::BindableMatcher< Stmt > gtestExpectThat(StatementMatcher Actual, StatementMatcher Matcher)
Matcher for gtest's EXPECT_THAT macro.
internal::Matcher< Stmt > StatementMatcher
Definition: ASTMatchers.h:144
internal::BindableMatcher< Stmt > gtestAssertThat(StatementMatcher Actual, StatementMatcher Matcher)
Matcher for gtest's ASSERT_THAT macro.
internal::BindableMatcher< Stmt > gtestOnCall(StatementMatcher MockObject, llvm::StringRef MockMethodName, MockArgs Args)
Like the first gtestExpectCall overload but for ON_CALL.
internal::BindableMatcher< Stmt > gtestExpectCall(StatementMatcher MockObject, llvm::StringRef MockMethodName, MockArgs Args)
Matcher for gtest's EXPECT_CALL macro.
The JSON file list parser is used to communicate input to InstallAPI.