Replace an internal link to AbslStringify's documentation with the equivalent public link.
PiperOrigin-RevId: 779085254
Change-Id: I2cbd2b6262a5ced06f166d4fcc7c08796e5a60af
Users have shown some confusion about the interaction between this flag,
sharding, and --gtest_filter, so let's provide some more information.
PiperOrigin-RevId: 776734799
Change-Id: Icdcf6aa056988095f15588758994604d326c0567
There are two cases that prompt this behavior:
- All test cases in the binary are disabled.
- There are more shards defined than test cases, so some shards are empty.
The result in each case is the same: the test runner needs to spin up
additional processes that do nothing, which is wasteful, especially when tests
need expensive resources.
PiperOrigin-RevId: 769176856
Change-Id: Ifa399a0b7b68e4add5a94ca148b32b2938a8666d
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
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
and std::variant now that the absl types are aliases of the
std types
PiperOrigin-RevId: 761136061
Change-Id: I702c3e1e8c58d003b8f4da99e7c84c9e5dbe1863
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
* 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
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
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
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
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
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
`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
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
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
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
to fail the test program if no test case is linked in
(a common programmer mistake).
PiperOrigin-RevId: 730571311
Change-Id: I1dab04adfe35581274d0b4ec79a017014d50e1ea
* 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