0
0
mirror of https://github.com/google/googletest.git synced 2025-03-19 10:23:48 +00:00

Manual docs tweaks still in preparation for including docs with code pushes

This commit is contained in:
Gennadiy Civil 2019-07-18 11:39:49 -04:00
parent 34ddfff946
commit 15756aa0c8
4 changed files with 98 additions and 66 deletions

View File

@ -215,7 +215,7 @@ and the default action will be taken each time.
### Matchers {#MatcherList} ### Matchers {#MatcherList}
<!-- GOOGLETEST_CM0019 DO NOT DELETE --> <!-- GOOGLETEST_CM0020 DO NOT DELETE -->
A **matcher** matches a *single* argument. You can use it inside `ON_CALL()` or A **matcher** matches a *single* argument. You can use it inside `ON_CALL()` or
`EXPECT_CALL()`, or use it to validate a value directly: `EXPECT_CALL()`, or use it to validate a value directly:
@ -341,65 +341,97 @@ write the elements in-line, match them more flexibly, or get more informative
messages, you can use: messages, you can use:
| Matcher | Description | | Matcher | Description |
| :----------------------------------- | :----------------------------------- | | :---------------------------------------- | :------------------------------- |
| `ContainerEq(container)` | The same as `Eq(container)` except | | `BeginEndDistanceIs(m)` | `argument` is a container whose |
: : that the failure message also : : : `begin()` and `end()` iterators :
: : includes which elements are in one : : : are separated by a number of :
: : container but not the other. : : : increments matching `m`. E.g. :
| `Contains(e)` | `argument` contains an element that | : : `BeginEndDistanceIs(2)` or :
: : matches `e`, which can be either a : : : `BeginEndDistanceIs(Lt(2))`. For :
: : value or a matcher. : : : containers that define a :
: : `size()` method, `SizeIs(m)` may :
: : be more efficient. :
| `ContainerEq(container)` | The same as `Eq(container)` |
: : except that the failure message :
: : also includes which elements are :
: : in one container but not the :
: : other. :
| `Contains(e)` | `argument` contains an element |
: : that matches `e`, which can be :
: : either a value or a matcher. :
| `Each(e)` | `argument` is a container where | | `Each(e)` | `argument` is a container where |
: : _every_ element matches `e`, which : : : *every* element matches `e`, :
: : can be either a value or a matcher. : : : which can be either a value or a :
: : matcher. :
| `ElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, | | `ElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, |
: : where the i-th element matches `ei`, : : : where the *i*-th element matches :
: : which can be a value or a matcher. 0 : : : `ei`, which can be a value or a :
: : to 10 arguments are allowed. : : : matcher. :
| `ElementsAreArray({ e0, e1, ..., en | The same as `ElementsAre()` except | | `ElementsAreArray({e0, e1, ..., en})`, | The same as `ElementsAre()` |
: })`, `ElementsAreArray(array)`, or : that the expected element : : `ElementsAreArray(a_container)`, : except that the expected element :
: `ElementsAreArray(array, count)` : values/matchers come from an : : `ElementsAreArray(begin, end)`, : values/matchers come from an :
: : initializer list, STL-style : : `ElementsAreArray(array)`, or : initializer list, STL-style :
: : container, or C-style array. : : `ElementsAreArray(array, count)` : container, iterator range, or :
: : C-style array. :
| `IsEmpty()` | `argument` is an empty container | | `IsEmpty()` | `argument` is an empty container |
: : (`container.empty()`). : : : (`container.empty()`). :
| `Pointwise(m, container)` | `argument` contains the same number | | `IsFalse()` | `argument` evaluates to `false` |
: : of elements as in `container`, and : : : in a Boolean context. :
: : for all i, (the i-th element in : | `IsSubsetOf({e0, e1, ..., en})`, | `argument` matches |
: : `argument`, the i-th element in : : `IsSubsetOf(a_container)`, : `UnorderedElementsAre(x0, x1, :
: : `container`) match `m`, which is a : : `IsSubsetOf(begin, end)`, : ..., xk)` for some subset `{x0, :
: : matcher on 2-tuples. E.g. : : `IsSubsetOf(array)`, or : x1, ..., xk}` of the expected :
: : `Pointwise(Le(), upper_bounds)` : : `IsSubsetOf(array, count)` : matchers. :
: : verifies that each element in : | `IsSupersetOf({e0, e1, ..., en})`, | Some subset of `argument` |
: : `argument` doesn't exceed the : : `IsSupersetOf(a_container)`, : matches :
: : corresponding element in : : `IsSupersetOf(begin, end)`, : `UnorderedElementsAre(`expected :
: : `upper_bounds`. See more detail : : `IsSupersetOf(array)`, or : matchers`)`. :
: : below. : : `IsSupersetOf(array, count)` : :
| `SizeIs(m)` | `argument` is a container whose size | | `IsTrue()` | `argument` evaluates to `true` |
: : matches `m`. E.g. `SizeIs(2)` or : : : in a Boolean context. :
: : `SizeIs(Lt(2))`. : | `Pointwise(m, container)`, `Pointwise(m, | `argument` contains the same |
| `UnorderedElementsAre(e0, e1, ..., | `argument` has `n + 1` elements, and | : {e0, e1, ..., en})` : number of elements as in :
: en)` : under some permutation each element : : : `container`, and for all i, (the :
: : i-th element in `argument`, the :
: : i-th element in `container`) :
: : match `m`, which is a matcher on :
: : 2-tuples. E.g. `Pointwise(Le(), :
: : upper_bounds)` verifies that :
: : each element in `argument` :
: : doesn't exceed the corresponding :
: : element in `upper_bounds`. See :
: : more detail below. :
| `SizeIs(m)` | `argument` is a container whose |
: : size matches `m`. E.g. :
: : `SizeIs(2)` or `SizeIs(Lt(2))`. :
| `UnorderedElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, |
: : and under *some* permutation of :
: : the elements, each element :
: : matches an `ei` (for a different : : : matches an `ei` (for a different :
: : `i`), which can be a value or a : : : `i`), which can be a value or a :
: : matcher. 0 to 10 arguments are : : : matcher. :
: : allowed. : | `UnorderedElementsAreArray({e0, e1, ..., | The same as |
| `UnorderedElementsAreArray({ e0, e1, | The same as `UnorderedElementsAre()` | : en})`, : `UnorderedElementsAre()` except :
: ..., en })`, : except that the expected element : : `UnorderedElementsAreArray(a_container)`, : that the expected element :
: `UnorderedElementsAreArray(array)`, : values/matchers come from an : : `UnorderedElementsAreArray(begin, end)`, : values/matchers come from an :
: or `UnorderedElementsAreArray(array, : initializer list, STL-style : : `UnorderedElementsAreArray(array)`, or : initializer list, STL-style :
: count)` : container, or C-style array. : : `UnorderedElementsAreArray(array, count)` : container, iterator range, or :
| `WhenSorted(m)` | When `argument` is sorted using the | : : C-style array. :
: : `<` operator, it matches container : | `UnorderedPointwise(m, container)`, | Like `Pointwise(m, container)`, |
: : matcher `m`. E.g. : : `UnorderedPointwise(m, {e0, e1, ..., : but ignores the order of :
: : `WhenSorted(ElementsAre(1, 2, 3))` : : en})` : elements. :
: : verifies that `argument` contains : | `WhenSorted(m)` | When `argument` is sorted using |
: : elements `1`, `2`, and `3`, ignoring : : : the `<` operator, it matches :
: : order. : : : container matcher `m`. E.g. :
| `WhenSortedBy(comparator, m)` | The same as `WhenSorted(m)`, except | : : `WhenSorted(ElementsAre(1, 2, :
: : that the given comparator instead of : : : 3))` verifies that `argument` :
: : `<` is used to sort `argument`. E.g. : : : contains elements 1, 2, and 3, :
: : `WhenSortedBy(std\:\:greater<int>(), : : : ignoring order. :
| `WhenSortedBy(comparator, m)` | The same as `WhenSorted(m)`, |
: : except that the given comparator :
: : instead of `<` is used to sort :
: : `argument`. E.g. :
: : `WhenSortedBy(std\:\:greater(), :
: : ElementsAre(3, 2, 1))`. : : : ElementsAre(3, 2, 1))`. :
**Notes:** **Notes:**

View File

@ -154,7 +154,7 @@ class MockStack : public StackInterface<Elem> {
#### Mocking Non-virtual Methods {#MockingNonVirtualMethods} #### Mocking Non-virtual Methods {#MockingNonVirtualMethods}
gMock can mock non-virtual functions to be used in Hi-perf dependency gMock can mock non-virtual functions to be used in Hi-perf dependency
injection.<!-- GOOGLETEST_CM0016 DO NOT DELETE -->. injection.<!-- GOOGLETEST_CM0017 DO NOT DELETE -->.
In this case, instead of sharing a common base class with the real class, your In this case, instead of sharing a common base class with the real class, your
mock class will be *unrelated* to the real class, but contain methods with the mock class will be *unrelated* to the real class, but contain methods with the
@ -1455,7 +1455,7 @@ mock object and gMock.
#### Knowing When to Expect {#UseOnCall} #### Knowing When to Expect {#UseOnCall}
<!-- GOOGLETEST_CM0017 DO NOT DELETE --> <!-- GOOGLETEST_CM0018 DO NOT DELETE -->
**`ON_CALL`** is likely the *single most under-utilized construct* in gMock. **`ON_CALL`** is likely the *single most under-utilized construct* in gMock.

View File

@ -499,7 +499,7 @@ always return 100 as `n++` is only evaluated once. Similarly, `Return(new Foo)`
will create a new `Foo` object when the `EXPECT_CALL()` is executed, and will will create a new `Foo` object when the `EXPECT_CALL()` is executed, and will
return the same pointer every time. If you want the side effect to happen every return the same pointer every time. If you want the side effect to happen every
time, you need to define a custom action, which we'll teach in the time, you need to define a custom action, which we'll teach in the
[cook book](http://<!-- GOOGLETEST_CM0011 DO NOT DELETE -->). [cook book](http://<!-- GOOGLETEST_CM0012 DO NOT DELETE -->).
Time for another quiz! What do you think the following means? Time for another quiz! What do you think the following means?

View File

@ -332,7 +332,7 @@ You may still want to use `SetUp()/TearDown()` in the following cases:
* In the body of a constructor (or destructor), it's not possible to use the * In the body of a constructor (or destructor), it's not possible to use the
`ASSERT_xx` macros. Therefore, if the set-up operation could cause a fatal `ASSERT_xx` macros. Therefore, if the set-up operation could cause a fatal
test failure that should prevent the test from running, it's necessary to test failure that should prevent the test from running, it's necessary to
use `abort` <!-- GOOGLETEST_CM0014 DO NOT DELETE --> and abort the whole test executable, use `abort` <!-- GOOGLETEST_CM0015 DO NOT DELETE --> and abort the whole test executable,
or to use `SetUp()` instead of a constructor. or to use `SetUp()` instead of a constructor.
* If the tear-down operation could throw an exception, you must use * If the tear-down operation could throw an exception, you must use
`TearDown()` as opposed to the destructor, as throwing in a destructor leads `TearDown()` as opposed to the destructor, as throwing in a destructor leads