GtestMatchers.h 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. #pragma once
  2. #ifdef __GNUC__
  3. #pragma GCC diagnostic push
  4. #pragma GCC diagnostic ignored "-Wunused-parameter"
  5. #endif
  6. //===- GtestMatchers.h - AST Matchers for GTest -----------------*- C++ -*-===//
  7. //
  8. // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
  9. // See https://llvm.org/LICENSE.txt for license information.
  10. // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
  11. //
  12. //===----------------------------------------------------------------------===//
  13. //
  14. // This file implements matchers specific to structures in the Googletest
  15. // (gtest) framework.
  16. //
  17. //===----------------------------------------------------------------------===//
  18. #ifndef LLVM_CLANG_ASTMATCHERS_GTESTMATCHERS_H
  19. #define LLVM_CLANG_ASTMATCHERS_GTESTMATCHERS_H
  20. #include "clang/AST/Stmt.h"
  21. #include "clang/ASTMatchers/ASTMatchers.h"
  22. #include "llvm/ADT/StringRef.h"
  23. namespace clang {
  24. namespace ast_matchers {
  25. /// Gtest's comparison operations.
  26. enum class GtestCmp {
  27. Eq,
  28. Ne,
  29. Ge,
  30. Gt,
  31. Le,
  32. Lt,
  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. /// Matcher for gtest's ASSERT comparison macros including ASSERT_EQ, ASSERT_NE,
  43. /// ASSERT_GE, ASSERT_GT, ASSERT_LE and ASSERT_LT.
  44. internal::BindableMatcher<Stmt> gtestAssert(GtestCmp Cmp, StatementMatcher Left,
  45. StatementMatcher Right);
  46. /// Matcher for gtest's ASSERT_THAT macro.
  47. internal::BindableMatcher<Stmt> gtestAssertThat(StatementMatcher Actual,
  48. StatementMatcher Matcher);
  49. /// Matcher for gtest's EXPECT comparison macros including EXPECT_EQ, EXPECT_NE,
  50. /// EXPECT_GE, EXPECT_GT, EXPECT_LE and EXPECT_LT.
  51. internal::BindableMatcher<Stmt> gtestExpect(GtestCmp Cmp, StatementMatcher Left,
  52. StatementMatcher Right);
  53. /// Matcher for gtest's EXPECT_THAT macro.
  54. internal::BindableMatcher<Stmt> gtestExpectThat(StatementMatcher Actual,
  55. StatementMatcher Matcher);
  56. /// Matcher for gtest's EXPECT_CALL macro. `MockObject` matches the mock
  57. /// object and `MockMethodName` is the name of the method invoked on the mock
  58. /// object.
  59. internal::BindableMatcher<Stmt> gtestExpectCall(StatementMatcher MockObject,
  60. llvm::StringRef MockMethodName,
  61. MockArgs Args);
  62. /// Matcher for gtest's EXPECT_CALL macro. `MockCall` matches the whole mock
  63. /// member method call. This API is more flexible but requires more knowledge of
  64. /// the AST structure of EXPECT_CALL macros.
  65. internal::BindableMatcher<Stmt> gtestExpectCall(StatementMatcher MockCall,
  66. MockArgs Args);
  67. /// Like the first `gtestExpectCall` overload but for `ON_CALL`.
  68. internal::BindableMatcher<Stmt> gtestOnCall(StatementMatcher MockObject,
  69. llvm::StringRef MockMethodName,
  70. MockArgs Args);
  71. /// Like the second `gtestExpectCall` overload but for `ON_CALL`.
  72. internal::BindableMatcher<Stmt> gtestOnCall(StatementMatcher MockCall,
  73. MockArgs Args);
  74. } // namespace ast_matchers
  75. } // namespace clang
  76. #endif // LLVM_CLANG_ASTMATCHERS_GTESTMATCHERS_H
  77. #ifdef __GNUC__
  78. #pragma GCC diagnostic pop
  79. #endif