4501 Commits

Author SHA1 Message Date
Abseil Team
e9092b12dc Fix unified diff headers.
The length part (only) of each range is optional when equal to one.
See http://www.gnu.org/software/diffutils/manual/html_node/Detailed-Unified.html

PiperOrigin-RevId: 765326445
Change-Id: I4aec68e82f889e3b4f01861d3b6a16a8b2785ce6
2025-05-30 13:58:42 -07:00
Abseil Team
7427a6b5e3 Use the provided length in ConditionalPrintAsText
While ConditionalPrintAsText gets a char pointer and the string length, it used to only pass the pointer to operator<<. That does not work for strings that are not zero terminated, because operator<< has to resort to strlen, which happily overflows the string buffer.

This CL wraps the char pointer and the length in a string_view and passes that to operator<< to fix that issue.

PiperOrigin-RevId: 765137769
Change-Id: Ie97067ce9d5b23175a512945fee943a8b95a94ff
2025-05-30 04:47:12 -07:00
Copybara-Service
7da55820cc Merge pull request #4765 from qubka:main
PiperOrigin-RevId: 763814429
Change-Id: Id80dc3c910aa955fda6b9ece1aee17032e28130d
2025-05-27 08:56:42 -07:00
qubka
3abc68be30 Fix extra ';' after member function definition 2025-05-25 11:09:39 +01:00
Abseil Team
09ffd00153 Updates Google Analytics tracker.
PiperOrigin-RevId: 762080294
Change-Id: Id874316dc6360e889f54fa631b56c8c6c783cc7a
2025-05-22 12:37:05 -07:00
Daniel Cheng
6aa03e6774 Print std::basic_string_view<Char> as a string literal
This is a followup to a previous change switching std::u8string,
std::u16string, and std::u32string to print as string literals instead
of an array of characters. Also update the PrintCharsAsStringTo<Char>()
helper to handle cases where the pointer to the string data is null;
unlike std::basic_string<Char>, std::basic_string_view<Char>'s data()
is allowed to return nullptr.

The new PrintTo overloads complicate the PrintTo(internal::StringView)
overload, which needs to be disabled if internal::StringView is an alias
for std::string_view to avoid multiple definitions with the same
overload. Simply omitting the unconditional PrintTo(std::string_view)
overload is a worse option though, as this results in std::string_view
not printing nicely if internal::StringView is not an alias for
std::string_view.
PiperOrigin-RevId: 762020327
Change-Id: I92f5bdbacba89e97bbcc0fef3ca9261ea5a788d3
2025-05-22 10:21:59 -07:00
Derek Mauro
16d4f8eff6 Delete the absl polyfill support for std::any, std::optional
and std::variant now that the absl types are aliases of the
std types

PiperOrigin-RevId: 761136061
Change-Id: I702c3e1e8c58d003b8f4da99e7c84c9e5dbe1863
2025-05-20 10:25:35 -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
fa8438ae6b Use static_cast instead of ImplicitCast_ for character conversions
Clang has recently added "warnings when mixing different charN_t types" [1].
The rationale is that "charN_t represent code units of different UTF encodings.
Therefore the values of 2 different charN_t objects do not represent the same
characters."

Note that the warning here may be legitimate - from https://github.com/google/googletest/issues/4762:
"[...] This is incorrect for values that do not represent valid codepoints."

For the time being, silence the warning by being more explicit about the
conversion being intentional by using static_cast.

Link: https://github.com/llvm/llvm-project/pull/138708 [1]
PiperOrigin-RevId: 760644157
Change-Id: I2e6cc1871975455cecac8731b2f93fd5beeaf0e1
2025-05-19 09:02:31 -07:00
Derek Mauro
571930618f GoogleTest CI Update
* Use abseil-cpp@20250512.0, which requires C++17 and
 removes any/optional/variant polyfills
* Test C++23
* Support/test GCC15
* Use Bazel vendor mode to reduce reliance on GitHub

PiperOrigin-RevId: 759184924
Change-Id: Ifb866cdd7faf1e5be475b44f69870745e21a3104
2025-05-15 09:42:50 -07:00
Mike Kruskal
9f79a9597a Add [[nodiscard]] to GetParam() to prevent accidental misuse.
This helps avoid a situation where someone sets up a parameterized test but forgets to actually use the parameter.

