TEST_P overrides TestBody() with public visibility instead
of private as defined in the Test base class
PiperOrigin-RevId: 981828756
Change-Id: I9ad0852642520b6b8585df15c3e63885f6fbd135
Static (linker-initialized) global mutex has a
pthread_t member, which is currently initialized
with 0. This is incorrect, since pthread_t is
an opaque type, which can be a struct in some
libc implementations (e.g. in LLVM-libc). Using
POSIX-specified PTHREAD_NULL is a better option,
however it may not be available on older platforms.
So, use PTHREAD_NULL if it's available, but
fallback to the original behavior for compatibility.
PiperOrigin-RevId: 979239391
Change-Id: I79a292868f85f62bb1962b3ac956ad40eb145907
Previously, non-Abseil builds of GoogleTest used either the POSIX <regex.h> header, or a hand-rolled bare-bones regex engine in GoogleTest.
This commit removes the custom regex engine and switches to the C++11 <regex> header instead, which primarily affects Windows builds. Correspondingly, the GTEST_USES_SIMPLE_RE macro is removed and GTEST_USES_STD_RE is defined in its place, so users that depend on the macro should update their code accordingly.
This commit may break on any exotic toolchains or platforms that lack all of these libraries, but these have been long unsupported, as GoogleTest requires C++17.
Note: MSVC's engine can be prone to overflowing the stack on some patterns and inputs. As a trivial example:
#include <regex>
int main() {
std::string corpus;
for (size_t i = 0; i < 1000; ++i) {
corpus += "a\n";
}
// Stack overflow
std::regex_match(corpus, std::regex("(\n|.)*", std::regex_constants::ECMAScript));
}
In such cases, it is recommended to use alternative patterns accomplishing the same goal, such as checking for pieces of a pattern independently.
PiperOrigin-RevId: 978659894
Change-Id: I4594285e696af12a008e1e4cee300f292bbdbf32
Compilers before this do not support C++17 at all, which is required by GoogleTest.
PiperOrigin-RevId: 975312508
Change-Id: I77a0649a11ea9162010a8a26807e4a970610616f
Classic IBM XL C/C++ (__IBMCPP__) only supported up to C++14 (V16.1 for AIX) before IBM retired the proprietary frontend and transitioned to IBM Open XL C/C++ (which is Clang-based and defines __clang__).
Since the legacy XL frontend never supported C++17, the workarounds are obsolete and should be removed.
PiperOrigin-RevId: 975123206
Change-Id: Ia706c7759d3f1df73d375fca68f91eee3aaef825
Classic Borland C++ (bcc32) only supported up to C++98/C++03 before Embarcadero transitioned C++Builder to Clang-based compilers (bcc32c/bcc64, which define __clang__) and is long obsolete.
PiperOrigin-RevId: 974883761
Change-Id: I220f736485710f37fe4a2b922bda3116304e3812
Oracle Developer Studio 12.6 (released July 2017) was the final release of the SunPro/Solaris Studio compiler suite, providing only partial/experimental support for C++14 before Oracle discontinued active compiler development. Sun Studio never supported C++17.
Additionally, Solaris 8 and 9 reached EOL over a decade ago. Therefore, workarounds for non-standard putenv/getenv memory behavior in legacy Solaris libc are obsolete, and should be removed.
PiperOrigin-RevId: 974866696
Change-Id: I29db7a1123642c7db0975522c641bd0500a40682
HP aC++ for HP-UX on Itanium (A.06.28) only supported up to C++03 and partial C++11 before HPE placed HP-UX and Itanium into maintenance mode. It was discontinued without ever supporting C++14 or C++17.
As GoogleTest requires C++17, the HP-specific workarounds are obsolete and should be removed.
PiperOrigin-RevId: 974700202
Change-Id: Iff9a41101f90f65d76394752bf197b8f2e97311f
Define `GTEST_HAS_NATIVE_WCHAR` as a replacement for the `!defined(_MSC_VER) || defined(_NATIVE_WCHAR_T_DEFINED)` condition used to remove `wchar_t*` overloads when `wchar_t` is a typedef. Remove `GMOCK_WCHAR_T_IS_NATIVE_` and migrate its uses to the GTest define.
PiperOrigin-RevId: 966022317
Change-Id: Ic929f45763566b9e8d194f280d1f32f5a582ff61
If the standard library claims not to support wide character strings, disable `GTEST_HAS_STD_WSTRING` and disallow users overriding it. If the standard library implementation can't be recognized, fall back to using the existing list of OSes with a known lack of support.
PiperOrigin-RevId: 964237076
Change-Id: I906f296259f8f17099990d51447a0d0d04dead66
If the standard library doesn't support wide character strings, `std::char_traits<Char>` won't be defined, so the definition of `PrintTo` shouldn't reference it. Use `wstrlen` directly instead.
PiperOrigin-RevId: 964168903
Change-Id: Ic628e6583679073b47bb1218dcf52b4c9eadaaf6
Android started supporting std::wstring with API Level 21 (Lollipop). On Android, unless `GTEST_HAS_STD_WSTRING` is explicitly defined, set it based on the current Android API level.
PiperOrigin-RevId: 963538624
Change-Id: I1a19c4e5b0fef841e0650a1f95b45fa3439dee92
This reapplies the change that was rolled back, with the change that it removes the convertibility requirement to string_view, because that excluded some desirable explicit conversions (like absl::Cord). Note that this is now the same criterion previously used by testing::internal::StringLike.
Fixes: #4912
PiperOrigin-RevId: 959205696
Change-Id: I002cb1224f5a2701bdf8e68ea4d91776b9c38593
Add a configurable `GTEST_HAS_WCHAR` option to control whether to provide `wchar_t*` overloads for `PrintTo`. Check implementation-specific standard library defines to determine proper defaults for `GTEST_HAS_WCHAR` and `GTEST_HAS_STD_WSTRING` and to produce compile errors if the users pick a configuration that depends on unavailable standard library features.
PiperOrigin-RevId: 958668507
Change-Id: Ic9b78d83fb455dff7d993303d54a0bde749a8cd8
Add a configurable `GTEST_HAS_WCHAR` option to control whether to provide `wchar_t*` overloads for `PrintTo`. Check implementation-specific standard library defines to determine proper defaults for `GTEST_HAS_WCHAR` and `GTEST_HAS_STD_WSTRING` and to produce compile errors if the users pick a configuration that depends on unavailable standard library features.
PiperOrigin-RevId: 958595883
Change-Id: I5ff25b395e4cbdab679effa7e760d64c31ac6572
Currently, these macros do not behave consistently in how they convert objects to bool, adding extra const qualifiers or using operator!(). This causes them to produce unexpected behavior on types such as the following:
```
struct example {
operator bool() { throw std::runtime_error("constness not propagated"); }
operator bool() const { return ...; }
};
```
This change preserves the qualifiers of the evaluated objects and makes the evaluation strategy uniform across macros.
Fixes: #4832
PiperOrigin-RevId: 953424646
Change-Id: I670a72eec11272c3b68d7eb6f739a15da227acde
This is the legacy fix for https://github.com/google/googletest/issues/4731, and to prevent similar breakages in the future with other flags.
The modern fix will be handled separately.
PiperOrigin-RevId: 953333662
Change-Id: I7c58b0123170878f0fe6909cabd5decc922b38f1
The alternate implementation based on ABSL_FLAG() already does this internally, so this resolves the inconsistency.
Fixes: #4897
PiperOrigin-RevId: 952840499
Change-Id: I7b8f61d2e9a97ffcd3db091abc373c9d9b48db79
Actions can now be implicitly constructed from zero-argument callables. There is no need to create wrapper objects using InvokeWithoutArgs().
PiperOrigin-RevId: 949656497
Change-Id: Ida2bc38e446e7b33aaf185ec593caf2a1959138e
Subsequences are defined as: "a subsequence of a given sequence is a sequence that can be derived from the given sequence by deleting some or no elements without changing the order of the remaining elements."
See: https://en.wikipedia.org/wiki/Subsequence
This new matcher checks if a container contains elements that match a given sequence of matchers in the specified order, but not necessarily contiguously.
The implementation is very similar to other matchers like ElementsAre or Contains.
PiperOrigin-RevId: 918323422
Change-Id: I56d7ebbe6f81038c93546ef7585db59eea5dbd57
DieInCRTDebugElse12() is only used inside a #ifdef _DEBUG block. Put
its definition inside a #ifdef _DEBUG block, too, otherwise we get a
"defined but not used [-Wunused-function]" warning under MinGW GCC.
PiperOrigin-RevId: 891795658
Change-Id: Ic9109eebc354dd20b2a5430794f491c9b451931f
Add an alternative implementation of the Notification class for MinGW
using a Windows manual-reset event object.
GCC version < 13 in MinGW, if configured with the win32 thread model
(with the --enable-threads=win32 configure option), does not implement
std::mutex and std::condition_variable in the <mutex> and
<condition_variable> headers. So the current implementation of the
Notification class, which uses std::mutex and std::condition_variable,
has compilation errors. Windows has a synchronization object called a
manual-reset event object that behaves just like the Notification class.
So we can easily implement the Notification class using a Windows
manual-reset event object.
This GCC issue is fixed in GCC 13. See
https://gcc.gnu.org/gcc-13/changes.html#windows. This alternative
implementation of Notification should be removed when GoogleTest
requires GCC version >= 13 in MinGW.
Fixes https://github.com/google/googletest/issues/4031 and
https://github.com/google/googletest/issues/4464.
PiperOrigin-RevId: 888752598
Change-Id: I69e01b2e7953e1fe72d87b6d0804c7a8a8d0e740
This is needed for ranges such as [`std::ranges::subrange`](https://en.cppreference.com/w/cpp/ranges/subrange.html) that don't expose the typical typedefs.
PiperOrigin-RevId: 879124865
Change-Id: Ie89e6ff249ee861d1b2d880079dc162bb9801679
Update str concatenation, instead of use operation+ use absl::StrCat
whenever available.
PiperOrigin-RevId: 874649732
Change-Id: I0acd91c04a9e50fa306e7130479bc330c1a0f068
If the iterators are forward iterators, we can measure the size and reserve the vector, avoiding reallocations and copying.
PiperOrigin-RevId: 874172640
Change-Id: Ie081fdf7952858d7e41ddda63a3ae15d9867c8c5
Change a mention of Eq(Optional(nullopt)) to Optional(Eq(nullopt)).
Optional is supposed to wrap matchers, not values. For example, Optional("bla") doesn't compile but Optional(std::string("bla")) does. Optional(Eq("bla")) is the functionally correct version. Eq() cannot wrap a matcher.
PiperOrigin-RevId: 872885639
Change-Id: I941f515308fa419162998073f6da9731fcf2168a
Clarify that SizeIs only requires the container to have a size() method, and the argument type can be any type compatible with the return type of size(). The previous comment incorrectly mentioned a requirement for size_type.
PiperOrigin-RevId: 869184176
Change-Id: Ib2d867fbfecde0006734772cf07958871a171199
The [Premature Exit File](https://google.github.io/googletest/advanced.html#detecting-test-premature-exit)
can be used for more than just death tests. Runners can use it to detect any
kind of unexpected exit.
Presently, its creation is tied to whether a platform supports Death
Tests. This change removes that coupling (though if Death Tests are supported,
then the Premature Exit file is implicitly supported).
PiperOrigin-RevId: 853416224
Change-Id: I5354730b82bc8a20981120f4e1df59b58cb31f6e
Sharded tests interact awkwardly with --gtest_fail_if_no_test_selected, but we
can't speak clearly enough to the use cases to complicate the mental model, so
instead we attempt to clarify the simplest approach to debugging a single test
when sharding and --gtest_fail_if_no_test_selected are both in use: unset the
flag.
PiperOrigin-RevId: 829686145
Change-Id: I9ebbddc6e7537feefe2a3707fd323fc9132b99d1
This allows for simpler migration of function args to smart pointers without needing all changes to tests to be atomic.
PiperOrigin-RevId: 818635600
Change-Id: I9434685d9640f82b98d0b5261701b78c93d3ec1e
Replace an internal link to AbslStringify's documentation with the equivalent public link.
PiperOrigin-RevId: 779085254
Change-Id: I2cbd2b6262a5ced06f166d4fcc7c08796e5a60af