mirror of
https://github.com/google/googletest.git
synced 2025-04-02 19:08:12 +00:00
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
This commit is contained in:
parent
4a00a24fff
commit
c00fd25b71
@ -39,43 +39,60 @@ if [[ -z ${GTEST_ROOT:-} ]]; then
|
||||
fi
|
||||
|
||||
if [[ -z ${STD:-} ]]; then
|
||||
STD="c++14 c++17 c++20"
|
||||
STD="c++17 c++20"
|
||||
fi
|
||||
|
||||
# Test the CMake build
|
||||
for cc in /usr/local/bin/gcc /opt/llvm/clang/bin/clang; do
|
||||
for cmake_off_on in OFF ON; do
|
||||
time docker run \
|
||||
--volume="${GTEST_ROOT}:/src:ro" \
|
||||
--tmpfs="/build:exec" \
|
||||
--workdir="/build" \
|
||||
--rm \
|
||||
--env="CC=${cc}" \
|
||||
--env=CXXFLAGS="-Werror -Wdeprecated" \
|
||||
${LINUX_LATEST_CONTAINER} \
|
||||
/bin/bash -c "
|
||||
cmake /src \
|
||||
-DCMAKE_CXX_STANDARD=14 \
|
||||
-Dgtest_build_samples=ON \
|
||||
-Dgtest_build_tests=ON \
|
||||
-Dgmock_build_tests=ON \
|
||||
-Dcxx_no_exception=${cmake_off_on} \
|
||||
-Dcxx_no_rtti=${cmake_off_on} && \
|
||||
make -j$(nproc) && \
|
||||
ctest -j$(nproc) --output-on-failure"
|
||||
done
|
||||
# Test CMake + GCC
|
||||
for cmake_off_on in OFF ON; do
|
||||
time docker run \
|
||||
--volume="${GTEST_ROOT}:/src:ro" \
|
||||
--tmpfs="/build:exec" \
|
||||
--workdir="/build" \
|
||||
--rm \
|
||||
--env="CC=/usr/local/bin/gcc" \
|
||||
--env=CXXFLAGS="-Werror -Wdeprecated" \
|
||||
${LINUX_LATEST_CONTAINER} \
|
||||
/bin/bash -c "
|
||||
cmake /src \
|
||||
-DCMAKE_CXX_STANDARD=17 \
|
||||
-Dgtest_build_samples=ON \
|
||||
-Dgtest_build_tests=ON \
|
||||
-Dgmock_build_tests=ON \
|
||||
-Dcxx_no_exception=${cmake_off_on} \
|
||||
-Dcxx_no_rtti=${cmake_off_on} && \
|
||||
make -j$(nproc) && \
|
||||
ctest -j$(nproc) --output-on-failure"
|
||||
done
|
||||
|
||||
# Test CMake + Clang
|
||||
for cmake_off_on in OFF ON; do
|
||||
time docker run \
|
||||
--volume="${GTEST_ROOT}:/src:ro" \
|
||||
--tmpfs="/build:exec" \
|
||||
--workdir="/build" \
|
||||
--rm \
|
||||
--env="CC=/opt/llvm/clang/bin/clang" \
|
||||
--env=CXXFLAGS="-Werror -Wdeprecated --gcc-toolchain=/usr/local" \
|
||||
${LINUX_LATEST_CONTAINER} \
|
||||
/bin/bash -c "
|
||||
cmake /src \
|
||||
-DCMAKE_CXX_STANDARD=17 \
|
||||
-Dgtest_build_samples=ON \
|
||||
-Dgtest_build_tests=ON \
|
||||
-Dgmock_build_tests=ON \
|
||||
-Dcxx_no_exception=${cmake_off_on} \
|
||||
-Dcxx_no_rtti=${cmake_off_on} && \
|
||||
make -j$(nproc) && \
|
||||
ctest -j$(nproc) --output-on-failure"
|
||||
done
|
||||
|
||||
# Do one test with an older version of GCC
|
||||
# TODO(googletest-team): This currently uses Bazel 5. When upgrading to a
|
||||
# version of Bazel that supports Bzlmod, add --enable_bzlmod=false to keep test
|
||||
# coverage for the old WORKSPACE dependency management.
|
||||
time docker run \
|
||||
--volume="${GTEST_ROOT}:/src:ro" \
|
||||
--workdir="/src" \
|
||||
--rm \
|
||||
--env="CC=/usr/local/bin/gcc" \
|
||||
--env="BAZEL_CXXOPTS=-std=c++14" \
|
||||
--env="BAZEL_CXXOPTS=-std=c++17" \
|
||||
${LINUX_GCC_FLOOR_CONTAINER} \
|
||||
/usr/local/bin/bazel test ... \
|
||||
--copt="-Wall" \
|
||||
@ -83,6 +100,7 @@ time docker run \
|
||||
--copt="-Wuninitialized" \
|
||||
--copt="-Wundef" \
|
||||
--copt="-Wno-error=pragmas" \
|
||||
--enable_bzlmod=false \
|
||||
--features=external_include_paths \
|
||||
--keep_going \
|
||||
--show_timestamps \
|
||||
|
@ -31,6 +31,9 @@
|
||||
|
||||
set -euox pipefail
|
||||
|
||||
# Use Xcode 16.0
|
||||
sudo xcode-select -s /Applications/Xcode_16.0.app/Contents/Developer
|
||||
|
||||
if [[ -z ${GTEST_ROOT:-} ]]; then
|
||||
GTEST_ROOT="$(realpath $(dirname ${0})/..)"
|
||||
fi
|
||||
@ -40,20 +43,20 @@ for cmake_off_on in OFF ON; do
|
||||
BUILD_DIR=$(mktemp -d build_dir.XXXXXXXX)
|
||||
cd ${BUILD_DIR}
|
||||
time cmake ${GTEST_ROOT} \
|
||||
-DCMAKE_CXX_STANDARD=14 \
|
||||
-DCMAKE_CXX_STANDARD=17 \
|
||||
-Dgtest_build_samples=ON \
|
||||
-Dgtest_build_tests=ON \
|
||||
-Dgmock_build_tests=ON \
|
||||
-Dcxx_no_exception=${cmake_off_on} \
|
||||
-Dcxx_no_rtti=${cmake_off_on}
|
||||
time make
|
||||
time make -j$(nproc)
|
||||
time ctest -j$(nproc) --output-on-failure
|
||||
done
|
||||
|
||||
# Test the Bazel build
|
||||
|
||||
# If we are running on Kokoro, check for a versioned Bazel binary.
|
||||
KOKORO_GFILE_BAZEL_BIN="bazel-7.0.0-darwin-x86_64"
|
||||
KOKORO_GFILE_BAZEL_BIN="bazel-8.0.0-darwin-x86_64"
|
||||
if [[ ${KOKORO_GFILE_DIR:-} ]] && [[ -f ${KOKORO_GFILE_DIR}/${KOKORO_GFILE_BAZEL_BIN} ]]; then
|
||||
BAZEL_BIN="${KOKORO_GFILE_DIR}/${KOKORO_GFILE_BAZEL_BIN}"
|
||||
chmod +x ${BAZEL_BIN}
|
||||
@ -67,7 +70,7 @@ for absl in 0 1; do
|
||||
--copt="-Wall" \
|
||||
--copt="-Werror" \
|
||||
--copt="-Wundef" \
|
||||
--cxxopt="-std=c++14" \
|
||||
--cxxopt="-std=c++17" \
|
||||
--define="absl=${absl}" \
|
||||
--enable_bzlmod=true \
|
||||
--features=external_include_paths \
|
||||
|
@ -1,6 +1,6 @@
|
||||
SETLOCAL ENABLEDELAYEDEXPANSION
|
||||
|
||||
SET BAZEL_EXE=%KOKORO_GFILE_DIR%\bazel-7.0.0-windows-x86_64.exe
|
||||
SET BAZEL_EXE=%KOKORO_GFILE_DIR%\bazel-8.0.0-windows-x86_64.exe
|
||||
|
||||
SET PATH=C:\Python34;%PATH%
|
||||
SET BAZEL_PYTHON=C:\python34\python.exe
|
||||
@ -11,21 +11,18 @@ SET CTEST_OUTPUT_ON_FAILURE=1
|
||||
SET CMAKE_BUILD_PARALLEL_LEVEL=16
|
||||
SET CTEST_PARALLEL_LEVEL=16
|
||||
|
||||
IF EXIST git\googletest (
|
||||
CD git\googletest
|
||||
) ELSE IF EXIST github\googletest (
|
||||
CD github\googletest
|
||||
)
|
||||
|
||||
SET GTEST_ROOT=%~dp0\..
|
||||
IF %errorlevel% neq 0 EXIT /B 1
|
||||
|
||||
:: ----------------------------------------------------------------------------
|
||||
:: CMake
|
||||
MKDIR cmake_msvc2022
|
||||
CD cmake_msvc2022
|
||||
SET CMAKE_BUILD_PATH=cmake_msvc2022
|
||||
MKDIR %CMAKE_BUILD_PATH%
|
||||
CD %CMAKE_BUILD_PATH%
|
||||
|
||||
%CMAKE_BIN% .. ^
|
||||
%CMAKE_BIN% %GTEST_ROOT% ^
|
||||
-G "Visual Studio 17 2022" ^
|
||||
-DCMAKE_CXX_STANDARD=17 ^
|
||||
-DPYTHON_EXECUTABLE:FILEPATH=c:\python37\python.exe ^
|
||||
-DPYTHON_INCLUDE_DIR:PATH=c:\python37\include ^
|
||||
-DPYTHON_LIBRARY:FILEPATH=c:\python37\lib\site-packages\pip ^
|
||||
@ -40,8 +37,8 @@ IF %errorlevel% neq 0 EXIT /B 1
|
||||
%CTEST_BIN% -C Debug --timeout 600
|
||||
IF %errorlevel% neq 0 EXIT /B 1
|
||||
|
||||
CD ..
|
||||
RMDIR /S /Q cmake_msvc2022
|
||||
CD %GTEST_ROOT%
|
||||
RMDIR /S /Q %CMAKE_BUILD_PATH%
|
||||
|
||||
:: ----------------------------------------------------------------------------
|
||||
:: Bazel
|
||||
@ -50,11 +47,26 @@ RMDIR /S /Q cmake_msvc2022
|
||||
:: because of Windows limitations on path length.
|
||||
:: --output_user_root=C:\tmp causes Bazel to use a shorter path.
|
||||
SET BAZEL_VS=C:\Program Files\Microsoft Visual Studio\2022\Community
|
||||
|
||||
:: C++17
|
||||
%BAZEL_EXE% ^
|
||||
--output_user_root=C:\tmp ^
|
||||
test ... ^
|
||||
--compilation_mode=dbg ^
|
||||
--copt=/std:c++14 ^
|
||||
--copt=/std:c++17 ^
|
||||
--copt=/WX ^
|
||||
--enable_bzlmod=true ^
|
||||
--keep_going ^
|
||||
--test_output=errors ^
|
||||
--test_tag_filters=-no_test_msvc2017
|
||||
IF %errorlevel% neq 0 EXIT /B 1
|
||||
|
||||
:: C++20
|
||||
%BAZEL_EXE% ^
|
||||
--output_user_root=C:\tmp ^
|
||||
test ... ^
|
||||
--compilation_mode=dbg ^
|
||||
--copt=/std:c++20 ^
|
||||
--copt=/WX ^
|
||||
--enable_bzlmod=true ^
|
||||
--keep_going ^
|
||||
|
@ -222,8 +222,8 @@ TEST(TypeTraits, IsInvocableRV) {
|
||||
// In C++17 and above, where it's guaranteed that functions can return
|
||||
// non-moveable objects, everything should work fine for non-moveable rsult
|
||||
// types too.
|
||||
#if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \
|
||||
GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
|
||||
// TODO(b/396121064) - Fix this test under MSVC
|
||||
#ifndef _MSC_VER
|
||||
{
|
||||
struct NonMoveable {
|
||||
NonMoveable() = default;
|
||||
@ -244,7 +244,7 @@ TEST(TypeTraits, IsInvocableRV) {
|
||||
static_assert(!internal::is_callable_r<int, Callable>::value);
|
||||
static_assert(!internal::is_callable_r<NonMoveable, Callable, int>::value);
|
||||
}
|
||||
#endif // C++17 and above
|
||||
#endif // _MSC_VER
|
||||
|
||||
// Nothing should choke when we try to call other arguments besides directly
|
||||
// callable objects, but they should not show up as callable.
|
||||
|
@ -804,9 +804,8 @@ TEST(ExpectCallTest, InfersCardinality1WhenThereIsWillRepeatedly) {
|
||||
"to be called at least once");
|
||||
}
|
||||
|
||||
#if defined(GTEST_INTERNAL_CPLUSPLUS_LANG) && \
|
||||
GTEST_INTERNAL_CPLUSPLUS_LANG >= 201703L
|
||||
|
||||
// TODO(b/396121064) - Fix this test under MSVC
|
||||
#ifndef _MSC_VER
|
||||
// It should be possible to return a non-moveable type from a mock action in
|
||||
// C++17 and above, where it's guaranteed that such a type can be initialized
|
||||
// from a prvalue returned from a function.
|
||||
@ -847,7 +846,7 @@ TEST(ExpectCallTest, NonMoveableType) {
|
||||
EXPECT_EQ(17, mock.AsStdFunction()().x);
|
||||
}
|
||||
|
||||
#endif // C++17 and above
|
||||
#endif // _MSC_VER
|
||||
|
||||
// Tests that the n-th action is taken for the n-th matching
|
||||
// invocation.
|
||||
|
@ -195,7 +195,7 @@ function(cxx_library_with_type name type cxx_flags)
|
||||
target_link_libraries(${name} PUBLIC Threads::Threads)
|
||||
endif()
|
||||
|
||||
target_compile_features(${name} PUBLIC cxx_std_14)
|
||||
target_compile_features(${name} PUBLIC cxx_std_17)
|
||||
endfunction()
|
||||
|
||||
########################################################################
|
||||
|
@ -275,8 +275,8 @@
|
||||
#endif
|
||||
|
||||
#if !defined(GTEST_INTERNAL_CPLUSPLUS_LANG) || \
|
||||
GTEST_INTERNAL_CPLUSPLUS_LANG < 201402L
|
||||
#error C++ versions less than C++14 are not supported.
|
||||
GTEST_INTERNAL_CPLUSPLUS_LANG < 201703L
|
||||
#error C++ versions less than C++17 are not supported.
|
||||
#endif
|
||||
|
||||
// MSVC >= 19.11 (VS 2017 Update 3) supports __has_include.
|
||||
|
@ -121,6 +121,9 @@ class UnprintableTemplateInGlobal {
|
||||
// A user-defined streamable type in the global namespace.
|
||||
class StreamableInGlobal {
|
||||
public:
|
||||
StreamableInGlobal() = default;
|
||||
StreamableInGlobal(const StreamableInGlobal&) = default;
|
||||
StreamableInGlobal& operator=(const StreamableInGlobal&) = default;
|
||||
virtual ~StreamableInGlobal() = default;
|
||||
};
|
||||
|
||||
@ -572,6 +575,8 @@ TEST(PrintU8StringTest, Null) {
|
||||
}
|
||||
|
||||
// Tests that u8 strings are escaped properly.
|
||||
// TODO(b/396121064) - Fix this test under MSVC
|
||||
#ifndef _MSC_VER
|
||||
TEST(PrintU8StringTest, EscapesProperly) {
|
||||
const char8_t* p = u8"'\"?\\\a\b\f\n\r\t\v\x7F\xFF hello 世界";
|
||||
EXPECT_EQ(PrintPointer(p) +
|
||||
@ -579,7 +584,8 @@ TEST(PrintU8StringTest, EscapesProperly) {
|
||||
"hello \\xE4\\xB8\\x96\\xE7\\x95\\x8C\"",
|
||||
Print(p));
|
||||
}
|
||||
#endif
|
||||
#endif // _MSC_VER
|
||||
#endif // __cpp_lib_char8_t
|
||||
|
||||
// const char16_t*.
|
||||
TEST(PrintU16StringTest, Const) {
|
||||
|
@ -31,14 +31,14 @@
|
||||
|
||||
class SetupFailTest : public ::testing::Test {
|
||||
protected:
|
||||
static void SetUpTestSuite() { ASSERT_EQ("", "SET_UP_FAIL"); }
|
||||
static void SetUpTestSuite() { ASSERT_STREQ("", "SET_UP_FAIL"); }
|
||||
};
|
||||
|
||||
TEST_F(SetupFailTest, NoopPassingTest) {}
|
||||
|
||||
class TearDownFailTest : public ::testing::Test {
|
||||
protected:
|
||||
static void TearDownTestSuite() { ASSERT_EQ("", "TEAR_DOWN_FAIL"); }
|
||||
static void TearDownTestSuite() { ASSERT_STREQ("", "TEAR_DOWN_FAIL"); }
|
||||
};
|
||||
|
||||
TEST_F(TearDownFailTest, NoopPassingTest) {}
|
||||
|
Loading…
x
Reference in New Issue
Block a user