heaths / samples-rs

Demonstration of tests and examples in Rust

Home Page:http://heaths.dev/samples-rs/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Samples

This repository contains samples of unit tests, integration tests, and examples.

Samplesaurus

Code sample

An example of code in a separate markdown document:

use samples::say_hello;

let greeting = say_hello("world");
assert_eq!("hello, world!", &greeting);

Documentation

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.

Testing

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

More information

About

Demonstration of tests and examples in Rust

http://heaths.dev/samples-rs/

License:MIT License


Languages

Language:Rust 100.0%