Skip to content

Commit b2a2d36

Browse files
authored
Merge branch 'google:main' into feat/qn9090
2 parents e3d405f + ec4fed9 commit b2a2d36

17 files changed

+151
-199
lines changed

.gitignore

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,10 @@ Win32-Release/
2424
x64-Debug/
2525
x64-Release/
2626

27+
# VSCode files
28+
.cache/
29+
cmake-variants.yaml
30+
2731
# Ignore autoconf / automake files
2832
Makefile.in
2933
aclocal.m4

CMakeLists.txt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,7 @@
11
# Note: CMake support is community-based. The maintainers do not use CMake
22
# internally.
33

4-
cmake_minimum_required(VERSION 3.5)
5-
6-
if (POLICY CMP0048)
7-
cmake_policy(SET CMP0048 NEW)
8-
endif (POLICY CMP0048)
9-
10-
if (POLICY CMP0069)
11-
cmake_policy(SET CMP0069 NEW)
12-
endif (POLICY CMP0069)
13-
14-
if (POLICY CMP0077)
15-
cmake_policy(SET CMP0077 NEW)
16-
endif (POLICY CMP0077)
4+
cmake_minimum_required(VERSION 3.13)
175

186
project(googletest-distribution)
197
set(GOOGLETEST_VERSION 1.13.0)

README.md

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@ The 1.13.x branch requires at least C++14.
2727
#### Continuous Integration
2828

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

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

