Skip to content

Commit

Permalink
Merge branch 'google:main' into feat/qn9090
Browse files Browse the repository at this point in the history
  • Loading branch information
ciband committed Jun 22, 2023
2 parents e3d405f + ec4fed9 commit b2a2d36
Show file tree
Hide file tree
Showing 17 changed files with 151 additions and 199 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ Win32-Release/
x64-Debug/
x64-Release/

# VSCode files
.cache/
cmake-variants.yaml

# Ignore autoconf / automake files
Makefile.in
aclocal.m4
Expand Down
14 changes: 1 addition & 13 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,19 +1,7 @@
# Note: CMake support is community-based. The maintainers do not use CMake
# internally.

cmake_minimum_required(VERSION 3.5)

if (POLICY CMP0048)
cmake_policy(SET CMP0048 NEW)
endif (POLICY CMP0048)

if (POLICY CMP0069)
cmake_policy(SET CMP0069 NEW)
endif (POLICY CMP0069)

if (POLICY CMP0077)
cmake_policy(SET CMP0077 NEW)
endif (POLICY CMP0077)
cmake_minimum_required(VERSION 3.13)

project(googletest-distribution)
set(GOOGLETEST_VERSION 1.13.0)
Expand Down
73 changes: 36 additions & 37 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ The 1.13.x branch requires at least C++14.
#### Continuous Integration

We use Google's internal systems for continuous integration. \
GitHub Actions were added for the convenience of open source contributors. They
are exclusively maintained by the open source community and not used by the
GitHub Actions were added for the convenience of open-source contributors. They
are exclusively maintained by the open-source community and not used by the
GoogleTest team.

#### Coming Soon
Expand All @@ -52,48 +52,47 @@ documentation. We recommend starting with the
More information about building GoogleTest can be found at
[googletest/README.md](googletest/README.md).

