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:
@ -340,67 +340,99 @@ or simply `expected_container` to match a container exactly. If you want to
write the elements in-line, match them more flexibly, or get more informative 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 :
| `Each(e)` | `argument` is a container where | : : `size()` method, `SizeIs(m)` may :
: : _every_ element matches `e`, which : : : be more efficient. :
: : can be either a value or a matcher. : | `ContainerEq(container)` | The same as `Eq(container)` |
| `ElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, | : : except that the failure message :
: : where the i-th element matches `ei`, : : : also includes which elements are :
: : which can be a value or a matcher. 0 : : : in one container but not the :
: : to 10 arguments are allowed. : : : other. :
| `ElementsAreArray({ e0, e1, ..., en | The same as `ElementsAre()` except | | `Contains(e)` | `argument` contains an element |
: })`, `ElementsAreArray(array)`, or : that the expected element : : : that matches `e`, which can be :
: `ElementsAreArray(array, count)` : values/matchers come from an : : : either a value or a matcher. :
: : initializer list, STL-style : | `Each(e)` | `argument` is a container where |
: : container, or C-style array. : : : *every* element matches `e`, :
| `IsEmpty()` | `argument` is an empty container | : : which can be either a value or a :
: : (`container.empty()`). : : : matcher. :
| `Pointwise(m, container)` | `argument` contains the same number | | `ElementsAre(e0, e1, ..., en)` | `argument` has `n + 1` elements, |
: : of elements as in `container`, and : : : where the *i*-th element matches :
: : for all i, (the i-th element in : : : `ei`, which can be a value or a :
: : `argument`, the i-th element in : : : matcher. :
: : `container`) match `m`, which is a : | `ElementsAreArray({e0, e1, ..., en})`, | The same as `ElementsAre()` |
: : matcher on 2-tuples. E.g. : : `ElementsAreArray(a_container)`, : except that the expected element :
: : `Pointwise(Le(), upper_bounds)` : : `ElementsAreArray(begin, end)`, : values/matchers come from an :
: : verifies that each element in : : `ElementsAreArray(array)`, or : initializer list, STL-style :
: : `argument` doesn't exceed the : : `ElementsAreArray(array, count)` : container, iterator range, or :
: : corresponding element in : : : C-style array. :
: : `upper_bounds`. See more detail : | `IsEmpty()` | `argument` is an empty container |
: : below. : : : (`container.empty()`). :
| `SizeIs(m)` | `argument` is a container whose size | | `IsFalse()` | `argument` evaluates to `false` |
: : matches `m`. E.g. `SizeIs(2)` or : : : in a Boolean context. :
: : `SizeIs(Lt(2))`. : | `IsSubsetOf({e0, e1, ..., en})`, | `argument` matches |
| `UnorderedElementsAre(e0, e1, ..., | `argument` has `n + 1` elements, and | : `IsSubsetOf(a_container)`, : `UnorderedElementsAre(x0, x1, :
: en)` : under some permutation each element : : `IsSubsetOf(begin, end)`, : ..., xk)` for some subset `{x0, :
: : matches an `ei` (for a different : : `IsSubsetOf(array)`, or : x1, ..., xk}` of the expected :
: : `i`), which can be a value or a : : `IsSubsetOf(array, count)` : matchers. :
: : matcher. 0 to 10 arguments are : | `IsSupersetOf({e0, e1, ..., en})`, | Some subset of `argument` |
: : allowed. : : `IsSupersetOf(a_container)`, : matches :
| `UnorderedElementsAreArray({ e0, e1, | The same as `UnorderedElementsAre()` | : `IsSupersetOf(begin, end)`, : `UnorderedElementsAre(`expected :
: ..., en })`, : except that the expected element : : `IsSupersetOf(array)`, or : matchers`)`. :
: `UnorderedElementsAreArray(array)`, : values/matchers come from an : : `IsSupersetOf(array, count)` : :
: or `UnorderedElementsAreArray(array, : initializer list, STL-style : | `IsTrue()` | `argument` evaluates to `true` |
: count)` : container, or C-style array. : : : in a Boolean context. :
| `WhenSorted(m)` | When `argument` is sorted using the | | `Pointwise(m, container)`, `Pointwise(m, | `argument` contains the same |
: : `<` operator, it matches container : : {e0, e1, ..., en})` : number of elements as in :
: : matcher `m`. E.g. : : : `container`, and for all i, (the :
: : `WhenSorted(ElementsAre(1, 2, 3))` : : : i-th element in `argument`, the :
: : verifies that `argument` contains : : : i-th element in `container`) :
: : elements `1`, `2`, and `3`, ignoring : : : match `m`, which is a matcher on :
: : order. : : : 2-tuples. E.g. `Pointwise(Le(), :
| `WhenSortedBy(comparator, m)` | The same as `WhenSorted(m)`, except | : : upper_bounds)` verifies that :
: : that the given comparator instead of : : : each element in `argument` :
: : `<` is used to sort `argument`. E.g. : : : doesn't exceed the corresponding :
: : `WhenSortedBy(std\:\:greater<int>(), : : : element in `upper_bounds`. See :
: : ElementsAre(3, 2, 1))`. : : : 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 :
: : `i`), which can be a value or a :
: : matcher. :
| `UnorderedElementsAreArray({e0, e1, ..., | The same as |
: en})`, : `UnorderedElementsAre()` except :
: `UnorderedElementsAreArray(a_container)`, : that the expected element :
: `UnorderedElementsAreArray(begin, end)`, : values/matchers come from an :
: `UnorderedElementsAreArray(array)`, or : initializer list, STL-style :
: `UnorderedElementsAreArray(array, count)` : container, iterator range, or :
: : C-style array. :
| `UnorderedPointwise(m, container)`, | Like `Pointwise(m, container)`, |
: `UnorderedPointwise(m, {e0, e1, ..., : but ignores the order of :
: en})` : elements. :
| `WhenSorted(m)` | When `argument` is sorted using |
: : the `<` operator, it matches :
: : container matcher `m`. E.g. :
: : `WhenSorted(ElementsAre(1, 2, :
: : 3))` verifies that `argument` :
: : contains elements 1, 2, and 3, :
: : 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))`. :
**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