0.6.0
Pre-releaseAPI changes
-
Changed the way the
Matcher
trait is generic with respect to the type of the actual value from a type parameter to an associated type.This should not break any code using matchers, but does affect how matchers are written. First, the
Matcher
implementation block must now use the associated type.OLD:
impl Matcher<ActualType> for MyMatcher { fn matches(&self, actual: &ActualType) -> MatcherResult {...} }
NEW:
impl Matcher for MyMatcher { type ActualT = ActualType; fn matches(&self, actual: &ActualType) -> MatcherResult {...} }
When the matcher is generic over the actual type (as is common), then the concrete matcher type must also reference the actual value type. This will often require the use of
PhantomData
in the struct body.OLD:
struct MyMatcher {...} impl<ActualT> Matcher<ActualT> for MyMatcher { fn matches(&self, actual: &ActualT) -> MatcherResult {...} }
NEW:
struct MyMatcher<ActualT> { ... phantom: PhantomData<ActualT>, } impl<ActualT> Matcher for MyMatcher<ActualT> { type ActualT = ActualT; fn matches(&self, actual: &ActualT) -> MatcherResult {...} }
Why did we make this change? This forces the concrete matcher type always to carry the type against which it matches. Doing so solves problems which we discovered where the compiler is unable to perform type inference on certain combinations of matchers due to missing information about that type (see below).
Bug fixes
-
The
and()
andor()
methods now work with strings. Previously, using them with strings would cause compilation to fail due to problems with type inference.verify_that!("A string", starts_with("A").and(ends_with("string")))
New features
-
The new
prelude
module makes it easier to include all core functionality and all matchers in one import statement:use googletest::prelude::*; #[test] fn should_work() -> Result<()> { verify_that!(123, eq(123)) }
-
The
eq
matcher now outputs a diff of debug output of the actual and expected values when the assertion fails due to their not being equal, if each value is more than one line. -
The new matcher
eq_deref_of
works likeeq
but takes a reference to the expected value. This is useful when one only has a reference to the expected value and it cannot or should not be cloned.
Other changes
- Many fixes to documentation examples. Examples corresponding to real code should now be correct.
- Doctests are now enabled on all examples where it makes sense to do so.
- The module import setup has been simplified, making things easier for external contributors.