Skip to content

0.7.0

Pre-release
Pre-release
Compare
Choose a tag to compare
@hovinen hovinen released this 19 May 17:03
· 363 commits to main since this release

API changes

  • The matcher size has been renamed to len to 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 AndMatcherExt and OrMatcherExt have been removed, their methods and() and or() folded into Matcher. In the vast majority of cases, it should suffice just to remove the imports of AndMatcherExt and OrMatcherExt and instead import Matcher (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::prelude causes Matcher to be imported.

  • The method Matcher::explain_match now returns just a String. The previous structure MatchExplanation has been removed. This has no effect on the uses of matchers, but does require some minor porting of implementations of the Matcher trait.

    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! and expect_pred! macros as well as the and_log_failure() extension method will now panic if they are invoked without having used the googletest::test attribute. Previously, it was all too easy to forget to annotate the test with #[googletest::test] when using the expect_* 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 lines
    

    This not only works with eq but also with the other string comparison matchers starts_with, ends_with, and contains_substring. It does not work with regular expression matchers, nor with string matchers on which one has applied additional configuration such as ignore_leading_whitespace() or times(...).

  • 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_as now 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.