This repository contains samples of unit tests, integration tests, and examples.
An example of code in a separate markdown document:
use samples::say_hello;
let greeting = say_hello("world");
assert_eq!("hello, world!", &greeting);
You can also test samples in separate documentation in much the same way. By injecting a single markdown file per module, line numbers will accurately reference lines of code in the injected markdown file.
You can exclude these modules from release code by attributing them as #[cfg(doctest)]
.
Note currently that you cannot declare types in code to reference in documentation tests with this predicate. See rust-lang/rust#67295 for more information and status.
To run all unit, integration, and doc tests:
cargo test
To run any tests in examples:
cargo test --examples
To run an example:
cargo run --example hello
cargo run --example hello -- world