PiperOrigin-RevId: 758455362
Change-Id: Ie4db03e82b6a4e1787be96f154b3fbb25657ae64
2025-05-13 18:26:40 -07:00
Abseil Team
8b8ef3ff0d Clarify that the return value of InvokeArgument is not the return value of the action.
PiperOrigin-RevId: 757918204
Change-Id: I3f3544ca602a3863c3bae67b8fb4c57e692f3373
2025-05-12 14:40:55 -07:00
Abseil Team
90a4152114 gtest: Remove incorrect documentation of private headers as PIMPL idiom
PiperOrigin-RevId: 753626014
Change-Id: I3ef90e13b08d5a22d3b220a4e8fbb78df92deb0a
2025-05-01 09:50:38 -07:00
Derek Mauro
04ee1b4f2a Update documentation for v1.17.0
PiperOrigin-RevId: 753214894
Change-Id: I5ec24399301dcc7e70b179db98e175f45374e3c2
2025-04-30 10:11:59 -07:00
Derek Mauro
54915d462b Update GoogleTest dependencies in preparation for release
PiperOrigin-RevId: 753143607
Change-Id: I3dadd610342d86e3c856327e446e956fab8abf04
2025-04-30 06:31:27 -07:00
Laramie Leavitt
59c924bc47 Use std::memcpy instead of a union to access floating point bits.
PiperOrigin-RevId: 752789717
Change-Id: I20d17677bc75d12fa50328feb2bdc5c25e852cc4
2025-04-29 10:26:44 -07:00
Derek Mauro
00b2154e8e Fix GCC15 warning that <ciso646> is deprecated in C++17
PiperOrigin-RevId: 752706554
Change-Id: I83d35b693efdaabcc63d15169dbf19d63163a563
2025-04-29 06:13:25 -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
Derek Mauro
155b337c93 Bump RE2 dependency to 2024-07-02.bcr.1
Mirrors the change from https://github.com/bazelbuild/bazel-central-registry/pull/4342

PiperOrigin-RevId: 748665684
Change-Id: I775ff08130046ad7a2dd288e1a58e007e407acd3
2025-04-17 06:50:43 -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
Andy Getzendanner
52204f78f9 Remove obsolete references to LinuxThreads.
PiperOrigin-RevId: 740860675
Change-Id: I73bf9fd36e6135eb7577da54254254df7eebdf7b
2025-03-26 12:20:16 -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
Tommy Chiang
c2ceb2b09b Fix a typo
I have no idea what DLP here means, but ULP make sense.
Assuming DLP is a typo of ULP.

PiperOrigin-RevId: 739113596
Change-Id: Ib8c66d54d95e3b015c79af1285b7008c91b8502e
2025-03-21 03:04:11 -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
Zhanyong Wan
4902ea2d7c Clarify the polymorphic matcher concept and explain how to define a composite matcher.
Many gtest users aren't aware that a polymorphic matcher is not actually a `testing::Matcher<>` and thus doesn't know how to describe itself. Clarify this.

Also adds a recipe on how to define a composite matcher. In particular, explain how the composite matcher can describe itself in terms of the description(s) of its sub-matcher(s).

PiperOrigin-RevId: 735840759
Change-Id: I26cff6179349aa739fc7fdd528a2f5308d18c189
2025-03-11 12:04:28 -07:00
Zhanyong Wan
4ee4b17bf5 Allow DistanceFrom() to use user-defined abs() by default.
`std::abs()` doesn't work on custom types. While one can use the 3-argument version of `DistanceFrom()` to specify how to compute the distance, it's not as convenient as defining `abs()` for the custom type once in the type's namespace and then use the 2-argument version.

PiperOrigin-RevId: 735741409
Change-Id: If8fb668455eb963a2ccf089f7467c64965a2e7a6
2025-03-11 06:58:43 -07:00
Zhanyong Wan
0bdccf4aa2 Add a DistanceFrom() matcher for general distance comparison.
We have a bunch of matchers for asserting that a value is near the target value, e.g.
`DoubleNear()` and `FloatNear()`. These matchers only work for specific types (`double` and `float`). They are not flexible enough to support other types that have the notion of a "distance" (e.g. N-dimensional points and vectors, which are commonly used in ML).

In this diff, we generalize the idea to a `DistanceFrom(target, get_distance, m)` matcher that works on arbitrary types that have the "distance" concept (the `get_distance` argument is optional and can be omitted for types that support `-`, and `std::abs()`). What it does:

1. compute the distance between the value and the target using `get_distance(value, target)`; if `get_distance` is omitted, compute the distance as `std::abs(value - target)`.
2. match the distance against matcher `m`; if the match succeeds, the `DistanceFrom()` match succeeds.

Examples:

```
  // 0.5's distance from 0.6 should be <= 0.2.
  EXPECT_THAT(0.5, DistanceFrom(0.6, Le(0.2)));

  Vector2D v1(3.0, 4.0), v2(3.2, 6.0);
  // v1's distance from v2, as computed by EuclideanDistance(v1, v2),
  // should be >= 1.0.
  EXPECT_THAT(v1, DistanceFrom(v2, EuclideanDistance, Ge(1.0)));
```

PiperOrigin-RevId: 734593292
Change-Id: Id6bb7074dc4aa4d8abd78b57ad2426637e590de5
2025-03-07 09:54:00 -08:00
Abseil Team
e88cb95b92 Add a testing::ConvertGenerator overload that accepts a converting functor. This allows the use of classes that do not have a converting ctor to the desired type.
PiperOrigin-RevId: 733383835
Change-Id: I6fbf79db0509b3d4fe8305a83ed47fceaa820e47
2025-03-04 10:40:25 -08:00
Derek Mauro
24a9e940d4 Try to warn the user when test filters do not match any tests
PiperOrigin-RevId: 732204780
Change-Id: I2c4ccabd123e3b79c3dd8bc768a4cd9a576d282c
2025-02-28 11:36:13 -08:00
pizzud
72189081ca googletest: Add testonly alias of :gtest for testonly cc_libraries to use.
While a testonly library can certainly depend on a non-testonly library, gtest
itself is logically testonly, but is not tagged as such for historical
reasons. Having a testonly target allows gradual migrations towards a
testonly-only world.

PiperOrigin-RevId: 731807655
Change-Id: Ie16f17fb74b80bb6200767a3ac5bafa424162146
2025-02-27 11:49:14 -08:00
Abseil Team
144d335538 Add UnpackStructImpl for structs with 21 fields.
PiperOrigin-RevId: 731737844
Change-Id: I3efeb26b0bf179958c8a3eda0b55dfc3d7778fb9
2025-02-27 08:36:00 -08:00
Derek Mauro
e5669fdffc Output to the test warning file if no tests are linked.
Bazel sets the environment variable TEST_WARNINGS_OUTPUT_FILE
https://bazel.build/reference/test-encyclopedia#initial-conditions

If no tests are linked and the new flag --gtest_fail_if_no_test_linked
is not true (which is the current default), we can still warn the user
as this may be a programming error without failing the test (which would
break existing users).

PiperOrigin-RevId: 731402363
Change-Id: Ia481689efd4bd18889feaaa38bc56049a3f651cd
2025-02-26 11:57:12 -08:00
Zhanyong Wan
54501746a6 Adds support for a --gtest_fail_if_no_test_linked flag
to fail the test program if no test case is linked in
(a common programmer mistake).

PiperOrigin-RevId: 730571311
Change-Id: I1dab04adfe35581274d0b4ec79a017014d50e1ea
2025-02-24 13:18:33 -08:00
Derek Mauro
3fbe4db9a3 GoogleTest C++17 cleanups
* Use `[[nodiscard]]` instead of GTEST_MUST_USE_RESULT_
  * Use `[[maybe_unused]]` instead of  GTEST_INTERNAL_ATTRIBUTE_MAYBE_UNUSED
  * Use `[[deprecated]]` instead of `GTEST_INTERNAL_DEPRECATED`
  * Remove `GTEST_INTERNAL_NEED_REDUNDANT_CONSTEXPR_DECL`

PiperOrigin-RevId: 729523519
Change-Id: Ia1b901cf9c0a0e148eec419ada0e0b56aba2dd3d
2025-02-21 07:33:55 -08:00
Jesse Rosenstock
a6ce08abf7 Property: Promote note to warning
Property() should not be used against member functions that you do not own.  Make
this warning more prominent in matchers.md and add it to gmock-matchers.h.

PiperOrigin-RevId: 727753777
Change-Id: Idf9155103b04b98efc957ff0d0cf3a8d8662eb72
2025-02-17 01:00:00 -08:00
Derek Mauro
c00fd25b71 Require C++17
Policy information:
https://opensource.google/documentation/policies/cplusplus-support#c_language_standard
https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md

Some small fixes are included for C++17 compatibility.

We had no tests for MSVC C++17 or C++20, so those tests that failed
and had no obvious fix are disabled and a tracking bug has been filed.

