Skip to content

Commit

Permalink
Googletest export
Browse files Browse the repository at this point in the history
Internal change

PiperOrigin-RevId: 356867746
  • Loading branch information
Abseil Team authored and derekmauro committed Feb 18, 2021
1 parent 6092810 commit e935e6c
Show file tree
Hide file tree
Showing 5 changed files with 7 additions and 69 deletions.
20 changes: 5 additions & 15 deletions docs/advanced.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,15 +99,13 @@ If you already have a function or functor that returns `bool` (or a type that
can be implicitly converted to `bool`), you can use it in a *predicate
assertion* to get the function arguments printed for free:
<!-- mdformat off(github rendering does not support multiline tables) -->
| Fatal assertion | Nonfatal assertion | Verifies |
| --------------------------------- | --------------------------------- | --------------------------- |
| `ASSERT_PRED1(pred1, val1)` | `EXPECT_PRED1(pred1, val1)` | `pred1(val1)` is true |
| `ASSERT_PRED2(pred2, val1, val2)` | `EXPECT_PRED2(pred2, val1, val2)` | `pred2(val1, val2)` is true |
| `...` | `...` | `...` |
<!-- mdformat on -->
In the above, `predn` is an `n`-ary predicate function or functor, where `val1`,
`val2`, ..., and `valn` are its arguments. The assertion succeeds if the
predicate returns `true` when applied to the given arguments, and fails
Expand Down Expand Up @@ -329,26 +327,22 @@ want to learn more, see

#### Floating-Point Macros

<!-- mdformat off(github rendering does not support multiline tables) -->

| Fatal assertion | Nonfatal assertion | Verifies |
| ------------------------------- | ------------------------------- | ---------------------------------------- |
| `ASSERT_FLOAT_EQ(val1, val2);` | `EXPECT_FLOAT_EQ(val1, val2);` | the two `float` values are almost equal |
| `ASSERT_DOUBLE_EQ(val1, val2);` | `EXPECT_DOUBLE_EQ(val1, val2);` | the two `double` values are almost equal |

<!-- mdformat on -->

By "almost equal" we mean the values are within 4 ULP's from each other.

The following assertions allow you to choose the acceptable error bound:

<!-- mdformat off(github rendering does not support multiline tables) -->

| Fatal assertion | Nonfatal assertion | Verifies |
| ------------------------------------- | ------------------------------------- | -------------------------------------------------------------------------------- |
| `ASSERT_NEAR(val1, val2, abs_error);` | `EXPECT_NEAR(val1, val2, abs_error);` | the difference between `val1` and `val2` doesn't exceed the given absolute error |

<!-- mdformat on -->

#### Floating-Point Predicate-Format Functions

Expand All @@ -373,13 +367,11 @@ validating arguments passed to mock objects. A gMock *matcher* is basically a
predicate that knows how to describe itself. It can be used in these assertion
macros:
<!-- mdformat off(github rendering does not support multiline tables) -->
| Fatal assertion | Nonfatal assertion | Verifies |
| ------------------------------ | ------------------------------ | --------------------- |
| `ASSERT_THAT(value, matcher);` | `EXPECT_THAT(value, matcher);` | value matches matcher |
<!-- mdformat on -->
For example, `StartsWith(prefix)` is a matcher that matches a string starting
with `prefix`, and you can write:
Expand Down Expand Up @@ -1355,7 +1347,6 @@ for generating test parameters. They return what we call (surprise!) *parameter
generators*. Here is a summary of them, which are all in the `testing`
namespace:

<!-- mdformat off(github rendering does not support multiline tables) -->

| Parameter Generator | Behavior |
| ----------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------- |
Expand All @@ -1365,7 +1356,6 @@ namespace:
| `Bool()` | Yields sequence `{false, true}`. |
| `Combine(g1, g2, ..., gN)` | Yields all combinations (Cartesian product) as std\:\:tuples of the values generated by the `N` generators. |

<!-- mdformat on -->

For more details, see the comments at the definitions of these functions.

Expand Down Expand Up @@ -1428,8 +1418,8 @@ given test suite, whether their definitions come before or *after* the
You can see [sample7_unittest.cc] and [sample8_unittest.cc] for more examples.
[sample7_unittest.cc]: ../googletest/samples/sample7_unittest.cc "Parameterized Test example"
[sample8_unittest.cc]: ../googletest/samples/sample8_unittest.cc "Parameterized Test example with multiple parameters"
[sample7_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample7_unittest.cc "Parameterized Test example"
[sample8_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample8_unittest.cc "Parameterized Test example with multiple parameters"
### Creating Value-Parameterized Abstract Tests
Expand Down Expand Up @@ -1579,7 +1569,7 @@ TYPED_TEST(FooTest, HasPropertyA) { ... }

You can see [sample6_unittest.cc] for a complete example.

[sample6_unittest.cc]: ../googletest/samples/sample6_unittest.cc "Typed Test example"
[sample6_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample6_unittest.cc "Typed Test example"

## Type-Parameterized Tests

Expand Down Expand Up @@ -2022,7 +2012,7 @@ You can do so by adding one line:
Now, sit back and enjoy a completely different output from your tests. For more
details, see [sample9_unittest.cc].

[sample9_unittest.cc]: ../googletest/samples/sample9_unittest.cc "Event listener example"
[sample9_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample9_unittest.cc "Event listener example"

You may append more than one listener to the list. When an `On*Start()` or
`OnTestPartResult()` event is fired, the listeners will receive it in the order
Expand All @@ -2049,7 +2039,7 @@ by the former.

See [sample10_unittest.cc] for an example of a failure-raising listener.

[sample10_unittest.cc]: ../googletest/samples/sample10_unittest.cc "Failure-raising listener example"
[sample10_unittest.cc]: https://github.com/google/googletest/blob/master/googletest/samples/sample10_unittest.cc "Failure-raising listener example"

## Running Test Programs: Advanced Options

Expand Down
4 changes: 2 additions & 2 deletions docs/faq.md
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ If necessary, you can continue to derive test fixtures from a derived fixture.
googletest has no limit on how deep the hierarchy can be.

For a complete example using derived test fixtures, see
[sample5_unittest.cc](../googletest/samples/sample5_unittest.cc).
[sample5_unittest.cc](https://github.com/google/googletest/blob/master/googletest/samples/sample5_unittest.cc).

## My compiler complains "void value not ignored as it ought to be." What does this mean?

Expand Down Expand Up @@ -670,7 +670,7 @@ there is an `std::ostream& operator<<(std::ostream&, const FooType&)` function
defined such that we can print a value of `FooType`.
In addition, if `FooType` is declared in a name space, the `<<` operator also
needs to be defined in the *same* name space. See https://abseil.io/tips/49 for details.
needs to be defined in the *same* name space. See abseil.io/tips/49 for details.
## How do I suppress the memory leak messages on Windows?
Expand Down
Loading

0 comments on commit e935e6c

Please sign in to comment.