Merge branch 'google:main' into feat/add_platformio

This commit is contained in:
Chris Johnson 2023-06-22 12:00:56 -05:00 committed by GitHub
commit 2d41439f5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 61 additions and 128 deletions

View File

@ -3,14 +3,6 @@
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13)
if (POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
endif (POLICY CMP0069)
if (POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif (POLICY CMP0077)
project(googletest-distribution) project(googletest-distribution)
set(GOOGLETEST_VERSION 1.13.0) set(GOOGLETEST_VERSION 1.13.0)

View File

@ -697,9 +697,9 @@ TEST(AbcTest, Xyz) {
EXPECT_CALL(foo, DoThat(_, _)); EXPECT_CALL(foo, DoThat(_, _));
int n = 0; int n = 0;
EXPECT_EQ('+', foo.DoThis(5)); // FakeFoo::DoThis() is invoked. EXPECT_EQ(foo.DoThis(5), '+'); // FakeFoo::DoThis() is invoked.
foo.DoThat("Hi", &n); // FakeFoo::DoThat() is invoked. foo.DoThat("Hi", &n); // FakeFoo::DoThat() is invoked.
EXPECT_EQ(2, n); EXPECT_EQ(n, 2);
} }
``` ```
@ -1129,11 +1129,11 @@ using STL's `<functional>` header is just painful). For example, here's a
predicate that's satisfied by any number that is >= 0, <= 100, and != 50: predicate that's satisfied by any number that is >= 0, <= 100, and != 50:
```cpp ```cpp
using testing::AllOf; using ::testing::AllOf;
using testing::Ge; using ::testing::Ge;
using testing::Le; using ::testing::Le;
using testing::Matches; using ::testing::Matches;
using testing::Ne; using ::testing::Ne;
... ...
Matches(AllOf(Ge(0), Le(100), Ne(50))) Matches(AllOf(Ge(0), Le(100), Ne(50)))
``` ```
@ -1861,7 +1861,7 @@ error. So, what shall you do?
Though you may be tempted, DO NOT use `std::ref()`: Though you may be tempted, DO NOT use `std::ref()`:
```cpp ```cpp
using testing::Return; using ::testing::Return;
class MockFoo : public Foo { class MockFoo : public Foo {
public: public:
@ -1873,7 +1873,7 @@ class MockFoo : public Foo {
EXPECT_CALL(foo, GetValue()) EXPECT_CALL(foo, GetValue())
.WillRepeatedly(Return(std::ref(x))); // Wrong! .WillRepeatedly(Return(std::ref(x))); // Wrong!
x = 42; x = 42;
EXPECT_EQ(42, foo.GetValue()); EXPECT_EQ(foo.GetValue(), 42);
``` ```
Unfortunately, it doesn't work here. The above code will fail with error: Unfortunately, it doesn't work here. The above code will fail with error:
@ -1895,14 +1895,14 @@ the expectation is set, and `Return(std::ref(x))` will always return 0.
returns the value pointed to by `pointer` at the time the action is *executed*: returns the value pointed to by `pointer` at the time the action is *executed*:
```cpp ```cpp
using testing::ReturnPointee; using ::testing::ReturnPointee;
... ...
int x = 0; int x = 0;
MockFoo foo; MockFoo foo;
EXPECT_CALL(foo, GetValue()) EXPECT_CALL(foo, GetValue())
.WillRepeatedly(ReturnPointee(&x)); // Note the & here. .WillRepeatedly(ReturnPointee(&x)); // Note the & here.
x = 42; x = 42;
EXPECT_EQ(42, foo.GetValue()); // This will succeed now. EXPECT_EQ(foo.GetValue(), 42); // This will succeed now.
``` ```
### Combining Actions ### Combining Actions
@ -2264,7 +2264,7 @@ TEST_F(FooTest, Test) {
EXPECT_CALL(foo, DoThis(2)) EXPECT_CALL(foo, DoThis(2))
.WillOnce(Invoke(NewPermanentCallback(SignOfSum, 5))); .WillOnce(Invoke(NewPermanentCallback(SignOfSum, 5)));
EXPECT_EQ('+', foo.DoThis(2)); // Invokes SignOfSum(5, 2). EXPECT_EQ(foo.DoThis(2), '+'); // Invokes SignOfSum(5, 2).
} }
``` ```
@ -2771,11 +2771,13 @@ returns a null `unique_ptr`, thats what youll get if you dont specify a
action: action:
```cpp ```cpp
using ::testing::IsNull;
...
// Use the default action. // Use the default action.
EXPECT_CALL(mock_buzzer_, MakeBuzz("hello")); EXPECT_CALL(mock_buzzer_, MakeBuzz("hello"));
// Triggers the previous EXPECT_CALL. // Triggers the previous EXPECT_CALL.
EXPECT_EQ(nullptr, mock_buzzer_.MakeBuzz("hello")); EXPECT_THAT(mock_buzzer_.MakeBuzz("hello"), IsNull());
``` ```
If you are not happy with the default action, you can tweak it as usual; see If you are not happy with the default action, you can tweak it as usual; see
@ -3194,9 +3196,9 @@ flag. For example, given the test program:
```cpp ```cpp
#include "gmock/gmock.h" #include "gmock/gmock.h"
using testing::_; using ::testing::_;
using testing::HasSubstr; using ::testing::HasSubstr;
using testing::Return; using ::testing::Return;
class MockFoo { class MockFoo {
public: public:
@ -3817,15 +3819,15 @@ If the built-in actions don't work for you, you can easily define your own one.
All you need is a call operator with a signature compatible with the mocked All you need is a call operator with a signature compatible with the mocked
function. So you can use a lambda: function. So you can use a lambda:
``` ```cpp
MockFunction<int(int)> mock; MockFunction<int(int)> mock;
EXPECT_CALL(mock, Call).WillOnce([](const int input) { return input * 7; }); EXPECT_CALL(mock, Call).WillOnce([](const int input) { return input * 7; });
EXPECT_EQ(14, mock.AsStdFunction()(2)); EXPECT_EQ(mock.AsStdFunction()(2), 14);
``` ```
Or a struct with a call operator (even a templated one): Or a struct with a call operator (even a templated one):
``` ```cpp
struct MultiplyBy { struct MultiplyBy {
template <typename T> template <typename T>
T operator()(T arg) { return arg * multiplier; } T operator()(T arg) { return arg * multiplier; }
@ -3840,16 +3842,16 @@ struct MultiplyBy {
It's also fine for the callable to take no arguments, ignoring the arguments It's also fine for the callable to take no arguments, ignoring the arguments
supplied to the mock function: supplied to the mock function:
``` ```cpp
MockFunction<int(int)> mock; MockFunction<int(int)> mock;
EXPECT_CALL(mock, Call).WillOnce([] { return 17; }); EXPECT_CALL(mock, Call).WillOnce([] { return 17; });
EXPECT_EQ(17, mock.AsStdFunction()(0)); EXPECT_EQ(mock.AsStdFunction()(0), 17);
``` ```
When used with `WillOnce`, the callable can assume it will be called at most When used with `WillOnce`, the callable can assume it will be called at most
once and is allowed to be a move-only type: once and is allowed to be a move-only type:
``` ```cpp
// An action that contains move-only types and has an &&-qualified operator, // An action that contains move-only types and has an &&-qualified operator,
// demanding in the type system that it be called at most once. This can be // demanding in the type system that it be called at most once. This can be
// used with WillOnce, but the compiler will reject it if handed to // used with WillOnce, but the compiler will reject it if handed to

View File

@ -100,18 +100,14 @@ else()
target_link_libraries(gmock_main PUBLIC gmock) target_link_libraries(gmock_main PUBLIC gmock)
set_target_properties(gmock_main PROPERTIES VERSION ${GOOGLETEST_VERSION}) set_target_properties(gmock_main PROPERTIES VERSION ${GOOGLETEST_VERSION})
endif() endif()
# If the CMake version supports it, attach header directory information
# to the targets for when we are part of a parent build (ie being pulled string(REPLACE ";" "$<SEMICOLON>" dirs "${gmock_build_include_dirs}")
# in via add_subdirectory() rather than being a standalone build). target_include_directories(gmock SYSTEM INTERFACE
if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
string(REPLACE ";" "$<SEMICOLON>" dirs "${gmock_build_include_dirs}")
target_include_directories(gmock SYSTEM INTERFACE
"$<BUILD_INTERFACE:${dirs}>" "$<BUILD_INTERFACE:${dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>") "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
target_include_directories(gmock_main SYSTEM INTERFACE target_include_directories(gmock_main SYSTEM INTERFACE
"$<BUILD_INTERFACE:${dirs}>" "$<BUILD_INTERFACE:${dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>") "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
endif()
######################################################################## ########################################################################
# #
@ -135,11 +131,7 @@ if (gmock_build_tests)
enable_testing() enable_testing()
if (MINGW OR CYGWIN) if (MINGW OR CYGWIN)
if (CMAKE_VERSION VERSION_LESS "2.8.12")
add_compile_options("-Wa,-mbig-obj") add_compile_options("-Wa,-mbig-obj")
else()
add_definitions("-Wa,-mbig-obj")
endif()
endif() endif()
############################################################ ############################################################

View File

@ -49,10 +49,6 @@ endif()
cmake_minimum_required(VERSION 3.13) cmake_minimum_required(VERSION 3.13)
project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C) project(gtest VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
if (POLICY CMP0063) # Visibility
cmake_policy(SET CMP0063 NEW)
endif (POLICY CMP0063)
if (COMMAND set_up_hermetic_build) if (COMMAND set_up_hermetic_build)
set_up_hermetic_build() set_up_hermetic_build()
endif() endif()
@ -144,18 +140,13 @@ if(GTEST_HAS_ABSL)
endif() endif()
cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc) cxx_library(gtest_main "${cxx_strict}" src/gtest_main.cc)
set_target_properties(gtest_main PROPERTIES VERSION ${GOOGLETEST_VERSION}) set_target_properties(gtest_main PROPERTIES VERSION ${GOOGLETEST_VERSION})
# If the CMake version supports it, attach header directory information string(REPLACE ";" "$<SEMICOLON>" dirs "${gtest_build_include_dirs}")
# to the targets for when we are part of a parent build (ie being pulled target_include_directories(gtest SYSTEM INTERFACE
# in via add_subdirectory() rather than being a standalone build).
if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
string(REPLACE ";" "$<SEMICOLON>" dirs "${gtest_build_include_dirs}")
target_include_directories(gtest SYSTEM INTERFACE
"$<BUILD_INTERFACE:${dirs}>" "$<BUILD_INTERFACE:${dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>") "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
target_include_directories(gtest_main SYSTEM INTERFACE target_include_directories(gtest_main SYSTEM INTERFACE
"$<BUILD_INTERFACE:${dirs}>" "$<BUILD_INTERFACE:${dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>") "$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
endif()
if(CMAKE_SYSTEM_NAME MATCHES "QNX") if(CMAKE_SYSTEM_NAME MATCHES "QNX")
target_link_libraries(gtest PUBLIC regex) target_link_libraries(gtest PUBLIC regex)
endif() endif()

View File

@ -12,14 +12,6 @@
# Test and Google Mock's option() definitions, and thus must be # Test and Google Mock's option() definitions, and thus must be
# called *after* the options have been defined. # called *after* the options have been defined.
if (POLICY CMP0054)
cmake_policy(SET CMP0054 NEW)
endif (POLICY CMP0054)
if (POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
endif (POLICY CMP0069)
# Tweaks CMake's default compiler/linker settings to suit Google Test's needs. # Tweaks CMake's default compiler/linker settings to suit Google Test's needs.
# #
# This must be a macro(), as inside a function string() can only # This must be a macro(), as inside a function string() can only
@ -196,23 +188,14 @@ function(cxx_library_with_type name type cxx_flags)
set_target_properties(${name} set_target_properties(${name}
PROPERTIES PROPERTIES
COMPILE_DEFINITIONS "GTEST_CREATE_SHARED_LIBRARY=1") COMPILE_DEFINITIONS "GTEST_CREATE_SHARED_LIBRARY=1")
if (NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
target_compile_definitions(${name} INTERFACE target_compile_definitions(${name} INTERFACE
$<INSTALL_INTERFACE:GTEST_LINKED_AS_SHARED_LIBRARY=1>) $<INSTALL_INTERFACE:GTEST_LINKED_AS_SHARED_LIBRARY=1>)
endif() endif()
endif()
if (DEFINED GTEST_HAS_PTHREAD) if (DEFINED GTEST_HAS_PTHREAD)
if ("${CMAKE_VERSION}" VERSION_LESS "3.1.0") target_link_libraries(${name} PUBLIC Threads::Threads)
set(threads_spec ${CMAKE_THREAD_LIBS_INIT})
else()
set(threads_spec Threads::Threads)
endif()
target_link_libraries(${name} PUBLIC ${threads_spec})
endif() endif()
if (NOT "${CMAKE_VERSION}" VERSION_LESS "3.8")
target_compile_features(${name} PUBLIC cxx_std_14) target_compile_features(${name} PUBLIC cxx_std_14)
endif()
endfunction() endfunction()
######################################################################## ########################################################################
@ -264,22 +247,7 @@ function(cxx_executable name dir libs)
${name} "${cxx_default}" "${libs}" "${dir}/${name}.cc" ${ARGN}) ${name} "${cxx_default}" "${libs}" "${dir}/${name}.cc" ${ARGN})
endfunction() endfunction()
# CMP0094 policy enables finding a Python executable in the LOCATION order, as find_package(Python3)
# specified by the PATH environment variable.
if (POLICY CMP0094)
cmake_policy(SET CMP0094 NEW)
endif()
# Sets PYTHONINTERP_FOUND and PYTHON_EXECUTABLE.
if ("${CMAKE_VERSION}" VERSION_LESS "3.12.0")
find_package(PythonInterp)
set(PYTHONINTERP_FOUND ${PYTHONINTERP_FOUND} CACHE INTERNAL "")
set(PYTHON_EXECUTABLE ${PYTHON_EXECUTABLE} CACHE INTERNAL "")
else()
find_package(Python COMPONENTS Interpreter)
set(PYTHONINTERP_FOUND ${Python_Interpreter_FOUND} CACHE INTERNAL "")
set(PYTHON_EXECUTABLE ${Python_EXECUTABLE} CACHE INTERNAL "")
endif()
# cxx_test_with_flags(name cxx_flags libs srcs...) # cxx_test_with_flags(name cxx_flags libs srcs...)
# #
@ -305,34 +273,22 @@ endfunction()
# creates a Python test with the given name whose main module is in # creates a Python test with the given name whose main module is in
# test/name.py. It does nothing if Python is not installed. # test/name.py. It does nothing if Python is not installed.
function(py_test name) function(py_test name)
if (PYTHONINTERP_FOUND) if (NOT Python3_Interpreter_FOUND)
if ("${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION}" VERSION_GREATER 3.1) return()
if (CMAKE_CONFIGURATION_TYPES)
# Multi-configuration build generators as for Visual Studio save
# output in a subdirectory of CMAKE_CURRENT_BINARY_DIR (Debug,
# Release etc.), so we have to provide it here.
add_test(NAME ${name}
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py
--build_dir=${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG> ${ARGN})
else (CMAKE_CONFIGURATION_TYPES)
# Single-configuration build generators like Makefile generators
# don't have subdirs below CMAKE_CURRENT_BINARY_DIR.
add_test(NAME ${name}
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py
--build_dir=${CMAKE_CURRENT_BINARY_DIR} ${ARGN})
endif (CMAKE_CONFIGURATION_TYPES)
else()
# ${CMAKE_CURRENT_BINARY_DIR} is known at configuration time, so we can
# directly bind it from cmake. ${CTEST_CONFIGURATION_TYPE} is known
# only at ctest runtime (by calling ctest -c <Configuration>), so
# we have to escape $ to delay variable substitution here.
add_test(NAME ${name}
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py
--build_dir=${CMAKE_CURRENT_BINARY_DIR}/\${CTEST_CONFIGURATION_TYPE} ${ARGN})
endif() endif()
get_cmake_property(is_multi "GENERATOR_IS_MULTI_CONFIG")
set(build_dir "${CMAKE_CURRENT_BINARY_DIR}")
if (is_multi)
set(build_dir "${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG>")
endif()
add_test(NAME ${name}
COMMAND Python3::Interpreter ${CMAKE_CURRENT_SOURCE_DIR}/test/${name}.py
--build_dir=${build_dir} ${ARGN})
# Make the Python import path consistent between Bazel and CMake. # Make the Python import path consistent between Bazel and CMake.
set_tests_properties(${name} PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_SOURCE_DIR}) set_tests_properties(${name} PROPERTIES ENVIRONMENT PYTHONPATH=${CMAKE_SOURCE_DIR})
endif(PYTHONINTERP_FOUND)
endfunction() endfunction()
# install_project(targets...) # install_project(targets...)