feat(printers): GTEST_MAX_NUM_ELEMENTS_TO_PRINT override (#4905)

Signed-off-by: ameliabarnabyhub <ameliabarnabyhub@users.noreply.github.com>
This commit is contained in:
ameliabarnabyhub 2026-08-14 10:27:11 +08:00
parent 963dd8ea18
commit df1aecf2a0
1 changed files with 5 additions and 1 deletions

View File

@ -163,6 +163,9 @@ struct IsStdSpan<std::span<E>> {
// the presence of const_iterator to avoid treating iterators as containers // the presence of const_iterator to avoid treating iterators as containers
// because of iterator::iterator. Which means std::span satisfies the *intended* // because of iterator::iterator. Which means std::span satisfies the *intended*
// condition of IsContainerTest. // condition of IsContainerTest.
#ifndef GTEST_MAX_NUM_ELEMENTS_TO_PRINT
#define GTEST_MAX_NUM_ELEMENTS_TO_PRINT 32
#endif
struct ContainerPrinter { struct ContainerPrinter {
template <typename T, template <typename T,
typename = typename std::enable_if< typename = typename std::enable_if<
@ -170,7 +173,8 @@ struct ContainerPrinter {
!IsRecursiveContainer<T>::value) || !IsRecursiveContainer<T>::value) ||
IsStdSpan<T>::value>::type> IsStdSpan<T>::value>::type>
static void PrintValue(const T& container, std::ostream* os) { static void PrintValue(const T& container, std::ostream* os) {
const size_t kMaxCount = 32; // The maximum number of elements to print. const size_t kMaxCount =
static_cast<size_t>(GTEST_MAX_NUM_ELEMENTS_TO_PRINT);
*os << '{'; *os << '{';
size_t count = 0; size_t count = 0;
for (auto&& elem : container) { for (auto&& elem : container) {