Skip to content

0.8.0

Pre-release
Pre-release
Compare
Choose a tag to compare
@hovinen hovinen released this 30 Jun 07:56
· 354 commits to main since this release

API Changes

None

Major features and improvements

  • The performance of constructing a diff of the actual and expected values in the assertion failure message for matchers such as eq, contains_substring, starts_with, ends_with, and eq_deref_of has been greatly improved.

  • The aforementioned diff output now compresses long sequences of equal lines, now showing only two lines of context around differences. This is similar to the standard diff tool.

  • verify_that! and related macros now support an abbreviated form for matching against containers with elements_are! and unordered_elements_are!. Namely:

    let value = vec![1, 2, 3];
    verify_that!(value, [eq(1), eq(2), eq(3)])
    

    is equivalent to

    let value = vec![1, 2, 3];
    verify_that!(value, elements_are![eq(1), eq(2), eq(3)])
    

    Similarly,

    let value = HashSet::from([1, 2, 3]);
    verify_that!(value, {eq(1), eq(2), eq(3)})
    

    is equivalent to

    let value = HashSet::from([1, 2, 3]);
    verify_that!(value, unordered_elements_are![eq(1), eq(2), eq(3)])
    

Bugfixes and other changes

  • The matches_pattern! macro now supports matching structs and enum variants without fields. For example, the following which would not compile previously now works fine:

    enum MyEnum {
        A
    }
    verify_that!(value, matches_pattern!(MyEnum::A))
    
  • The test assertion failure message for matches_pattern! now always includes the expected struct or enum variant. For example, the following code:

    enum AnEnum {
        A(u32),
        B(u32),
    }
    let value = AnEnum::B(123);
    verify_that!(value, matches_pattern!(AnEnum::A(eq(123)))
    

    would previously produce the following test assertion failure message:

    Value of: value
    Expected: has field `0`, which is equal to 123
    Actual: AnEnum::B(123),
      which does not have field `0`
    

    This was confusing, since the actual problem -- that the actual value had the wrong enum variant -- was not made clear. Now the failure message is as follows:

    Value of: value
    Expected: is AnEnum :: A which has field `0`, which is equal to 123
    Actual: AnEnum::B(123),
      which does not have field `0`
    

    We plan to continue to polish this message in upcoming versions.

  • The aforementioned generated diff will now only show up to ca. 25 lines of difference. If the actual and expected debug strings differ on more lines, then the two are deemed unrelated and the diff output is suppressed.