Hamcrest2
A port of Hamcrest to Rust. Fork of original hamcrest-rust (which is unmaintained) with extra matchers, better docs etc.
Installing
To use Hamcrest, add this to your Cargo.toml
:
[dev-dependencies]
hamcrest2 = "*"
And this to your crate root:
extern crate hamcrest2;
After a quick cargo build
, you should be good to go!
Usage
Hamcrest2 supports a number of matchers. The easiest way is to just use
them all like this:
use *;
If you want to be more selective make sure that you also import the HamcrestMatcher
trait.
General Matchers
eq, not
assert_that!; // also equal_to()
assert_that!;
compared_to
assert_that!; // also less_than()
assert_that!; // also less_than_or_equal_to()
assert_that!; // also greater_than()
assert_that!; // also greater_than_or_equal_to()
type_of
assert_that!;
assert_that!;
matches_regex
assert_that!;
assert_that!;
Numerical Matchers
close_to
assert_that!;
assert_that!;
Filesystem Matchers
path_exists, file_exists, dir_exists
let path = new;
assert_that!;
assert_that!;
assert_that!;
Option and Result
has
let var: = Some;
assert_that!;
let var: = Ok;
assert_that!;
ok
let var: = Ok;
assert_that!;
assert_that!;
let var: = Err;
assert_that!;
err
let var: = Err;
assert_that!;
assert_that!;
let var: = Ok;
assert_that!;
some
let var: = Some;
assert_that!;
assert_that!;
let var: = None;
assert_that!;
none
let var: = None;
assert_that!;
assert_that!;
assert_that!;
Collection Matchers
contains, contains exactly, contains in order
assert_that!;
assert_that!;
assert_that!;
assert_that!;
assert_that!;
assert_that!;
len
assert_that!;
assert_that!;
empty
assert_that!;
assert_that!;
Compound Matchers
all
assert_that!; // also and!()
assert_that!;
any
assert_that!; // also or!()
assert_that!;
Misc Matchers
is(bool)
assert_that!;
assert_that!;
anything
assert_that!;
assert_that!;
License
Licensed under either of
- Apache License, Version 2.0 (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
- MIT license (LICENSE-MIT or http://opensource.org/licenses/MIT)
at your option.
Contribution
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.