PiperOrigin-RevId: 726090558
Change-Id: I4d37d47e87c11f85bfd572deb10f67ca3eb2a9b5
2025-02-12 09:44:07 -08:00
Abseil Team
4a00a24fff Add SaveArgByMove
Allows capture of move-only argument types (e.g. AnyInvocable)

PiperOrigin-RevId: 725262899
Change-Id: Idcd46e333a42d99ff05d58a1bc57d8791f6d45a6
2025-02-10 10:22:27 -08:00
Derek Mauro
a866428a78 Update docs for v1.16.x branch
Also update the minimum required CMake version
https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md

PiperOrigin-RevId: 724375734
Change-Id: Iefa6c7e2061457bc6149a280d2408085b1fb9d11
2025-02-07 09:41:05 -08:00
Derek Mauro
445e9bd8d0 Update GoogleTest deps in preparation for release
PiperOrigin-RevId: 724135630
Change-Id: I24622387e508d27337769e83f7de8fecae9ad425
2025-02-06 17:40:25 -08:00
Derek Mauro
e5443e5c65 Remove empty glob pattern, which is now an error.
It look like this may be a copy-paste bug from the root BUILD file.

PiperOrigin-RevId: 724062332
Change-Id: I8eda2275d996dd14693aee569254db28d9bc4f9d
2025-02-06 13:52:23 -08:00
Abseil Team
e235eb34c6 Pull Regexp syntax out of Death test section in advanced.md
Regexps seem to have nothing in common with death tests, yet their description is planted right in the middle of the death test section.

This CL pulls the regexp section one level up and just before death tests.

PiperOrigin-RevId: 721817710
Change-Id: Idc52f450fb10960a590ceb1a70339f86d4478fe4
2025-01-31 10:23:04 -08:00
Abseil Team
66d7401378 Fix extended regular expressions reference URL in advanced.md
The original URL started with https://www.opengroup.org and fails to redirect to the reference page. According to Chrome's dev tools (Network tab), the response to that request is a HTTP 302 Found, with the new location being "balancer://pubs/onlinepubs/009695399/basedefs/xbd_chap09.html". Chrome does not know what to do with that and displays a blank page.

Changing the `www` subdomain to `pubs` results in HTTP 200.

PiperOrigin-RevId: 721804738
Change-Id: I816d08d5baf957c63ac97506d04c7cc49c3a5ce7
2025-01-31 09:45:17 -08:00
Abseil Team
b4aae50ce1 Export testsuite properties as XML elements, not attributes.
With this change, arbitrary property names in the testsuite no longer
cause the produced XML output to be ill-formed.

PiperOrigin-RevId: 721549090
Change-Id: Iedffa89bf914478f563c8f3b82cd50557762a665
2025-01-30 16:01:31 -08:00
Abseil Team
2b6b042a77 Cast mutable lvalue references to const from testing::ResultOf
PiperOrigin-RevId: 716343482
Change-Id: I125bc4725886958d026c88f3902a8289e476598b
2025-01-16 12:51:11 -08:00
Abseil Team
e4ece4881d Enable safe matcher casts from Matcher<const T&> to Matcher<T>.
PiperOrigin-RevId: 715826130
Change-Id: Id962fd456f6da21ea2a909f331f92d814f1dad46
2025-01-15 09:16:57 -08:00
Abseil Team
504ea69cf7 Document unexpected interaction with death test error code and gmock.
If you have a death test that uses mock objects, it's very likely that those mock objects are not properly cleaned up before death. The gMock atexit leak detector will call `_exit(1)`, overriding your expected exit code.

PiperOrigin-RevId: 713722657
Change-Id: I92a326f3923efc9f0e235d825616f3094eca995c
2025-01-09 10:43:08 -08:00
Abseil Team
4bbf80823c Add UnpackStructImpl for structs with 20 fields.
PiperOrigin-RevId: 713272335
Change-Id: I2b289ece4ce3f91834a8c9ba11a4bd18e6e40fca
2025-01-08 06:38:13 -08:00
Abseil Team
7d76a231b0 gtest: Output a canned test case for test suite setup / teardown failures in XML/JSON
This surfaces useful information about the environment failure in a structured form.

As we can see from the updated test, previously unsurfaced information is now present.

PiperOrigin-RevId: 709892315
Change-Id: I2656294d50c33f995bef5c96195a66cff3c4b907
2024-12-26 15:30:52 -08:00