0.7.0
Pre-releaseAPI changes
-
The matcher
sizehas been renamed tolento be more idiomatic in Rust.OLD:
let value = vec![...]; verify_that!(value, size(eq(1)))NEW:
let value = vec![...]; verify_that!(value, len(eq(1))) -
The extension traits
AndMatcherExtandOrMatcherExthave been removed, their methodsand()andor()folded intoMatcher. In the vast majority of cases, it should suffice just to remove the imports ofAndMatcherExtandOrMatcherExtand instead importMatcher(if not already done).OLD:
use googletest::matchers::{AndMatcherExt, OrMatcherExt}; #[test] fn should_work() { verify_that!(value, starts_with("Something").and(ends_with("else").or(contains_substring("another thing")))) }NEW:
use googletest::matcher::Matcher; // or, recommended: use googletest::prelude::*; #[test] fn should_work() { verify_that!(value, starts_with("Something").and(ends_with("else").or(contains_substring("another thing")))) }Importing all symbols in
googletest::preludecausesMatcherto be imported. -
The method
Matcher::explain_matchnow returns just aString. The previous structureMatchExplanationhas been removed. This has no effect on the uses of matchers, but does require some minor porting of implementations of theMatchertrait.OLD:
fn explain_match(&self, actual: &Self::ActualT) -> MatchExplanation { MatchExplanation(format!("which ...")) }NEW:
fn explain_match(&self, actual: &Self::ActualT) -> String { format!("which ...") }
New features and other changes
-
GoogleTest Rust now works with rustc 1.59. Previously, the minimum required rustc version was 1.67.
-
The
expect_that!andexpect_pred!macros as well as theand_log_failure()extension method will now panic if they are invoked without having used thegoogletest::testattribute. Previously, it was all too easy to forget to annotate the test with#[googletest::test]when using theexpect_*family of assertions. The result was that the assertions would not do anything! Now, the test will immediately panic in that situation.The assertions will also now panic if invoked in a thread other than that in which one is running the test.
-
The output of the actual value in test assertion failure messages will no longer pretty-print if the value's debug output is a single line of at most 60 characters. This should reduce visual clutter. For example, a value of
Some(123)previously would be output:Actual: Some( 123 )Now it is output:
Actual: Some(123) -
Assertion failures now have a newline between the debug output of the value and the further explanation of why an actual value did not match.
-
String comparisons now print a diff output when both the actual and expected values have more than one line. This should make finding the difference between two strings much easier. For example, the following assertion:
let value = "The first line\nThe second line"; verify_that!(value, eq("The first line\nThe second lines"))yields the following diagnostic output:
Value of: value Expected: is equal to "The first line\nThe second line" Actual: "The first line\nThe second line" which is not equal to "The first line\nThe second line" Difference: The first line +The second line -The second linesThis not only works with
eqbut also with the other string comparison matchersstarts_with,ends_with, andcontains_substring. It does not work with regular expression matchers, nor with string matchers on which one has applied additional configuration such asignore_leading_whitespace()ortimes(...). -
It is now possible to create composed matchers inside functions without running into problems with inner matchers being dropped too early. For example, previously, the following did not compile:
fn create_a_matcher(value: u32) -> impl Matcher<ActualT = Vec<u32>> { contains_each![eq(value), gt(value)] }Now this and other functions of this sort should compile and work.
-
The matcher
displays_asnow displays a full match explanation of its inner matcher rather than just showing how the actual value displays. In particular, it will now show a diff if the display value has multiple lines and is matched with one of the string matchers.