480 Commits
Author SHA1 Message Date
Abseil Team 4267679b68 Fix the compilation of the matcher UnorderedElementsAre when used with
a native pointer and size

PiperOrigin-RevId: 983276604
Change-Id: I76ee9771bae7b0801e6aa74c0786bf5809b43226
2026-09-17 10:23:06 -07:00
Abseil Team 283c17563f Remove workarounds for MSVC with versions _MSC_VER < 1925
GoogleTest only supports Visual Studio 2022 or later.

PiperOrigin-RevId: 975742423
Change-Id: Ibc09f5cd2c8cb1f9097bd27b584ec136ec2ce42a
2026-09-03 08:29:26 -07:00
Abseil Team efbef50b59 Remove workarounds for MSVC with versions _MSC_VER < 1915
Compilers before this do not support C++17 at all, which is required by GoogleTest.

PiperOrigin-RevId: 975312508
Change-Id: I77a0649a11ea9162010a8a26807e4a970610616f
2026-09-02 14:02:24 -07:00
Abseil Team c3e1e7fe8e Avoid linter warning about multiline comments
PiperOrigin-RevId: 974701766
Change-Id: I8098fe21ed27f0e3bed9568837579551fe0918dd
2026-09-01 14:16:50 -07:00
Abseil Team 36ba75f0ad UnorderedElementsAre(): Allow matching containers where end is a [sentinel](https://en.cppreference.com/cpp/iterator/sentinel_for). ElementsAre already supports that.
PiperOrigin-RevId: 971869110
Change-Id: I1316463fbd0b532bdf5d636d47165aace84b3801
2026-08-27 04:14:10 -07:00
Abseil Team 71edd0ef29 Extract GTEST_HAS_NATIVE_WCHAR
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
2026-08-17 09:42:15 -07:00
Abseil Team 002d14757f When Return is passed to WillOnce (i.e. converted to OnceAction) delegate to be equivalent to Return(ByMove(...))
This should eliminate most required usages of ByMove(...).

PiperOrigin-RevId: 964026018
Change-Id: I2dd5a56842ae3823b200c16b575960b6c367ca20
2026-08-13 05:34:04 -07:00
Abseil Team 4f472747b1 Set GTEST_INTERNAL_HAS_STRING_VIEW = 1 in googletest as C++17 always supports it
PiperOrigin-RevId: 959873168
Change-Id: I66fc09077383f307c98a62f67a57005ce3c96502
2026-08-05 14:31:52 -07:00
Abseil Team 488c47cc68 Make string matchers work with std::wstring_view
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
2026-08-04 13:42:29 -07:00
Copybara-Service 136a6b8865 Merge pull request #4994 from edge90:fix/onceaction-tuple-sfinae-order
PiperOrigin-RevId: 953630264
Change-Id: Iad16b5ee9a92ccb6b580733be18dbeb85371e66d
2026-07-24 17:31:32 -07:00
Abseil Team 425811f10e Undo make string matchers work with std::wstring_view due to internal breakages
Reopens: #4912
PiperOrigin-RevId: 953470061
Change-Id: Ie979aa352f0ecbfb27dec5a41aae4b668cf7541b
2026-07-24 11:27:08 -07:00
Abseil Team fef8e5e23b Make string matchers work with std::wstring_view
Fixes: #4912
PiperOrigin-RevId: 953423131
Change-Id: Id288c01c9d1bd9c92ce78b89ec3e8587f4ffc2a7
2026-07-24 10:03:44 -07:00
Abseil Team fa005b296f Set up inlining for InvokeWithoutArgs when passed a functor.
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
2026-07-17 10:58:22 -07:00
Bogdan Graur a25f43576e Fixes -Wtautological-pointer-compare in gmock-matchers
PiperOrigin-RevId: 948667420
Change-Id: Ibb35d7e6469a193607a72f10377ef3a494f9525f
2026-07-15 18:51:05 -07:00
Mike Kruskal 7d012aa162 Fail smoothly for nullptr on c-style strings in IsEmpty
PiperOrigin-RevId: 944115454
Change-Id: I99284439b0c0e0acee1cb4e12f2d0b8d422c83ba
2026-07-07 15:11:54 -07:00
Copybara-Service cd975499e8 Merge pull request #5008 from K-S-Manikandan:fix/wide-string-isempty
PiperOrigin-RevId: 944044650
Change-Id: I9dcd6625f41f4f098439d222c26383150f7e8f6a
2026-07-07 12:49:50 -07:00
Manikandan K. S. df4fdc5cfd fix: add C-style wide string overload to IsEmpty matcher 2026-07-04 22:50:12 +05:30
Clayton Knittel 973323ed64 Delay name resolution by un-qualifying DynamicCastMessage calls from gMock.
Since we can't directly depend on proto headers, we rely on ADL + proto headers being included by calling code for this matcher to choose the right overload of `DynamicCastMessage`.

PiperOrigin-RevId: 940593408
Change-Id: I7374aed3c5cfe61a183d28ea02e6583ab340f647
2026-06-30 12:20:56 -07:00
Abseil Team 8b53336594 Automated Code Change
PiperOrigin-RevId: 936635684
Change-Id: I3b1bfa2ef921cdc3d0aaa1fc95986b64a9ad0282
2026-06-23 06:45:34 -07:00
Clayton Knittel 0b1e895ba4 Specialize testing::WhenDynamicCastTo for protobuf messages.
Protobuf messages have a custom dynamic_cast, for when RTTI is not available on the messages.

PiperOrigin-RevId: 933270097
Change-Id: Iaeb50bce3fe1b746306a7507ab1985b111c03416
2026-06-16 13:32:04 -07:00
Niclas Larsson b7ced159db Avoid is_constructible recursion in OnceAction
Both OnceAction compatibility traits, IsDirectlyCompatible and
IsCompatibleAfterIgnoringArguments, check std::is_constructible before
is_callable_r.

On libc++ that order breaks. Evaluating
is_constructible<std::tuple<OnceAction&&>, ...> drives libc++'s tuple
constructor SFINAE, which calls back into OnceAction's converting
constructor and re-enters the conjunction while it is still incomplete.
GCC <= 8 (e.g. QNX 7.1's gcc 8.3) rejects this with:

    incomplete type ... used in nested name specifier

so EXPECT_CALL(m, f()).WillOnce(Return(...)) fails to compile. GCC >= 9
and every Clang accept the original order; libstdc++ is unaffected.

Swapping the two checks fixes it: is_callable_r is cheap and
non-recursive, so the conjunction short-circuits to false for the
non-callable tuple before is_constructible is instantiated.

Fixes #3947.
2026-06-04 19:56:55 +02:00
Aaron Jacobs 8736d2cd5c gmock-spec-builders: support mocking const-qualified function types.
In particular this automatically gives us support for examples like the
following:

    using SomeFn = absl::AnyInvocable<R(Args...) const>;
    MockFunction<SomeFn> some_fn;

PiperOrigin-RevId: 921303527
Change-Id: I19bf59671781e85db65cc20c0d6ea10b056c528a
2026-05-26 01:30:54 -07:00
Abseil Team add971c7cb Introduce ContainsSubsequence matcher.
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
2026-05-20 02:39:49 -07:00
Abseil Team dc3c9eda2f Double the MOCK_METHOD parameter count limit to mitigate users running into it
PiperOrigin-RevId: 916092228
Change-Id: Ifb22a4583b3cf8e4b31a51a5f7373137c9e3b9f0
2026-05-15 11:11:10 -07:00
Abseil Team a35bc7693c Make gmock-matchers.h auto-detect the value_type of ranges that don't have a typedef for it based on the ranges' iterators
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
2026-03-05 10:09:30 -08:00
Abseil Team a407966592 Revert Optimize copying of matchers vector to speed up ElementsAreArray by reserving a std::vector copied via push_back.
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
2026-02-23 11:30:44 -08:00
Dillon Sharlet 73e0fc18eb Optimize copying of matchers vector to speed up ElementsAreArray by reserving a std::vector copied via push_back.
If the iterators are forward iterators, we can measure the size and reserve the vector, avoiding reallocations and copying.

PiperOrigin-RevId: 874129590
Change-Id: I6cdcaf38e28ac90c1cf596977b703d8de93994e5
2026-02-23 10:02:03 -08:00
Abseil Team e9907112b4 Update doc for Optional.
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
2026-02-20 07:10:28 -08:00
Abseil Team 77f6bd3e75 Update comment for SizeIs matcher.
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
2026-02-12 06:25:24 -08:00
Corentin Le Molgat ff6133ab49 cmake: Fix declspec of gtest flag when using BUILD_SHARED_LIBS=ON and absl
On windows flags declaration must be prepend by `GTEST_API_`
to have the correct declspec (dllexport or dllimport)

This patch also fix super build integration of googletest by adding the necessary `INSTALL_RPATH` and `$<BUILD_INTERFACE:` needed to be able to `FetchContent` or `add_subdirectory()` googletest in a user CMake project.

Fix #4718
related to abseil/abseil-cpp#1817

PiperOrigin-RevId: 854187933
Change-Id: I4341fdb7e88a51c5f9a1c72c58bcc8c4d6bfd1c5
2026-01-09 07:34:16 -08:00
Derek Mauro 7d7e750850 Fix "error: standard attributes in middle of decl-specifiers"
Between the friend declaration, visibility declaration, and
attribute placement rules, compilers can't seem to agree on the
how to write this, so I switched to a static factory function.

Fixes https://github.com/google/googletest/issues/4881

PiperOrigin-RevId: 852842303
Change-Id: I7fe737819abf05ea2911693f8d93683446e326cc
2026-01-06 10:37:35 -08:00
Chris Kennelly 065127f1e4 Add [[nodiscard]] throughput Google Test.
`EXPECT_THAT(foo, Matcher(bar))` can sometimes get accidentally written as a
no-op `foo, Matcher(bar)`, causing the code to be exercised but defeating the
purpose of testing.

PiperOrigin-RevId: 841880995
Change-Id: Ia55548e3dd83a6f44fff7b5433c8c8ecd7ecbe03
2025-12-08 12:55:11 -08:00
Derek Mauro 1b96fa13f5 Switch to referenceful lock holder for Abseil compatibility
PiperOrigin-RevId: 831156684
Change-Id: I8a8b017ec2fc318a65f57e04428c030c707ee682
2025-11-11 18:56:52 -08:00
Justin Bassett 17d335d7c7 Remove short-circuiting from AllOf, for better failure messages
For `EXPECT_THAT` matcher usage, showing only the first failure meant
that users would sometimes have to make a fix and run the test again
only to notice that there's another failure. It's better to show more
failures so that the user can fix several issues in one go.

In practice, very little code actually wants the short circuiting here,
only a handful of cases with custom matchers used like
`AllOf(BoundsCheck(), UncheckedAccess())`. These cases are fixable by
refactoring `UncheckedAccess()` to instead also apply a bounds check to
fail the matcher rather than crash. Notably, this change doesn't affect
`AnyOf`, so another workaround is to change `AllOf(m1, m2, ...)` into
`Not(AnyOf(Not(m1), Not(m2), ...))`.

PiperOrigin-RevId: 826316273
Change-Id: Ie8186f75c10443d8da35b5d07b6a8cd9ae85b451
2025-10-30 21:53:01 -07:00
Abseil Team b2b9072ecb Mark InternalDefaultActionSetAt as nodiscard.
PiperOrigin-RevId: 820207225
Change-Id: I8e053f724c18b466bd287f80a720542a535615d2
2025-10-16 06:31:44 -07:00
Abseil Team 2ce9d8f2e8 Allow for passing non-pointers to DeleteArg and have them emit a deprecation warning instead.
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
2025-10-13 06:51:01 -07:00
Derek Mauro 0934b7e112 Use an internal symbol for deprecate-and-inline that allows
the use of a deprecation message

PiperOrigin-RevId: 807753856
Change-Id: I34b0c7c6faf34cad11ea2aca5ccd16bca16acdec
2025-09-16 10:39:10 -07:00
Abseil Team 4969d0ad54 Automated Code Change
PiperOrigin-RevId: 806527439
Change-Id: I2e9aa5de44c011938e0bfc8e86af6c7d10c23ab0
2025-09-12 20:45:06 -07:00
Derek Mauro 9df216cc9d Update spelling of Mutex::lock and Mutex::unlock for compatibility
with the standard and the latest Abseil

PiperOrigin-RevId: 806260850
Change-Id: Ie973be4a3aaf7e174cd692ce6df7a82c8f261bf7
2025-09-12 06:17:43 -07:00
Abseil Team 6986c2b575 Internal header include changes.
PiperOrigin-RevId: 797151958
Change-Id: I26ce36684e8822cd76723e664782764cf222152c
2025-08-19 22:05:22 -07:00
Abseil Team a05c091507 Deprecate single-argument DoAll and Invoke.
PiperOrigin-RevId: 795969677
Change-Id: I56d88ec715475d91fb527a9281bc62574fb4608b
2025-08-16 20:08:07 -07:00
Abseil Team 175c1b55cf Add UnpackStructImpl for structs with 24, 25 and 26 fields.
PiperOrigin-RevId: 770690821
Change-Id: Ic759e29f46a34d0f2c0ef831e0ddc784290a938f
2025-06-12 09:37:31 -07:00
Abseil Team 6230d316e1 In MatcherCast, store the input value as its own type rather than as the Matcher type, to avoid dangling references
PiperOrigin-RevId: 769240838
Change-Id: I7b1ac23a0a88ba90b5d1ae6e20b97f679f381f31
2025-06-09 12:07:01 -07:00
Abseil Team bac6a8fd8a Add UnpackStructImpl specialization for 23 struct members.
PiperOrigin-RevId: 760700889
Change-Id: I52ea2bc83d218f73504c9dfba82ce0c07e59cbb2
2025-05-19 11:21:57 -07:00
Abseil Team cd430b47a5 AllOf, AnyOf, Optional: Avoid generating unnecessary match explanations
Previously, those matchers always invoked the child matchers with an IsInterested MatchResultListener, resulting in unnecessary work formatting match results that would be discarded.

PiperOrigin-RevId: 750704295
Change-Id: I1639a3a15d269459f26b3aebc3a6cbdced6896a3
2025-04-23 13:29:56 -07:00
Aaron Jacobs e90fe24856 gmock-actions: add a missing conversion operator to WithArgsAction.
PiperOrigin-RevId: 745802500
Change-Id: I8cf7b69f89af8615e9c405b1e6552d3e12ebf93d
2025-04-09 17:57:30 -07:00
Aaron Jacobs 50a9511f50 gmock-actions: run clang-format.
PiperOrigin-RevId: 745757973
Change-Id: I59ca0098a73eaf8a7e68016ba003fc2447e1c702
2025-04-09 15:33:40 -07:00
Abseil Team 2ae29b52fd Add UnpackStructImpl for structs with 22 fields.
PiperOrigin-RevId: 739148442
Change-Id: Iae29066daddeea8384f3eb06ff075299156e9579
2025-03-21 05:44:56 -07:00
Abseil Team e7b26b7246 Add a non-'const' overload for the function invoked by the IgnoreArgs action wrapper.
PiperOrigin-RevId: 738865907
Change-Id: Ia43b297692ddca681bf29fa7547a5a4da330e51a
2025-03-20 10:56:05 -07:00
Zhanyong Wan 3af834740f Improve the failure messages of ElementsAre(), ElementsAreArray(), etc.
NOTE: if you suspect that this change breaks your build, it's likely that your tests depend on the exact messages of `ElementsAre()` and friends. The messages are implementation details of these matcher and are subject to change without notice. Depending on the messages is not supported. In that case, please rewrite your tests to avoid the dependency.

When the array being matched is long, it can be hard for the user to find the mismatched element in the message generated by `ElementsAre()` or `ElementsAreArray()` - even though these matchers print the index of the mismatched element, the user still has to count to find the actual element and its corresponding matcher.

With this change, these matchers will include the actual value and corresponding matcher in the failure message, making it easier for the user.

Also make a small style improvement: now it's advised to write
```
EXPECT_EQ(actual, expected);
```
as opposed to
```
EXPECT_EQ(expected, actual);
```

PiperOrigin-RevId: 738039133
Change-Id: I3b94f7d01a6a4c92e2daf268df8cfb04a21d4294
2025-03-18 09:42:12 -07:00