summaryrefslogtreecommitdiffstats
path: root/googlemock/include/gmock/internal
diff options
context:
space:
mode:
authorDerek Mauro <dmauro@google.com>2022-04-04 14:38:23 (GMT)
committerCopybara-Service <copybara-worker@google.com>2022-04-04 14:39:03 (GMT)
commit25dcdc7e8bfac8967f20fb2c0a628f5cf442188d (patch)
tree0bd2bf078f5491dfd089dc0fab194b805788d622 /googlemock/include/gmock/internal
parentaf29db7ec28d6df1c7f0f745186884091e602e07 (diff)
downloadgoogletest-25dcdc7e8bfac8967f20fb2c0a628f5cf442188d.zip
googletest-25dcdc7e8bfac8967f20fb2c0a628f5cf442188d.tar.gz
googletest-25dcdc7e8bfac8967f20fb2c0a628f5cf442188d.tar.bz2
Use the Abseil flags library when Abseil is present
When built with `--define=absl=1` under Bazel, GoogleTest flags use ABSL_FLAG instead of GoogleTest's own implementation. There are some minor behavior differences in this mode. The most notable difference is that unrecognized flags result in a flag parsing error, and are not returned to the user though a modified argc/argv, unless they appear after the positional argument delimiter ("--"). For example, to pass a non-Abseil flag, you would have to do ./mytest --gtest_color=false -- --myflag=myvalue The documentation at https://abseil.io/docs/cpp/guides/flags may be helpful in understanding the behavior. There are some other minor differences. For example, passing --help results in the program returning 1 instead of 0. https://github.com/google/googletest/issues/3646 PiperOrigin-RevId: 439312700 Change-Id: Id696a25f50f24a5b1785c45ca8fa59794f86fd5c
Diffstat (limited to 'googlemock/include/gmock/internal')
-rw-r--r--googlemock/include/gmock/internal/gmock-port.h67
1 files changed, 47 insertions, 20 deletions
diff --git a/googlemock/include/gmock/internal/gmock-port.h b/googlemock/include/gmock/internal/gmock-port.h
index f3e63c1..bc18a25 100644
--- a/googlemock/include/gmock/internal/gmock-port.h
+++ b/googlemock/include/gmock/internal/gmock-port.h
@@ -42,7 +42,6 @@
#include <assert.h>
#include <stdlib.h>
-
#include <cstdint>
#include <iostream>
@@ -57,6 +56,11 @@
#include "gmock/internal/custom/gmock-port.h"
#include "gtest/internal/gtest-port.h"
+#if GTEST_HAS_ABSL
+#include "absl/flags/declare.h"
+#include "absl/flags/flag.h"
+#endif
+
// For MS Visual C++, check the compiler version. At least VS 2015 is
// required to compile Google Mock.
#if defined(_MSC_VER) && _MSC_VER < 1900
@@ -65,26 +69,33 @@
// Macro for referencing flags. This is public as we want the user to
// use this syntax to reference Google Mock flags.
+#define GMOCK_FLAG_NAME_(name) gmock_##name
#define GMOCK_FLAG(name) FLAGS_gmock_##name
-#if !defined(GMOCK_DECLARE_bool_)
+// Pick a command line flags implementation.
+#if GTEST_HAS_ABSL
+
+// Macros for defining flags.
+#define GMOCK_DEFINE_bool_(name, default_val, doc) \
+ ABSL_FLAG(bool, GMOCK_FLAG_NAME_(name), default_val, doc)
+#define GMOCK_DEFINE_int32_(name, default_val, doc) \
+ ABSL_FLAG(int32_t, GMOCK_FLAG_NAME_(name), default_val, doc)
+#define GMOCK_DEFINE_string_(name, default_val, doc) \
+ ABSL_FLAG(std::string, GMOCK_FLAG_NAME_(name), default_val, doc)
// Macros for declaring flags.
-#define GMOCK_DECLARE_bool_(name) \
- namespace testing { \
- GTEST_API_ extern bool GMOCK_FLAG(name); \
- } \
- static_assert(true, "no-op to require trailing semicolon")
-#define GMOCK_DECLARE_int32_(name) \
- namespace testing { \
- GTEST_API_ extern int32_t GMOCK_FLAG(name); \
- } \
- static_assert(true, "no-op to require trailing semicolon")
-#define GMOCK_DECLARE_string_(name) \
- namespace testing { \
- GTEST_API_ extern ::std::string GMOCK_FLAG(name); \
- } \
- static_assert(true, "no-op to require trailing semicolon")
+#define GMOCK_DECLARE_bool_(name) \
+ ABSL_DECLARE_FLAG(bool, GMOCK_FLAG_NAME_(name))
+#define GMOCK_DECLARE_int32_(name) \
+ ABSL_DECLARE_FLAG(int32_t, GMOCK_FLAG_NAME_(name))
+#define GMOCK_DECLARE_string_(name) \
+ ABSL_DECLARE_FLAG(std::string, GMOCK_FLAG_NAME_(name))
+
+#define GMOCK_FLAG_GET(name) ::absl::GetFlag(GMOCK_FLAG(name))
+#define GMOCK_FLAG_SET(name, value) \
+ (void)(::absl::SetFlag(&GMOCK_FLAG(name), value))
+
+#else // GTEST_HAS_ABSL
// Macros for defining flags.
#define GMOCK_DEFINE_bool_(name, default_val, doc) \
@@ -102,11 +113,27 @@
GTEST_API_ ::std::string GMOCK_FLAG(name) = (default_val); \
} \
static_assert(true, "no-op to require trailing semicolon")
-#endif // !defined(GMOCK_DECLARE_bool_)
-#if !defined(GMOCK_FLAG_GET)
+// Macros for declaring flags.
+#define GMOCK_DECLARE_bool_(name) \
+ namespace testing { \
+ GTEST_API_ extern bool GMOCK_FLAG(name); \
+ } \
+ static_assert(true, "no-op to require trailing semicolon")
+#define GMOCK_DECLARE_int32_(name) \
+ namespace testing { \
+ GTEST_API_ extern int32_t GMOCK_FLAG(name); \
+ } \
+ static_assert(true, "no-op to require trailing semicolon")
+#define GMOCK_DECLARE_string_(name) \
+ namespace testing { \
+ GTEST_API_ extern ::std::string GMOCK_FLAG(name); \
+ } \
+ static_assert(true, "no-op to require trailing semicolon")
+
#define GMOCK_FLAG_GET(name) ::testing::GMOCK_FLAG(name)
#define GMOCK_FLAG_SET(name, value) (void)(::testing::GMOCK_FLAG(name) = value)
-#endif // !defined(GMOCK_FLAG_GET)
+
+#endif // GTEST_HAS_ABSL
#endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_PORT_H_