| Feature | Description |
| ---------------------------- | --------------------------------------------- |
| xUnit test framework | Googletest is based on the |
: : [xUnit](https\://en.wikipedia.org/wiki/XUnit) :
: : testing framework, a popular architecture for :
: : unit testing :
| Test discovery | Googletest automatically discovers and runs |
: : your tests, eliminating the need to manually :
: : register your tests :
| Rich set of assertions | Googletest provides a variety of assertions, |
: : such as equality, inequality, exceptions, and :
: : more, making it easy to test your code :
| User-defined assertions | You can define your own assertions with |
: : Googletest, making it simple to write tests :
: : that are specific to your code :
| Death tests | Googletest supports death tests, which verify |
: : that your code exits in a certain way, making :
: : it useful for testing error-handling code :
| Fatal and non-fatal failures | You can specify whether a test failure should |
: : be treated as fatal or non-fatal with :
: : Googletest, allowing tests to continue :
: : running even if a failure occurs :
| Value-parameterized tests | Googletest supports value-parameterized |
: : tests, which run multiple times with :
: : different input values, making it useful for :
: : testing functions that take different inputs :
| Type-parameterized tests | Googletest also supports type-parameterized |
: : tests, which run with different data types, :
: : making it useful for testing functions that :
: : work with different data types :
| Various options for running | Googletest provides many options for running |
: tests : tests, including running individual tests, :
: : running tests in a specific order, and :
: : running tests in parallel :
## Features

* xUnit test framework: \
Googletest is based on the [xUnit](https://en.wikipedia.org/wiki/XUnit)
testing framework, a popular architecture for unit testing
* Test discovery: \
Googletest automatically discovers and runs your tests, eliminating the need
to manually register your tests
* Rich set of assertions: \
Googletest provides a variety of assertions, such as equality, inequality,
exceptions, and more, making it easy to test your code
* User-defined assertions: \
You can define your own assertions with Googletest, making it simple to
write tests that are specific to your code
* Death tests: \
Googletest supports death tests, which verify that your code exits in a
certain way, making it useful for testing error-handling code
* Fatal and non-fatal failures: \
You can specify whether a test failure should be treated as fatal or
non-fatal with Googletest, allowing tests to continue running even if a
failure occurs
* Value-parameterized tests: \
Googletest supports value-parameterized tests, which run multiple times with
different input values, making it useful for testing functions that take
different inputs
* Type-parameterized tests: \
Googletest also supports type-parameterized tests, which run with different
data types, making it useful for testing functions that work with different
data types
* Various options for running tests: \
Googletest provides many options for running tests including running
individual tests, running tests in a specific order and running tests in
parallel

## Supported Platforms

GoogleTest follows Google's
[Foundational C++ Support Policy](https://opensource.google/documentation/policies/cplusplus-support).
See
[this table](https://github.com/google/oss-policies-info/blob/main/foundational-cxx-support-matrix.md)
for a list of currently supported versions compilers, platforms, and build
for a list of currently supported versions of compilers, platforms, and build
tools.

## Who Is Using GoogleTest?
Expand Down
46 changes: 24 additions & 22 deletions docs/gmock_cook_book.md
Original file line number Diff line number Diff line change
Expand Up @@ -697,9 +697,9 @@ TEST(AbcTest, Xyz) {
EXPECT_CALL(foo, DoThat(_, _));

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.
EXPECT_EQ(2, n);
EXPECT_EQ(n, 2);
}
```

Expand Down Expand Up @@ -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:

```cpp
using testing::AllOf;
using testing::Ge;
using testing::Le;
using testing::Matches;
using testing::Ne;
using ::testing::AllOf;
using ::testing::Ge;
using ::testing::Le;
using ::testing::Matches;
using ::testing::Ne;
...
Matches(AllOf(Ge(0), Le(100), Ne(50)))
```
Expand Down Expand Up @@ -1861,7 +1861,7 @@ error. So, what shall you do?
Though you may be tempted, DO NOT use `std::ref()`:

```cpp
using testing::Return;
using ::testing::Return;

class MockFoo : public Foo {
public:
Expand All @@ -1873,7 +1873,7 @@ class MockFoo : public Foo {
EXPECT_CALL(foo, GetValue())
.WillRepeatedly(Return(std::ref(x))); // Wrong!
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:
Expand All @@ -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*:

```cpp
using testing::ReturnPointee;
using ::testing::ReturnPointee;
...
int x = 0;
MockFoo foo;
EXPECT_CALL(foo, GetValue())
.WillRepeatedly(ReturnPointee(&x)); // Note the & here.
x = 42;
EXPECT_EQ(42, foo.GetValue()); // This will succeed now.
EXPECT_EQ(foo.GetValue(), 42); // This will succeed now.
```

### Combining Actions
Expand Down Expand Up @@ -2264,7 +2264,7 @@ TEST_F(FooTest, Test) {

EXPECT_CALL(foo, DoThis(2))
.WillOnce(Invoke(NewPermanentCallback(SignOfSum, 5)));
EXPECT_EQ('+', foo.DoThis(2)); // Invokes SignOfSum(5, 2).
EXPECT_EQ(foo.DoThis(2), '+'); // Invokes SignOfSum(5, 2).
}
```

Expand Down Expand Up @@ -2771,11 +2771,13 @@ returns a null `unique_ptr`, that’s what you’ll get if you don’t specify a
action:

```cpp
using ::testing::IsNull;
...
// Use the default action.
EXPECT_CALL(mock_buzzer_, MakeBuzz("hello"));

// 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
Expand Down Expand Up @@ -3194,9 +3196,9 @@ flag. For example, given the test program:
```cpp
#include "gmock/gmock.h"

using testing::_;
using testing::HasSubstr;
using testing::Return;
using ::testing::_;
using ::testing::HasSubstr;
using ::testing::Return;

class MockFoo {
public:
Expand Down Expand Up @@ -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
function. So you can use a lambda:

```
```cpp
MockFunction<int(int)> mock;
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):

```
```cpp
struct MultiplyBy {
template <typename T>
T operator()(T arg) { return arg * multiplier; }
Expand All @@ -3840,16 +3842,16 @@ struct MultiplyBy {
It's also fine for the callable to take no arguments, ignoring the arguments
supplied to the mock function:

```
```cpp
MockFunction<int(int)> mock;
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
once and is allowed to be a move-only type:

```
```cpp
// 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
// used with WillOnce, but the compiler will reject it if handed to
Expand Down
14 changes: 5 additions & 9 deletions docs/pkgconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,15 @@ examples here we assume you want to compile the sample
Using `pkg-config` in CMake is fairly easy:

```cmake
cmake_minimum_required(VERSION 3.0)
cmake_policy(SET CMP0048 NEW)
project(my_gtest_pkgconfig VERSION 0.0.1 LANGUAGES CXX)
find_package(PkgConfig)
pkg_search_module(GTEST REQUIRED gtest_main)
add_executable(testapp samples/sample3_unittest.cc)
target_link_libraries(testapp ${GTEST_LDFLAGS})
target_compile_options(testapp PUBLIC ${GTEST_CFLAGS})
add_executable(testapp)
target_sources(testapp PRIVATE samples/sample3_unittest.cc)
target_link_libraries(testapp PRIVATE ${GTEST_LDFLAGS})
target_compile_options(testapp PRIVATE ${GTEST_CFLAGS})
include(CTest)
enable_testing()
add_test(first_and_only_test testapp)
```

Expand Down
2 changes: 1 addition & 1 deletion docs/primer.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ Since GoogleTest is based on the popular xUnit architecture, you'll feel right
at home if you've used JUnit or PyUnit before. If not, it will take you about 10
minutes to learn the basics and get started. So let's go!

## Beware of the nomenclature
## Beware of the Nomenclature

{: .callout .note}
*Note:* There might be some confusion arising from different definitions of the
Expand Down
29 changes: 10 additions & 19 deletions googlemock/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ endif()
# as ${gmock_SOURCE_DIR} and to the root binary directory as
# ${gmock_BINARY_DIR}.
# Language "C" is required for find_package(Threads).
cmake_minimum_required(VERSION 3.5)
cmake_policy(SET CMP0048 NEW)
cmake_minimum_required(VERSION 3.13)
project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)

if (COMMAND set_up_hermetic_build)
Expand Down Expand Up @@ -101,18 +100,14 @@ else()
target_link_libraries(gmock_main PUBLIC gmock)
set_target_properties(gmock_main PROPERTIES VERSION ${GOOGLETEST_VERSION})
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
# 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 "${gmock_build_include_dirs}")
target_include_directories(gmock SYSTEM INTERFACE
"$<BUILD_INTERFACE:${dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
target_include_directories(gmock_main SYSTEM INTERFACE
"$<BUILD_INTERFACE:${dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
endif()

string(REPLACE ";" "$<SEMICOLON>" dirs "${gmock_build_include_dirs}")
target_include_directories(gmock SYSTEM INTERFACE
"$<BUILD_INTERFACE:${dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
target_include_directories(gmock_main SYSTEM INTERFACE
"$<BUILD_INTERFACE:${dirs}>"
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")

########################################################################
#
Expand All @@ -136,11 +131,7 @@ if (gmock_build_tests)
enable_testing()

if (MINGW OR CYGWIN)
if (CMAKE_VERSION VERSION_LESS "2.8.12")
add_compile_options("-Wa,-mbig-obj")
else()
add_definitions("-Wa,-mbig-obj")
endif()
add_compile_options("-Wa,-mbig-obj")
endif()

############################################################
Expand Down
Loading

0 comments on commit b2a2d36

Please sign in to comment.