0.9.0
Pre-releaseAPI Changes
-
We eliminated the macro
tuple!
and implemented theMatcher
trait directly for tuples of matchers. #260Previously, 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 totuple!
: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
. #258We renamed the variants of the enum
MatcherResult
fromMatches
andDoesNotMatch
toMatch
respectivelyNoMatch
. 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
toMatcherResult::is_match
. This name is clearer and more in line with Rust idioms such asResult::is_ok
andResult::is_err
. #259let 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 ofMatcherResult::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. #245For 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 tolen
for containers. #247verify_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 outputtingError: ()
, the test harness will now outputError: See failure output above
. #255