Commit Graph

393 Commits

Author SHA1 Message Date
Derek Mauro
3656c2713e Fix redundant redeclaration warning
Fixes #4200

PiperOrigin-RevId: 520017094
Change-Id: Id707a1c0489edde083771ccd412d7035612474dc
2023-03-28 07:03:07 -07:00
Abseil Team
e9faae170f Internal Code Change
PiperOrigin-RevId: 518213370
Change-Id: I88d0acc195dadf8d03cd15c8534c721141db14ea
2023-03-21 02:36:37 -07:00
Abseil Team
391ce627de Internal Code Change
PiperOrigin-RevId: 515855852
Change-Id: I8016eefd45c36089e189bbd1ebbe9fdabe68255b
2023-03-11 02:48:36 -08:00
Lawrence Wolf-Sonkin
038e392ebd [gtest] Drop custom-rolled heterogeneous comparator functors in favor of C++ standard ones
* Standard heterogeneous comparator functors such as `std::equal_to<>` and `std::less<>` [have been available since C++14](https://en.cppreference.com/w/cpp/utility/functional/less_void)
* Now that [C++14 is the minimum supported version of C++ in Googletest](https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md), let's delete these duplications of the standard library

PiperOrigin-RevId: 515743068
Change-Id: I1563a2f94039c3a6688429298555545a922f6d7e
2023-03-10 14:43:13 -08:00
Abseil Team
1a727c27aa Internal Code Change
PiperOrigin-RevId: 514678702
Change-Id: I5b0089d905152ccb85022be395ed340e42586234
2023-03-07 03:06:06 -08:00
Tom Hughes
23142843f7 Use "#ifdef GTEST_OS_..." instead of "#if GTEST_OS_..."
This is compatible with compiling with "-Wundef" (#3267).

PiperOrigin-RevId: 513943378
Change-Id: I47cf5fabbb77be061c4483a0adc54511af6b191c
2023-03-06 07:14:21 -08:00
Martijn Vels
ee33b34bec Fix GTEST_HAS_ABSL define check for [-Werror=undef] compilations
PiperOrigin-RevId: 507788664
Change-Id: Ib8cfbf3102a38e210fdae8a548fd84f0723ccc10
2023-02-07 08:28:15 -08:00
Tom Hughes
4fb7039fda Use GTEST_DISABLE_MSC_WARNINGS macros to disable warnings
Prior to this change we had a mixture of pragmas and
GTEST_DISABLE_MSC_WARNINGS; this change consolidates all instances
to use the macros.

PiperOrigin-RevId: 505786926
Change-Id: I2be8f6304387393995081af42ed32c2ad1bba5a7
2023-01-30 13:45:46 -08:00
Tom Hughes
2491710524 Fix formatting of C++ files
PiperOrigin-RevId: 504325204
Change-Id: Iaa1d6d0ab1dccaaeef26f9cb109d530835499240
2023-01-24 11:10:09 -08:00
Tom Hughes
e5e46b09a1 IWYU: Add missing std includes
PiperOrigin-RevId: 499893032
Change-Id: I33304802b7c82ae2d008f3ee89df38866e5f57ba
2023-01-05 08:44:01 -08:00
Abseil Team
3fa7f983c6 Shut up a Clang warning.
Clang warns on this pattern because it looks like the author might
have meant to use the value of the first part of the comma operator,
so it warns that it isn't being used. The cast here signals to Clang
that this behavior is intentional.

This was discovered while updating gmock in Android. Clang's -Wcomma
warning is on by default with either -Wall or -Werror, so users of
gmock with those on in combination with -Werror are unable to build
without this fix.

PiperOrigin-RevId: 495655990
Change-Id: Iaf27e2199669f5b6185a877738234e551b6b6556
2022-12-15 11:50:51 -08:00
Abseil Team
ad54e90f57 Refactor matrix verification into VerifyMatchMatrix.
PiperOrigin-RevId: 494786543
Change-Id: I7769558dd2ca046d8957bf352dc04cfb48ff7c3a
2022-12-12 11:51:48 -08:00
Abseil Team
1f643f71d4 Make SizeIsMatcher::Impl conform to the contract of MatcherDescriberInterface.
MatcherDescriberInterface specifies that DescribeTo "should print a verb phrase", but "size ..." is not a verb phrase. Currently, ElementsAre(SizeIs(9)) is described as "has 1 element that size is equal to 9". With this change, it will be described as "has 1 element that has a size that is equal to 9".

PiperOrigin-RevId: 492022324
Change-Id: I4083335f2419462464957521c1e033643b53b763
2022-11-30 14:42:31 -08:00
Abseil Team
a16bfcfda1 Disables -Wunused-member-function and -Wused-but-marked-unused that trigger via MOCK_METHOD() and EXPECT_THAT() macros.
Fixes: #4052, #4055
PiperOrigin-RevId: 491647393
Change-Id: I8e2ad838156fa8c7e9dccd1740af797e694992b6
2022-11-29 08:44:15 -08:00
Abseil Team
6b63c98ac4 Remove incorrect GTEST_ATTRIBUTE_UNUSED_ from InSequence class.
Fixes: #4048
PiperOrigin-RevId: 486951561
Change-Id: I4fae101b5ac5ed4f46c32aba8c36519e1f784db1
2022-11-08 07:58:14 -08:00
Copybara-Service
3026483ae5 Merge pull request #4041 from zloylos:allow-naming-expectations
PiperOrigin-RevId: 483683590
Change-Id: Id22de3a22018324e5c1e21e262ac5e027a83bf3e
2022-10-25 08:39:19 -07:00
Denis Hananein
09e1c64f86 Fix format without expectation name
Signed-off-by: Denis Hananein <i@zloylos.me>
2022-10-21 15:37:38 +02:00
Denis Hananein
0d26378919 Change messages
Signed-off-by: Denis Hananein <i@zloylos.me>
2022-10-21 14:03:45 +02:00
Denis Hananein
f3eb2b7e38 Allow naming expectations #3970
Signed-off-by: Denis Hananein <i@zloylos.me>
2022-10-20 23:13:06 +02:00
Abseil Team
d29b143bda Workaround for Visual C++ error C2039 with std::tuple_element_t.
Fixes #3931

PiperOrigin-RevId: 480659507
Change-Id: I6fabef63b1285189a06375227273d9de2456e37a
2022-10-12 10:31:07 -07:00
Abseil Team
0f6885405c Remove obsolete MSVC warning pragmas for Invalid<T>()
Remove the MSVC pragmas for disabling warning C4717 (infinite recursion) for
Invalid<T>() because that warning has been fixed in cl/441474979.

PiperOrigin-RevId: 473012585
Change-Id: I5f1bf88379bd4f2bf005e029c04766ac4caadd84
2022-09-08 09:42:31 -07:00
Abseil Team
0e0d9feefa Fixed header guards to match style guide conventions.
PiperOrigin-RevId: 471524660
Change-Id: Ie11e6a7a5a5497f64d5b9c382f1017094e043093
2022-09-01 07:25:03 -07:00
Hardik Vala
25cc5777a1 Add support of 19-member structs to gmock UnpackStructImpl.
PiperOrigin-RevId: 469171380
Change-Id: Ic75fc0523924e40e620552d4c04b79dad22a68e0
2022-08-22 06:42:57 -07:00
Copybara-Service
6045bf2ade Merge pull request #3918 from assafpr:master2main
PiperOrigin-RevId: 464586117
Change-Id: Icda62f13b962f7408bb5698ae2b627391257d152
2022-08-01 11:47:51 -07:00
Abseil Team
dd7a9d29a3 Add support of 18-member structs to gmock UnpackStructImpl.
PiperOrigin-RevId: 463961734
Change-Id: Ib62e320a745c190955f181c1f4f12e4cd407ef22
2022-07-28 17:15:30 -07:00
Dino Radakovic
b1e9b6323a Add IsEmpty overload for C-style strings
Fixes #3937

PiperOrigin-RevId: 463180144
Change-Id: I21b528acc4c3f3aba4234642be01fcead7fe7f00
2022-07-25 14:38:26 -07:00
Abseil Team
d9335595b4 Add support of 17-member structs to gmock UnpackStructImpl.
PiperOrigin-RevId: 458018249
Change-Id: I7df8f75ef5b5a6478e7301f959c221810ff9f0b3
2022-06-29 11:10:54 -07:00
assafpr
d0af91ead3
Update gmock-matchers.h
branch master changed to main on link
2022-06-27 09:56:59 +03:00
assafpr
1547c2acc8
Update gmock-actions.h
master branch changed to main in links
2022-06-27 09:55:28 +03:00
Derek Mauro
0320f517fd Work around a maybe-uninitialized warning under GCC 12
Some Mock constructors insert the pointer to the Mock itself into a
global registry. Since GCC cannot see how the pointer is used (only as
an identifier), it cannot tell that the object doesn't need to be
initialized at that point at all. Work around this by using uintptr_t
instead.

PiperOrigin-RevId: 452380347
Change-Id: Ia5a493057ed90719de1d0efab71de9a8a08ddf8b
2022-06-01 14:08:04 -07:00
Aaron Jacobs
e649993a40 gmock-spec-builders: remove the name for an unused parameter.
This fixes unused parameter errors under both MSVC and clang (when
`-Werror=unused-parameter` is used, as reported
[here](9d21db9e0a (r74769946))).

Fixes #3858

PiperOrigin-RevId: 451907906
Change-Id: Ic07da19ea6a547eb1797fbbab19cd57cc2a83fe8
2022-05-30 12:46:59 -07:00
Aaron Jacobs
9d21db9e0a gmock-spec-builders: add support for non-moveable types.
Do this by ripping out the "untyped perform action" machinery, which isn't
necessary: we can simply template the entry point on the result type, and use
RAII to avoid the need to special case void. This makes it easier to understand
the code and harder to introduce type-related undefined behavior, to boot.
PiperOrigin-RevId: 451493451
Change-Id: I225305f83164752ca92f2916721972eafba33168
2022-05-27 15:25:37 -07:00
Aaron Jacobs
28356773cb gmock-actions: properly support non-moveable results in is_callable_r.
Previously this excluded callables that return non-moveable types. This is the
same as the
[libc++ std::is_invocable_r bug](https://github.com/llvm/llvm-project/issues/55346)
fixed by
[this commit](https://github.com/llvm/llvm-project/commit/c3a24882903d): it's
wrong to use std::is_convertible for checking the return type, since (despite
its name) that doesn't check the standard-defined notion of "implicitly
convertible". Instead we must base the check on whether the source type can be
used as an argument to a function that accepts the destination type.

PiperOrigin-RevId: 451341205
Change-Id: I2530051312a0361ea7a2ce26993ae973c9242089
2022-05-27 02:23:49 -07:00
Aaron Jacobs
56246cdb94 gmock-spec-builders: move a method to the header.
In order to make the diff more readable in an upcoming commit that requires the
method to be templated on the action's result type.

PiperOrigin-RevId: 451157029
Change-Id: I57beb7544efccd0459efb3a1f039ea45cd7c7602
2022-05-26 07:25:17 -07:00
Aaron Jacobs
5126f71661 gmock-actions: add support for move-only values to Return.
`Return(x)` can now be used directly with `WillOnce` (the only place it makes
sense in the type system), without using `ByMove`.

PiperOrigin-RevId: 448380066
Change-Id: Ia71cc60ccbc3b99720662731a2d309735a5ce7c8
2022-05-12 17:55:11 -07:00
Aaron Jacobs
cbca6bc395 gmock-actions: provide a const reference when converting in ReturnAction.
It doesn't make semantic sense for the conversion to modify the input, and the
fact that it's allowed to do so appears to have just been a historical accident.

PiperOrigin-RevId: 448135555
Change-Id: Id10f17af38cf3947ee25fe10654d97527173ebfc
2022-05-11 19:01:15 -07:00
Aaron Jacobs
4224c770a3 gmock-actions: simplify Return and add better documentation.
Better document requirements, API decisions, and historical accidents. Make an
implicit conversion easier and in a more appropriate place, and ease the burden
of some assertions in the conversion operator. Stop using the legacy
ActionInterface style for defining the action.

PiperOrigin-RevId: 447894892
Change-Id: I179e23ec2abdd9bf05c204ab18dbb492f1372e8e
2022-05-10 20:41:04 -07:00
Aaron Jacobs
6386897feb gmock-actions: make OnceAction public.
So that it can be referenced in conversion operators for actions that need to
know the concrete return type.

PiperOrigin-RevId: 447889344
Change-Id: I643d3298bc8effd08741282a956c221f9d67d378
2022-05-10 20:08:51 -07:00
Abseil Team
2a02723b76 Fix example of DescribeMatcher to properly support negation.
PiperOrigin-RevId: 446259163
Change-Id: I3ad5f405f44fc233f5cf5a18a274a9104b5c4ab8
2022-05-03 12:18:27 -07:00
Aaron Jacobs
42ca3da579 gmock-actions: remove a no-longer-necessary friend declaration.
PiperOrigin-RevId: 445940487
Change-Id: I26952a72327db0d308bbe57ca4d1d91a0d7defc8
2022-05-02 08:37:49 -07:00
Aaron Jacobs
5176726123 gmock-actions: support ByMove in a specialization of ReturnAction.
Rather than branching on whether the return type is ByMoveWrapper within
ReturnAction itself, hoist the distinction to outside. This allows the main
class template to be modified without worrying about this special case, which
means we can stop using a shared pointer to the value (introduced as a
linked_ptr in commit 3d1c78b2bf to support ByMove) in this commit and simplify
the class template further in a future commit with the eventual aim of directly
supporting move-only result types.

PiperOrigin-RevId: 445938943
Change-Id: I7bc71ea301d5e493ac6ecbe57d62738a48a2721a
2022-05-02 08:30:07 -07:00
Aaron Jacobs
830fb56728 gmock-actions: improve comments and tests for the implicit cast in Return.
Commit a070cbd91c added an implicit cast to this path but didn't leave a very
clear explanation for why it was desirable, a clear example, or even test
coverage. Add a better comment and a test that fails when the implicit cast is
removed.

PiperOrigin-RevId: 444871311
Change-Id: I127982fa8d5bce9b6d1b68177c12dc0709449164
2022-04-27 08:49:18 -07:00
Aaron Jacobs
c144d78f82 Support move-only and &&-qualified actions in WithArgs.
PiperOrigin-RevId: 444671005
Change-Id: I7df5f038caf17afb60d4fb35434ff0b656d4c954
2022-04-26 14:39:37 -07:00
Aaron Jacobs
0498660ea5 Support move-only and &&-qualified actions in DoAll.
This is necessary for generic support of these actions, since `DoAll` is a
frequently-used action wrapper.

PiperOrigin-RevId: 444561964
Change-Id: I02edb55e35ab4207fbd71e371255a319c8253136
2022-04-26 08:05:34 -07:00
Derek Mauro
bf66935e07 Remove the legacy internal GTEST_DISALLOW_* macros
PiperOrigin-RevId: 443715444
Change-Id: I3ffd54b63d2728ae4a668ee7875c8c3c8188087c
2022-04-22 11:26:03 -07:00
Derek Mauro
b85864c647 Eliminate the legacy GTEST_COMPILE_ASSERT_ macro
PiperOrigin-RevId: 443462203
Change-Id: I0c43f981663a7531ff5da4d4be01fb3d6762273d
2022-04-21 13:23:32 -07:00
Aaron Jacobs
80600e56cc Document two surprises in DoAllAction::NonFinalType.
PiperOrigin-RevId: 441589196
Change-Id: Ic3e483ca70d72261046bad464d817f9dfd4bec65
2022-04-13 15:04:29 -07:00
Abseil Team
733f875989 Replace infinite recursion call (intentionally invoking undefined behavior to indicate unreachability) with explicit unreachability marker.
PiperOrigin-RevId: 441474979
Change-Id: I1fcbb437026631212fec954c663482bb7e1cf819
2022-04-13 07:28:00 -07:00
Abseil Team
a1cc8c5519 Add support for move-only and &&-qualified actions in WillOnce.
This provides a type-safe way for an action to express that it wants to be
called only once, or to capture move-only objects. It is a generalization of
the type system-evading hack in ByMove, with the improvement that it works for
_any_ action (including user-defined ones), and correctly expresses that the
action can only be used with WillOnce. I'll make existing actions benefit in a
future commit.

PiperOrigin-RevId: 440496139
Change-Id: I4145d191cca5655995ef41360bb126c123cb41d3
2022-04-08 18:40:07 -07:00
Abseil Team
137f67e91f gmock: improve SFINAE for actions involving arguments.
Avoid instantiating functions like std::get<index> for an out of range index
when doing SFINAE on the invocability of the action itself.

PiperOrigin-RevId: 439415110
Change-Id: Ifc20285a6d526c34830870cd1910c2b2b92e1e81
2022-04-04 14:38:58 -07:00