This is a demonstration library.
This is a unit-test in Rust:
#[test]
fn it_works() {
println!("Hello World");
println!("Goodbye World");
}
We run such unit tests via cargo test
, which will:
-
run the
tango
build script, bringing the.md
and.rs
files into sync, -
compile the crate via
rustc --test lib.rs
, putting the resulting test binary intotarget/debug/lib-
VERSIONHASH, -
run the test binary.
By default, the generated test binary redirects the stdout
port,
capturing any output generated by the unit test, so when we run the
above unit test, it prints:
% cargo test
Compiling tango-demo v0.1.0 (file:///Users/fklock/Dev/Rust/tango-demo)
Running target/debug/lib-5ad37d9a16a89b76
running 1 test
test it_works ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
Doc-tests lib
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
%
If we wanted to see the output, we could set the RUST_TEST_NOCAPTURE
environment variable, or pass the --nocapture
flag to the test
binary.
% cargo test | grep 'Hello World'
% cargo test -- --nocapture | grep 'Hello World'
Hello World
% RUST_TEST_NOCAPTURE=1 cargo test | grep 'Hello World'
Hello World
% RUST_TEST_NOCAPTURE= cargo test | grep 'Hello World'
Hello World
% cargo test | grep 'Hello World'
% cargo test -- --nocapture | grep 'Hello World'
Hello World
% RUST_TEST_NOCAPTURE=1 cargo test | grep 'Goodbye World'
Goodbye World
% RUST_TEST_NOCAPTURE=any_setting_will_do cargo test | grep 'Hello World'
Hello World
% RUST_TEST_NOCAPTURE= cargo test
Running target/debug/lib-5ad37d9a16a89b76
running 1 test
Hello World
Goodbye World
test it_works ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured
Doc-tests lib
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured
%
Here is some more text I added to the demo library.
Here is one Rust submodule:
pub mod submod_one {
pub fn twice<F, X>(f: F, x: X) -> X
where F: Fn(X) -> X
{
f(f(x))
}
}
Here is another submodule:
pub mod submod_two;
Here is another paragraph.