Skip to content

0.3.0

Pre-release
Pre-release
Compare
Choose a tag to compare
@hovinen hovinen released this 31 Jan 14:47
· 627 commits to main since this release

New additions

  • The new macros expect_that! and expect_pred! can be used for non-fatal assertions. They are equivalent to verify_*!(...).and_log_failure().
  • The new macros contains_each! and is_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 to superset_of and subset_of but the arguments are matchers rather than values.
  • There is now an extension method or (in the trait OrMatcherExt) which can be used to express disjunction in matchers: eq(123).or(eq(234)). This is analogous to the existing and method.

Other improvements

  • All assertion macros which produce Result are 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 TestAssertionFailure now implements From<T> for all T: 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 Describe has been folded into Matcher and removed. Existing matchers must be updated with the new version. To do this, move the describe method implementation into the impl Matcher block, 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_failure and its associated trait MapErrorToTestFailure are no longer needed and have been removed. The ? operator should now work transparently as long as the Err type of the Result implements std::error::Error (which is standard practice). Calls to err_to_test_failure can 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 return statement or expression, then it should be replaced by Ok(...?):
    OLD:

    fn run_do_something() -> Result<Something> {
        do_something().err_to_test_failure()
    }
    

    NEW:

    fn run_do_something() -> Result<Something> {
        Ok(do_something()?)
    }