55-
| Feature | Description |
56-
| ---------------------------- | --------------------------------------------- |
57-
| xUnit test framework | Googletest is based on the |
58-
: : [xUnit](https\://en.wikipedia.org/wiki/XUnit) :
59-
: : testing framework, a popular architecture for :
60-
: : unit testing :
61-
| Test discovery | Googletest automatically discovers and runs |
62-
: : your tests, eliminating the need to manually :
63-
: : register your tests :
64-
| Rich set of assertions | Googletest provides a variety of assertions, |
65-
: : such as equality, inequality, exceptions, and :
66-
: : more, making it easy to test your code :
67-
| User-defined assertions | You can define your own assertions with |
68-
: : Googletest, making it simple to write tests :
69-
: : that are specific to your code :
70-
| Death tests | Googletest supports death tests, which verify |
71-
: : that your code exits in a certain way, making :
72-
: : it useful for testing error-handling code :
73-
| Fatal and non-fatal failures | You can specify whether a test failure should |
74-
: : be treated as fatal or non-fatal with :
75-
: : Googletest, allowing tests to continue :
76-
: : running even if a failure occurs :
77-
| Value-parameterized tests | Googletest supports value-parameterized |
78-
: : tests, which run multiple times with :
79-
: : different input values, making it useful for :
80-
: : testing functions that take different inputs :
81-
| Type-parameterized tests | Googletest also supports type-parameterized |
82-
: : tests, which run with different data types, :
83-
: : making it useful for testing functions that :
84-
: : work with different data types :
85-
| Various options for running | Googletest provides many options for running |
86-
: tests : tests, including running individual tests, :
87-
: : running tests in a specific order, and :
88-
: : running tests in parallel :
55+
## Features
56+
57+
* xUnit test framework: \
58+
Googletest is based on the [xUnit](https://en.wikipedia.org/wiki/XUnit)
59+
testing framework, a popular architecture for unit testing
60+
* Test discovery: \
61+
Googletest automatically discovers and runs your tests, eliminating the need
62+
to manually register your tests
63+
* Rich set of assertions: \
64+
Googletest provides a variety of assertions, such as equality, inequality,
65+
exceptions, and more, making it easy to test your code
66+
* User-defined assertions: \
67+
You can define your own assertions with Googletest, making it simple to
68+
write tests that are specific to your code
69+
* Death tests: \
70+
Googletest supports death tests, which verify that your code exits in a
71+
certain way, making it useful for testing error-handling code
72+
* Fatal and non-fatal failures: \
73+
You can specify whether a test failure should be treated as fatal or
74+
non-fatal with Googletest, allowing tests to continue running even if a
75+
failure occurs
76+
* Value-parameterized tests: \
77+
Googletest supports value-parameterized tests, which run multiple times with
78+
different input values, making it useful for testing functions that take
79+
different inputs
80+
* Type-parameterized tests: \
81+
Googletest also supports type-parameterized tests, which run with different
82+
data types, making it useful for testing functions that work with different
83+
data types
84+
* Various options for running tests: \
85+
Googletest provides many options for running tests including running
86+
individual tests, running tests in a specific order and running tests in
87+
parallel
8988

9089
## Supported Platforms
9190

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

9998
## Who Is Using GoogleTest?

docs/gmock_cook_book.md

Lines changed: 24 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -697,9 +697,9 @@ TEST(AbcTest, Xyz) {
697697
EXPECT_CALL(foo, DoThat(_, _));
698698

699699
int n = 0;
700-
EXPECT_EQ('+', foo.DoThis(5)); // FakeFoo::DoThis() is invoked.
700+
EXPECT_EQ(foo.DoThis(5), '+'); // FakeFoo::DoThis() is invoked.
701701
foo.DoThat("Hi", &n); // FakeFoo::DoThat() is invoked.
702-
EXPECT_EQ(2, n);
702+
EXPECT_EQ(n, 2);
703703
}
704704
```
705705

@@ -1129,11 +1129,11 @@ using STL's `<functional>` header is just painful). For example, here's a
11291129
predicate that's satisfied by any number that is >= 0, <= 100, and != 50:
11301130

11311131
```cpp
1132-
using testing::AllOf;
1133-
using testing::Ge;
1134-
using testing::Le;
1135-
using testing::Matches;
1136-
using testing::Ne;
1132+
using ::testing::AllOf;
1133+
using ::testing::Ge;
1134+
using ::testing::Le;
1135+
using ::testing::Matches;
1136+
using ::testing::Ne;
11371137
...
11381138
Matches(AllOf(Ge(0), Le(100), Ne(50)))
11391139
```
@@ -1861,7 +1861,7 @@ error. So, what shall you do?
18611861
Though you may be tempted, DO NOT use `std::ref()`:
18621862

18631863
```cpp
1864-
using testing::Return;
1864+
using ::testing::Return;
18651865

18661866
class MockFoo : public Foo {
18671867
public:
@@ -1873,7 +1873,7 @@ class MockFoo : public Foo {
18731873
EXPECT_CALL(foo, GetValue())
18741874
.WillRepeatedly(Return(std::ref(x))); // Wrong!
18751875
x = 42;
1876-
EXPECT_EQ(42, foo.GetValue());
1876+
EXPECT_EQ(foo.GetValue(), 42);
18771877
```
18781878

18791879
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.
18951895
returns the value pointed to by `pointer` at the time the action is *executed*:
18961896

18971897
```cpp
1898-
using testing::ReturnPointee;
1898+
using ::testing::ReturnPointee;
18991899
...
19001900
int x = 0;
19011901
MockFoo foo;
19021902
EXPECT_CALL(foo, GetValue())
19031903
.WillRepeatedly(ReturnPointee(&x)); // Note the & here.
19041904
x = 42;
1905-
EXPECT_EQ(42, foo.GetValue()); // This will succeed now.
1905+
EXPECT_EQ(foo.GetValue(), 42); // This will succeed now.
19061906
```
19071907

19081908
### Combining Actions
@@ -2264,7 +2264,7 @@ TEST_F(FooTest, Test) {
22642264

22652265
EXPECT_CALL(foo, DoThis(2))
22662266
.WillOnce(Invoke(NewPermanentCallback(SignOfSum, 5)));
2267-
EXPECT_EQ('+', foo.DoThis(2)); // Invokes SignOfSum(5, 2).
2267+
EXPECT_EQ(foo.DoThis(2), '+'); // Invokes SignOfSum(5, 2).
22682268
}
22692269
```
22702270

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

27732773
```cpp
2774+
using ::testing::IsNull;
2775+
...
27742776
// Use the default action.
27752777
EXPECT_CALL(mock_buzzer_, MakeBuzz("hello"));
27762778

27772779
// Triggers the previous EXPECT_CALL.
2778-
EXPECT_EQ(nullptr, mock_buzzer_.MakeBuzz("hello"));
2780+
EXPECT_THAT(mock_buzzer_.MakeBuzz("hello"), IsNull());
27792781
```
27802782

27812783
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:
31943196
```cpp
31953197
#include "gmock/gmock.h"
31963198

3197-
using testing::_;
3198-
using testing::HasSubstr;
3199-
using testing::Return;
3199+
using ::testing::_;
3200+
using ::testing::HasSubstr;
3201+
using ::testing::Return;
32003202

32013203
class MockFoo {
32023204
public:
@@ -3817,15 +3819,15 @@ If the built-in actions don't work for you, you can easily define your own one.
38173819
All you need is a call operator with a signature compatible with the mocked
38183820
function. So you can use a lambda:
38193821

3820-
```
3822+
```cpp
38213823
MockFunction<int(int)> mock;
38223824
EXPECT_CALL(mock, Call).WillOnce([](const int input) { return input * 7; });
3823-
EXPECT_EQ(14, mock.AsStdFunction()(2));
3825+
EXPECT_EQ(mock.AsStdFunction()(2), 14);
38243826
```
38253827

38263828
Or a struct with a call operator (even a templated one):
38273829

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

3843-
```
3845+
```cpp
38443846
MockFunction<int(int)> mock;
38453847
EXPECT_CALL(mock, Call).WillOnce([] { return 17; });
3846-
EXPECT_EQ(17, mock.AsStdFunction()(0));
3848+
EXPECT_EQ(mock.AsStdFunction()(0), 17);
38473849
```
38483850

38493851
When used with `WillOnce`, the callable can assume it will be called at most
38503852
once and is allowed to be a move-only type:
38513853

3852-
```
3854+
```cpp
38533855
// An action that contains move-only types and has an &&-qualified operator,
38543856
// demanding in the type system that it be called at most once. This can be
38553857
// used with WillOnce, but the compiler will reject it if handed to

docs/pkgconfig.md

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -19,19 +19,15 @@ examples here we assume you want to compile the sample
1919
Using `pkg-config` in CMake is fairly easy:
2020

2121
```cmake
22-
cmake_minimum_required(VERSION 3.0)
23-
24-
cmake_policy(SET CMP0048 NEW)
25-
project(my_gtest_pkgconfig VERSION 0.0.1 LANGUAGES CXX)
26-
2722
find_package(PkgConfig)
2823
pkg_search_module(GTEST REQUIRED gtest_main)
2924
30-
add_executable(testapp samples/sample3_unittest.cc)
31-
target_link_libraries(testapp ${GTEST_LDFLAGS})
32-
target_compile_options(testapp PUBLIC ${GTEST_CFLAGS})
25+
add_executable(testapp)
26+
target_sources(testapp PRIVATE samples/sample3_unittest.cc)
27+
target_link_libraries(testapp PRIVATE ${GTEST_LDFLAGS})
28+
target_compile_options(testapp PRIVATE ${GTEST_CFLAGS})
3329
34-
include(CTest)
30+
enable_testing()
3531
add_test(first_and_only_test testapp)
3632
```
3733

docs/primer.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ Since GoogleTest is based on the popular xUnit architecture, you'll feel right
4242
at home if you've used JUnit or PyUnit before. If not, it will take you about 10
4343
minutes to learn the basics and get started. So let's go!
4444

45-
## Beware of the nomenclature
45+
## Beware of the Nomenclature
4646

4747
{: .callout .note}
4848
*Note:* There might be some confusion arising from different definitions of the

googlemock/CMakeLists.txt

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,7 @@ endif()
3636
# as ${gmock_SOURCE_DIR} and to the root binary directory as
3737
# ${gmock_BINARY_DIR}.
3838
# Language "C" is required for find_package(Threads).
39-
cmake_minimum_required(VERSION 3.5)
40-
cmake_policy(SET CMP0048 NEW)
39+
cmake_minimum_required(VERSION 3.13)
4140
project(gmock VERSION ${GOOGLETEST_VERSION} LANGUAGES CXX C)
4241

4342
if (COMMAND set_up_hermetic_build)
@@ -101,18 +100,14 @@ else()
101100
target_link_libraries(gmock_main PUBLIC gmock)
102101
set_target_properties(gmock_main PROPERTIES VERSION ${GOOGLETEST_VERSION})
103102
endif()
104-
# If the CMake version supports it, attach header directory information
105-
# to the targets for when we are part of a parent build (ie being pulled
106-
# in via add_subdirectory() rather than being a standalone build).
107-
if (DEFINED CMAKE_VERSION AND NOT "${CMAKE_VERSION}" VERSION_LESS "2.8.11")
108-
string(REPLACE ";" "$<SEMICOLON>" dirs "${gmock_build_include_dirs}")
109-
target_include_directories(gmock SYSTEM INTERFACE
110-
"$<BUILD_INTERFACE:${dirs}>"
111-
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
112-
target_include_directories(gmock_main SYSTEM INTERFACE
113-
"$<BUILD_INTERFACE:${dirs}>"
114-
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
115-
endif()
103+
104+
string(REPLACE ";" "$<SEMICOLON>" dirs "${gmock_build_include_dirs}")
105+
target_include_directories(gmock SYSTEM INTERFACE
106+
"$<BUILD_INTERFACE:${dirs}>"
107+
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
108+
target_include_directories(gmock_main SYSTEM INTERFACE
109+
"$<BUILD_INTERFACE:${dirs}>"
110+
"$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}>")
116111

117112
########################################################################
118113
#
@@ -136,11 +131,7 @@ if (gmock_build_tests)
136131
enable_testing()
137132

138133
if (MINGW OR CYGWIN)
139-
if (CMAKE_VERSION VERSION_LESS "2.8.12")
140-
add_compile_options("-Wa,-mbig-obj")
141-
else()
142-
add_definitions("-Wa,-mbig-obj")
143-
endif()
134+
add_compile_options("-Wa,-mbig-obj")
144135
endif()
145136

146137
############################################################

0 commit comments

Comments
 (0)