0.3.0
Pre-release
Pre-release
New additions
- The new macros
expect_that!andexpect_pred!can be used for non-fatal assertions. They are equivalent toverify_*!(...).and_log_failure(). - The new macros
contains_each!andis_contained_in!allow for matching on containers containing some set of elements, or contained in some superset of elements, specified by matchers. These are analogous tosuperset_ofandsubset_ofbut the arguments are matchers rather than values. - There is now an extension method
or(in the traitOrMatcherExt) which can be used to express disjunction in matchers:eq(123).or(eq(234)). This is analogous to the existingandmethod.
Other improvements
- All assertion macros which produce
Resultare now annotated with#[must_use]so that the compiler will produce a warning if the result is ignored. - Improvements to the readability and usefulness of test assertion failure messages. In particular, actual values are now pretty-printed, redundant display has been removed, and mismatches from nested matchers are more consistently explained.
- The struct
TestAssertionFailurenow implementsFrom<T>for allT: std::error::Error, so the?operator works transparently in tests. - Test assertion failure messages for the
tuple!macro now produce more detailed information about which tuple elements failed to match. - The macros
elements_are!,unordered_elements_are!now support trailing commas. - Documentation pages for empty and internal-only modules should no longer be published on docs.rs.
API changes
-
The trait
Describehas been folded intoMatcherand removed. Existing matchers must be updated with the new version. To do this, move thedescribemethod implementation into theimpl Matcherblock, like so:OLD:
impl Matcher<T> for MyMatcher { fn matches(&self, actual: &T) -> MatcherResult {...} } impl Describe for MyMatcher { fn describe(&self, matcher_result: MatcherResult) -> String {...} }NEW:
impl Matcher<T> for MyMatcher { fn matches(&self, actual: &T) -> MatcherResult {...} fn describe(&self, matcher_result: MatcherResult) -> String {...} } -
The extension method
err_to_test_failureand its associated traitMapErrorToTestFailureare no longer needed and have been removed. The?operator should now work transparently as long as theErrtype of theResultimplementsstd::error::Error(which is standard practice). Calls toerr_to_test_failurecan be removed:
OLD:#[test] fn test_that_something_works() -> Result<()> { do_something().err_to_test_failure()?; ... }NEW:
#[test] fn test_that_something_works() -> Result<()> { do_something()?; ... }If the output of such a call is used directly in a
returnstatement or expression, then it should be replaced byOk(...?):
OLD:fn run_do_something() -> Result<Something> { do_something().err_to_test_failure() }NEW:
fn run_do_something() -> Result<Something> { Ok(do_something()?) }