Crate must [−] [src]
Usage
Add must
to your Cargo.toml file.
[dev-dependencies] must = "0.2.*"
And add
#[cfg_attr(test, macro_use)] #[cfg(test)] extern crate must;
to your root module.
Then add
use must::prelude::*;
your test module.
Features
- Lazy. You can use .with_msg() after assertion.
- Fluent.
- You can build your own composable test tool. See lazy module for full example.
let parser: fn(&str) -> Result<Lit, ParseError> = parse_lit; parser.must_parse("false").as_ok(Lit::Bool(false)); // .or(fail!()) is optional parser.must_parse("true").as_ok(Lit::Bool(true)).or(fail!()); parser.must_parse("352").as_ok(Lit::Num(352)).or(fail!());
How does it work?
- If value is not explicitly taken by user, it panics on drop.
- As it defers panic, with_msg() can be used almost anywhere.
Examples (Usage)
#[macro_use] extern crate must; use must::prelude::*; // fail!() is optional, and if not called, it will panic on drop. // but as it's value is not used, it will be dropped right after one assertion chain. Some(5u8).must_be_some_and(|val| { val.must_be(5) // closure must return assertion }).or(fail!("your msg {}", "and args")); // fail! macro captures location, so you can know source of panic without backtrace. // fail! macro supports optional formatting. // As value is printed by must, you don't have to put it in format args. fn double(x: usize) -> usize { x * 2 } 10.must_be_in_range(10..); 10.must_not_be_in_range(..10); double(10).must_be_in_range(..); double(10).must_not_be_in_range(..20);
Examples (Extending must with builder style)
See lazy module.
Reexports
pub use self::errors::Error; |
pub use self::errors::ErrorKind; |
pub use self::lazy::LazyAssertion; |
pub use self::lazy::LazyMatcher; |
Modules
error_renderer | |
errors | |
lazy |
Builder style, lazy evaluating matcher. |
marker |
Marker trait for types. |
matchers | |
prelude |
Macros
fail |
fail! macro is used to add source and custom message to result. |
Traits
Mutator |
Mutator |