1105 Commits

Author SHA1 Message Date
Abseil Team
ecb18f0b03 Automated Code Change
PiperOrigin-RevId: 955003621
Change-Id: I83518a7f947d9f7d9b89fe14e1219d32bcdc95a3
2026-07-27 21:17:32 -07:00
Abseil Team
b78aa5ee64 Automated Code Change
PiperOrigin-RevId: 953750672
Change-Id: I9314622e998cb9d17eec0dc1baeb6d8bc8a801fd
2026-07-24 23:56:31 -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
Copybara-Service
d4e2591485 Merge pull request #5033 from UditDewan:fix/absolute-install-includedir
PiperOrigin-RevId: 953333932
Change-Id: I1f3dfb118bb2a7e3b4ae64fcc4206baf4c8e7f4b
2026-07-24 06:25:48 -07:00
Mike Kruskal
30a3151b0c Fix broken tests due to deprecation warning
PiperOrigin-RevId: 951523081
Change-Id: I145c6066a202629e5d0c89453d726495dd535290
2026-07-21 09:06:28 -07:00
uditDewan
fcd5e26089 Fix exported include paths for absolute CMAKE_INSTALL_INCLUDEDIR
The INSTALL_INTERFACE include directory was written as
$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}, which unconditionally
prepends the install prefix. When CMAKE_INSTALL_INCLUDEDIR is an
absolute path, the exported GTestTargets.cmake ends up with an invalid
doubled path such as "/usr/local//usr/local/include", and find_package
consumers fail at configure time with "Imported target includes
non-existent path".

Relative paths inside $<INSTALL_INTERFACE:...> are already interpreted
relative to the installation prefix, so the explicit $<INSTALL_PREFIX>/
prefix is redundant for relative values and wrong for absolute ones.
Dropping it keeps the exported path identical for relative values
(${_IMPORT_PREFIX}/include) and uses absolute values as-is.

Fixes #4817
2026-07-18 14:59:31 -04: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
Abseil Team
aa40ee603e Automated Code Change
PiperOrigin-RevId: 936616624
Change-Id: I3a05afadf807fc372337186c26b5d73a2bc21410
2026-06-23 06:03:11 -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
2461743991 Automated Code Change
PiperOrigin-RevId: 890778982
Change-Id: Idef51b737a250560d0b71130e6e87b6249d8c47a
2026-03-27 21:30:37 -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
Derek Mauro
5a9c3f9e8d Upgrade most builds to use Bazel 9.0.0
Keep one build on 8.5.1 to test WORKSPACE

Fixes the -Wdeprecated-declaration warnings
enabled by default in Bazel 9 that come from the
single-arg Invoke().

Fixes the new -Winconsistent-missing-override that
we intentionally use in a test.

Upgrades RE2 to a version compatible with Bazel 9.

PiperOrigin-RevId: 865966282
Change-Id: I5f7c3b60daf5f8a90be08004d96aaa59611e35c4
2026-02-05 08:42:50 -08:00
Abseil Team
56efe39831 Allow implicit matcher construction from nullptr. This allows "nullptr" to be used as a valid matcher for smart pointer types.
PiperOrigin-RevId: 861759501
Change-Id: I09ff55cd532014015725ec61356f480760819b29
2026-01-27 09:35:08 -08:00
Abseil Team
85087857ad Automated Code Change
PiperOrigin-RevId: 857421343
Change-Id: I6b64c34c1b0ccd31ec5277fbbdcc6c0e800e6241
2026-01-16 21:50:57 -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
e17e37a115 Automated Code Change
PiperOrigin-RevId: 820039898
Change-Id: I910d8ec41198794e7344a2d79566a19243532251
2025-10-15 21:01:54 -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
50b8600c63 Add rules_cc dependency, required by Bazel going forward
This also adds the dependencies of rules_cc to WORKSPACE.
bzlmod automatically pulls in dependencies.
skylib is removed as it is pulled in by a deps function.

PiperOrigin-RevId: 808659470
Change-Id: Idc41cad7b05019793d4a1898bdb80bc4797da5cf
2025-09-18 11:16:02 -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
fd15f51d57 Automated Code Change
PiperOrigin-RevId: 769938700
Change-Id: I3f36d03a5d54f1f2fbeda9fbaa5e205736c3cdbc
2025-06-10 21:03:35 -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
7e2c425db2 Remove "blindly" from the gmock "uninteresting call" message.
PiperOrigin-RevId: 767766090
Change-Id: I9202c1c24a3af8d73806f68ca93025b26704178e
2025-06-05 14:31:20 -07:00
qubka
3abc68be30 Fix extra ';' after member function definition 2025-05-25 11:09:39 +01: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