summaryrefslogtreecommitdiffstats
path: root/googletest
diff options
context:
space:
mode:
Diffstat (limited to 'googletest')
-rw-r--r--googletest/README.md2
-rw-r--r--googletest/cmake/internal_utils.cmake2
-rw-r--r--googletest/include/gtest/gtest-printers.h27
-rw-r--r--googletest/include/gtest/internal/gtest-internal.h10
-rw-r--r--googletest/include/gtest/internal/gtest-port.h14
-rw-r--r--googletest/src/gtest-death-test.cc2
-rw-r--r--googletest/src/gtest-internal-inl.h2
-rw-r--r--googletest/src/gtest-port.cc27
-rw-r--r--googletest/src/gtest.cc5
-rw-r--r--googletest/test/googletest-port-test.cc6
-rw-r--r--googletest/test/googletest-printers-test.cc16
11 files changed, 89 insertions, 24 deletions
diff --git a/googletest/README.md b/googletest/README.md
index 9331fce..44fd69b 100644
--- a/googletest/README.md
+++ b/googletest/README.md
@@ -12,7 +12,7 @@ GoogleTest comes with a CMake build script
([CMakeLists.txt](https://github.com/google/googletest/blob/main/CMakeLists.txt))
that can be used on a wide range of platforms ("C" stands for cross-platform.).
If you don't have CMake installed already, you can download it for free from
-<http://www.cmake.org/>.
+<https://cmake.org/>.
CMake works by generating native makefiles or build projects that can be used in
the compiler environment of your choice. You can either build GoogleTest as a
diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake
index 64fa340..d4f67f4 100644
--- a/googletest/cmake/internal_utils.cmake
+++ b/googletest/cmake/internal_utils.cmake
@@ -80,7 +80,7 @@ macro(config_compiler_and_linker)
set(cxx_no_exception_flags "-EHs-c- -D_HAS_EXCEPTIONS=0")
set(cxx_no_rtti_flags "-GR-")
# Suppress "unreachable code" warning
- # http://stackoverflow.com/questions/3232669 explains the issue.
+ # https://stackoverflow.com/questions/3232669 explains the issue.
set(cxx_base_flags "${cxx_base_flags} -wd4702")
# Ensure MSVC treats source files as UTF-8 encoded.
if(CMAKE_CXX_COMPILER_ID STREQUAL "MSVC")
diff --git a/googletest/include/gtest/gtest-printers.h b/googletest/include/gtest/gtest-printers.h
index d1766e6..9ccbff7 100644
--- a/googletest/include/gtest/gtest-printers.h
+++ b/googletest/include/gtest/gtest-printers.h
@@ -122,6 +122,10 @@
#include "gtest/internal/gtest-internal.h"
#include "gtest/internal/gtest-port.h"
+#if GTEST_INTERNAL_HAS_STD_SPAN
+#include <span> // NOLINT
+#endif // GTEST_INTERNAL_HAS_STD_SPAN
+
namespace testing {
// Definitions in the internal* namespaces are subject to change without notice.
@@ -131,13 +135,32 @@ namespace internal {
template <typename T>
void UniversalPrint(const T& value, ::std::ostream* os);
+template <typename T>
+struct IsStdSpan {
+ static constexpr bool value = false;
+};
+
+#if GTEST_INTERNAL_HAS_STD_SPAN
+template <typename E>
+struct IsStdSpan<std::span<E>> {
+ static constexpr bool value = true;
+};
+#endif // GTEST_INTERNAL_HAS_STD_SPAN
+
// Used to print an STL-style container when the user doesn't define
// a PrintTo() for it.
+//
+// NOTE: Since std::span does not have const_iterator until C++23, it would
+// fail IsContainerTest before C++23. However, IsContainerTest only uses
+// the presence of const_iterator to avoid treating iterators as containers
+// because of iterator::iterator. Which means std::span satisfies the *intended*
+// condition of IsContainerTest.
struct ContainerPrinter {
template <typename T,
typename = typename std::enable_if<
- (sizeof(IsContainerTest<T>(0)) == sizeof(IsContainer)) &&
- !IsRecursiveContainer<T>::value>::type>
+ ((sizeof(IsContainerTest<T>(0)) == sizeof(IsContainer)) &&
+ !IsRecursiveContainer<T>::value) ||
+ IsStdSpan<T>::value>::type>
static void PrintValue(const T& container, std::ostream* os) {
const size_t kMaxCount = 32; // The maximum number of elements to print.
*os << '{';
diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h
index 97a9833..4f077fc 100644
--- a/googletest/include/gtest/internal/gtest-internal.h
+++ b/googletest/include/gtest/internal/gtest-internal.h
@@ -78,7 +78,7 @@
//
// will result in the token foo__LINE__, instead of foo followed by
// the current line number. For more details, see
-// http://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6
+// https://www.parashift.com/c++-faq-lite/misc-technical-issues.html#faq-39.6
#define GTEST_CONCAT_TOKEN_(foo, bar) GTEST_CONCAT_TOKEN_IMPL_(foo, bar)
#define GTEST_CONCAT_TOKEN_IMPL_(foo, bar) foo##bar
@@ -169,7 +169,7 @@ namespace edit_distance {
// All edits cost the same, with replace having lower priority than
// add/remove.
// Simple implementation of the Wagner-Fischer algorithm.
-// See http://en.wikipedia.org/wiki/Wagner-Fischer_algorithm
+// See https://en.wikipedia.org/wiki/Wagner-Fischer_algorithm
enum EditType { kMatch, kAdd, kRemove, kReplace };
GTEST_API_ std::vector<EditType> CalculateOptimalEdits(
const std::vector<size_t>& left, const std::vector<size_t>& right);
@@ -236,7 +236,7 @@ GTEST_API_ std::string GetBoolAssertionFailureMessage(
// For double, there are 11 exponent bits and 52 fraction bits.
//
// More details can be found at
-// http://en.wikipedia.org/wiki/IEEE_floating-point_standard.
+// https://en.wikipedia.org/wiki/IEEE_floating-point_standard.
//
// Template parameter:
//
@@ -281,7 +281,7 @@ class FloatingPoint {
// bits. Therefore, 4 should be enough for ordinary use.
//
// See the following article for more details on ULP:
- // http://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
+ // https://randomascii.wordpress.com/2012/02/25/comparing-floating-point-numbers-2012-edition/
static const uint32_t kMaxUlps = 4;
// Constructs a FloatingPoint from a raw floating-point number.
@@ -362,7 +362,7 @@ class FloatingPoint {
// N - 1 (the biggest number representable using
// sign-and-magnitude) is represented by 2N - 1.
//
- // Read http://en.wikipedia.org/wiki/Signed_number_representations
+ // Read https://en.wikipedia.org/wiki/Signed_number_representations
// for more details on signed number representations.
static Bits SignAndMagnitudeToBiased(const Bits& sam) {
if (kSignBitMask & sam) {
diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h
index b887e24..35544a0 100644
--- a/googletest/include/gtest/internal/gtest-port.h
+++ b/googletest/include/gtest/internal/gtest-port.h
@@ -208,6 +208,8 @@
// or
// UniversalPrinter<absl::optional>
// specializations. Always defined to 0 or 1.
+// GTEST_INTERNAL_HAS_STD_SPAN - for enabling UniversalPrinter<std::span>
+// specializations. Always defined to 0 or 1
// GTEST_INTERNAL_HAS_STRING_VIEW - for enabling Matcher<std::string_view> or
// Matcher<absl::string_view>
// specializations. Always defined to 0 or 1.
@@ -609,7 +611,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
// Determines whether clone(2) is supported.
// Usually it will only be available on Linux, excluding
// Linux on the Itanium architecture.
-// Also see http://linux.die.net/man/2/clone.
+// Also see https://linux.die.net/man/2/clone.
#ifndef GTEST_HAS_CLONE
// The user didn't tell us, so we need to figure it out.
@@ -2407,6 +2409,16 @@ inline ::std::nullopt_t Nullopt() { return ::std::nullopt; }
#define GTEST_INTERNAL_HAS_OPTIONAL 0
#endif
+#ifdef __has_include
+#if __has_include(<span>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L
+#define GTEST_INTERNAL_HAS_STD_SPAN 1
+#endif // __has_include(<span>) && GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L
+#endif // __has_include
+
+#ifndef GTEST_INTERNAL_HAS_STD_SPAN
+#define GTEST_INTERNAL_HAS_STD_SPAN 0
+#endif
+
#ifdef GTEST_HAS_ABSL
// Always use absl::string_view for Matcher<> specializations if googletest
// is built with absl support.
diff --git a/googletest/src/gtest-death-test.cc b/googletest/src/gtest-death-test.cc
index 0eb6e38..8417a30 100644
--- a/googletest/src/gtest-death-test.cc
+++ b/googletest/src/gtest-death-test.cc
@@ -783,7 +783,7 @@ DeathTest::TestRole WindowsDeathTest::AssumeRole() {
StreamableToString(static_cast<unsigned int>(::GetCurrentProcessId())) +
// size_t has the same width as pointers on both 32-bit and 64-bit
// Windows platforms.
- // See http://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx.
+ // See https://msdn.microsoft.com/en-us/library/tcxf1dw6.aspx.
"|" + StreamableToString(reinterpret_cast<size_t>(write_handle)) + "|" +
StreamableToString(reinterpret_cast<size_t>(event_handle_.Get()));
diff --git a/googletest/src/gtest-internal-inl.h b/googletest/src/gtest-internal-inl.h
index 5b7fcbd..4799a1e 100644
--- a/googletest/src/gtest-internal-inl.h
+++ b/googletest/src/gtest-internal-inl.h
@@ -312,7 +312,7 @@ void ShuffleRange(internal::Random* random, int begin, int end,
<< begin << ", " << size << "].";
// Fisher-Yates shuffle, from
- // http://en.wikipedia.org/wiki/Fisher-Yates_shuffle
+ // https://en.wikipedia.org/wiki/Fisher-Yates_shuffle
for (int range_width = end - begin; range_width >= 2; range_width--) {
const int last_in_range = begin + range_width - 1;
const int selected =
diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc
index 628ab3d..e9d12d9 100644
--- a/googletest/src/gtest-port.cc
+++ b/googletest/src/gtest-port.cc
@@ -158,13 +158,13 @@ size_t GetThreadCount() {
// we cannot detect it.
size_t GetThreadCount() {
int mib[] = {
- CTL_KERN,
- KERN_PROC,
- KERN_PROC_PID,
- getpid(),
+ CTL_KERN,
+ KERN_PROC,
+ KERN_PROC_PID,
+ getpid(),
#ifdef GTEST_OS_NETBSD
- sizeof(struct kinfo_proc),
- 1,
+ sizeof(struct kinfo_proc),
+ 1,
#endif
};
u_int miblen = sizeof(mib) / sizeof(mib[0]);
@@ -1028,6 +1028,16 @@ GTEST_DISABLE_MSC_DEPRECATED_PUSH_()
#if GTEST_HAS_STREAM_REDIRECTION
+namespace {
+
+#if defined(GTEST_OS_LINUX_ANDROID) || defined(GTEST_OS_IOS)
+bool EndsWithPathSeparator(const std::string& path) {
+ return !path.empty() && path.back() == GTEST_PATH_SEP_[0];
+}
+#endif
+
+} // namespace
+
// Object that captures an output stream (stdout/stderr).
class CapturedStream {
public:
@@ -1068,6 +1078,9 @@ class CapturedStream {
// However, prefer using the TMPDIR environment variable if set, as newer
// devices may have /data/local/tmp read-only.
name_template = TempDir();
+ if (!EndsWithPathSeparator(name_template))
+ name_template.push_back(GTEST_PATH_SEP_[0]);
+
#elif defined(GTEST_OS_IOS)
char user_temp_dir[PATH_MAX + 1];
@@ -1087,7 +1100,7 @@ class CapturedStream {
::confstr(_CS_DARWIN_USER_TEMP_DIR, user_temp_dir, sizeof(user_temp_dir));
name_template = user_temp_dir;
- if (name_template.back() != GTEST_PATH_SEP_[0])
+ if (!EndsWithPathSeparator(name_template))
name_template.push_back(GTEST_PATH_SEP_[0]);
#else
name_template = "/tmp/";
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc
index 30a5cc3..62dfef6 100644
--- a/googletest/src/gtest.cc
+++ b/googletest/src/gtest.cc
@@ -879,7 +879,7 @@ int UnitTestOptions::GTestProcessSEH(DWORD seh_code, const char* location) {
// apparently).
//
// SEH exception code for C++ exceptions.
- // (see http://support.microsoft.com/kb/185294 for more information).
+ // (see https://support.microsoft.com/kb/185294 for more information).
const DWORD kCxxExceptionCode = 0xe06d7363;
if (!GTEST_FLAG_GET(catch_exceptions) || seh_code == kCxxExceptionCode ||
@@ -3228,7 +3228,8 @@ static const char* GetAnsiColorCode(GTestColor color) {
case GTestColor::kYellow:
return "3";
default:
- return nullptr;
+ assert(false);
+ return "9";
}
}
diff --git a/googletest/test/googletest-port-test.cc b/googletest/test/googletest-port-test.cc
index e0793ba..8d21026 100644
--- a/googletest/test/googletest-port-test.cc
+++ b/googletest/test/googletest-port-test.cc
@@ -296,7 +296,7 @@ void* ThreadFunc(void* data) {
TEST(GetThreadCountTest, ReturnsCorrectValue) {
size_t starting_count;
size_t thread_count_after_create;
- size_t thread_count_after_join;
+ size_t thread_count_after_join = 0;
// We can't guarantee that no other thread was created or destroyed between
// any two calls to GetThreadCount(). We make multiple attempts, hoping that
@@ -316,9 +316,9 @@ TEST(GetThreadCountTest, ReturnsCorrectValue) {
const int status = pthread_create(&thread_id, &attr, &ThreadFunc, &mutex);
ASSERT_EQ(0, pthread_attr_destroy(&attr));
ASSERT_EQ(0, status);
- }
- thread_count_after_create = GetThreadCount();
+ thread_count_after_create = GetThreadCount();
+ }
void* dummy;
ASSERT_EQ(0, pthread_join(thread_id, &dummy));
diff --git a/googletest/test/googletest-printers-test.cc b/googletest/test/googletest-printers-test.cc
index bee0ca4..d5061be 100644
--- a/googletest/test/googletest-printers-test.cc
+++ b/googletest/test/googletest-printers-test.cc
@@ -54,11 +54,16 @@
#include "gtest/gtest-printers.h"
#include "gtest/gtest.h"
+#include "gtest/internal/gtest-port.h"
#ifdef GTEST_HAS_ABSL
#include "absl/strings/str_format.h"
#endif
+#if GTEST_INTERNAL_HAS_STD_SPAN
+#include <span> // NOLINT
+#endif // GTEST_INTERNAL_HAS_STD_SPAN
+
// Some user-defined types for testing the universal value printer.
// An anonymous enum type.
@@ -1179,6 +1184,17 @@ TEST(PrintStlContainerTest, Vector) {
EXPECT_EQ("{ 1, 2 }", Print(v));
}
+TEST(PrintStlContainerTest, StdSpan) {
+#if GTEST_INTERNAL_HAS_STD_SPAN
+ int a[] = {3, 6, 5};
+ std::span<int> s = a;
+
+ EXPECT_EQ("{ 3, 6, 5 }", Print(s));
+#else
+ GTEST_SKIP() << "Does not have std::span.";
+#endif // GTEST_INTERNAL_HAS_STD_SPAN
+}
+
TEST(PrintStlContainerTest, LongSequence) {
const int a[100] = {1, 2, 3};
const vector<int> v(a, a + 100);