about summary refs log tree commit diff
path: root/src/doc
diff options
context:
space:
mode:
authorkennytm <kennytm@gmail.com>2018-03-16 01:49:45 +0800
committerGitHub <noreply@github.com>2018-03-16 01:49:45 +0800
commit97b489ef39bb775bbe5b99557ef11e5d954c0446 (patch)
tree761b08e185a47215566fcbc0ae9d4a6df2fea3ad /src/doc
parent292c6ca041173a67c9bdfb69cd02144e052aaded (diff)
parenta48224b9ac287b9fe1b2e0783d0ccefe5b8c87df (diff)
downloadrust-97b489ef39bb775bbe5b99557ef11e5d954c0446.tar.gz
rust-97b489ef39bb775bbe5b99557ef11e5d954c0446.zip
Rollup merge of #48961 - Songbird0:rustdoc_doctests_assertions, r=GuillaumeGomez
Rustdoc: example of use of assertions

I added this section at the beginning of the file because it seems to be basic information. Let me know if there's someplace more relevant.

See #47945.
Diffstat (limited to 'src/doc')
-rw-r--r--src/doc/rustdoc/src/documentation-tests.md16
1 files changed, 16 insertions, 0 deletions
diff --git a/src/doc/rustdoc/src/documentation-tests.md b/src/doc/rustdoc/src/documentation-tests.md
index cc7b15812ec..fea8685a605 100644
--- a/src/doc/rustdoc/src/documentation-tests.md
+++ b/src/doc/rustdoc/src/documentation-tests.md
@@ -35,6 +35,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`