Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc_testing.md: clarify tests vs doc-tests #1547

Merged
merged 1 commit into from
Jun 2, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/testing/doc_testing.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
The primary way of documenting a Rust project is through annotating the source
code. Documentation comments are written in [markdown] and support code
blocks in them. Rust takes care about correctness, so these code blocks are
compiled and used as tests.
compiled and used as documentation tests.

```rust,ignore
/// First line is a short summary describing function.
Expand Down Expand Up @@ -48,7 +48,8 @@ pub fn div(a: i32, b: i32) -> i32 {
}
```

Tests can be run with `cargo test`:
Code blocks in documentation are automatically tested
when running the regular `cargo test` command:

```shell
$ cargo test
Expand All @@ -73,8 +74,8 @@ the functionality, which is one of the most important
[guidelines][question-instead-of-unwrap]. It allows using examples from docs as
complete code snippets. But using `?` makes compilation fail since `main`
returns `unit`. The ability to hide some source lines from documentation comes
to the rescue: one may write `fn try_main() -> Result<(), ErrorType>`, hide it and
`unwrap` it in hidden `main`. Sounds complicated? Here's an example:
to the rescue: one may write `fn try_main() -> Result<(), ErrorType>`, hide it
and `unwrap` it in hidden `main`. Sounds complicated? Here's an example:

```rust,ignore
/// Using hidden `try_main` in doc tests.
Expand Down