Skip to content

Commit

Permalink
Add a section for using assertions into doc tests.
Browse files Browse the repository at this point in the history
See #47945.
  • Loading branch information
Songbird0 committed Mar 13, 2018
1 parent 1e1bfc7 commit a48224b
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/doc/rustdoc/src/documentation-tests.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@ let x = 5;

There's some subtlety though! Read on for more details.

## Passing or failing a doctest

Like regular unit tests, regular doctests are considered to "pass"
if they compile and run without panicking.
So if you want to demonstrate that some computation gives a certain result,
the `assert!` family of macros works the same as other Rust code:

```rust
let foo = "foo";

assert_eq!(foo, "foo");
```

This way, if the computation ever returns something different,
the code panics and the doctest fails.

## Pre-processing examples

In the example above, you'll note something strange: there's no `main`
Expand Down

0 comments on commit a48224b

Please sign in to comment.