Skip to content

0.9.0

Pre-release
Pre-release
Compare
Choose a tag to compare
@hovinen hovinen released this 14 Jul 16:21
· 395 commits to main since this release

API Changes

  • We eliminated the macro tuple! and implemented the Matcher trait directly for tuples of matchers. #260

    Previously, if one wanted to match against a tuple of matchers, one would use the tuple! macro. Now, one can construct a matcher just by taking a tuple of matchers. To port code, just remove the call to tuple!:

    OLD:

    verify_that!((1, 2), tuple!(eq(1), eq(2)))
    

    NEW:

    verify_that!((1, 2), (eq(1), eq(2)))
    

    If the tuple is a singleton, one must ensure that a trailing comma is present so that the Rust compiler recognises it as a tuple:

    OLD:

    verify_that!((1,), tuple!(eq(1)))
    

    NEW:

    verify_that!((1), (eq(1),))
    
  • We renamed the variants of MatcherResult. #258

    We renamed the variants of the enum MatcherResult from Matches and DoesNotMatch to Match respectively NoMatch. The new names are more concise and work better linguistically.

    To port code, just use the new variants:

    OLD:

    fn matches(&self, actual: &Self::ActualT) -> MatcherResult {
        if condition {
            MatcherResult::Matches
        } else {
            MatcherResult::DoesNotMatch
        }
    }
    

    NEW:

    fn matches(&self, actual: &Self::ActualT) -> MatcherResult {
        if condition {
            MatcherResult::Match
        } else {
            MatcherResult::NoMatch
        }
    }
    

    This should only affect developers who write their own matchers, not those using existing matchers.

  • We renamed MatcherResult::into_bool to MatcherResult::is_match. This name is clearer and more in line with Rust idioms such as Result::is_ok and Result::is_err. #259

    let result = matcher.matches(&value);
    if result.into_bool() { ... }
    

    NEW:

    let result = matcher.matches(&value);
    if result.is_match() { ... }
    

    We have also added a corresponding method MatcherResult::is_no_match() which we recommend instead of negating the output of MatcherResult::is_match().

    This should only affect developers who write their own matchers, not those using existing matchers.

Bugfixes

  • All test assertion failures -- fatal and nonfatal -- will now be output when using a mix of assertion types with the #[googletest::test] macro. Previously, when a fatal failure occurred after a non-fatal failure, only the non-fatal failure would be output to the console. #254

Other new features and improvements

  • The diff of actual and expected values is now coloured, with extra lines from the actual value appearing in red and lines missing from the expected value appearing in green. The + and - characters are still present for the case that colours are not available or the reader of the output has colourblindness. There is also now an explanation of the output at the top of the diff. #232 #251

  • The assertion failure message for matches_pattern! has been improved when matching enums with fields. It now indicates directly that the wrong enum variant was used rather than showing a confusing message about the field not being present. #245

    For example:

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

    Previous output:

    Value of: actual
    Expected: is AnEnum :: B which has field `0`, which is equal to 123
    Actual: A(123),
      which has no field `0`
    

    New output:

    Value of: actual
    Expected: is AnEnum :: B which has field `0`, which is equal to 123
    Actual: A(123),
      which has the wrong enum variant `A`
    
  • There is new optional support to ease integration with the proptest crate for property-based testing. See the crate-level documentation for more information. #246

  • The new matcher char_count matches string slices and owned strings with a given number of Unicode scalar values. It is analogous to len for containers. #247

    verify_that!("This string", char_count(gt(5)))
    

Other minor changes

  • The description and match explanation of the len matcher now uses the word "length" rather than (the potentially misleading) "size".
  • The output for test failures when using the #[googletest::test] attribute macro has been improved somewhat. Instead of outputting Error: (), the test harness will now output Error: See failure output above. #255