Skip to content

Releases: google/googletest-rust

0.4.2

24 Mar 10:38
Compare
Choose a tag to compare
0.4.2 Pre-release
Pre-release

API additions

  • A new method times on the matcher contains_substring allows asserting on the number of times the actual string contains the given substring.
  • The enum MatcherResult can now be converted to and from bool (representing MatcherResult::Matches) via the Into and From traits.

Bugfixes

  • Using both #[google_test] and #[rstest] on a test should no longer result in problems with compilation. This is a partial fix for #77, as much as is possible within this library alone. The rest of clarified in the documentation.

0.4.1

17 Mar 09:22
Compare
Choose a tag to compare
0.4.1 Pre-release
Pre-release

This is a bugfix release from 0.4.0.

Version 0.4.0 contained a regression which broke compilation of downstream tests using the matches_pattern! macro. This version fixes that problem and modifies the testing approach to avoid similar regressions in the future.

It contains no further changes.

0.4.0

10 Mar 16:37
Compare
Choose a tag to compare
0.4.0 Pre-release
Pre-release

New additions

  • The new matcher StrMatcher combines string equality (using eq with String or &str), starts_with, ends_with, and contains_substring and provides common features for all of these. This includes ASCII case-insensitive matching and ignoring leading and trailing whitespace.
  • The new matcher predicate allows matching using an arbitrary predicate on the input.

Other improvements

  • There is now crate-level documentation, including a table of available matchers.
  • The documentation for the declarative macros which generate matchers (all!, matchers_pattern!, unordered_elements_are! and so on) has been improved to more clearly indicate what the arguments should be as well as the types of values against which they match.
  • elements_are!, unordered_elements_are!, pointwise!, and size no longer require the actual value to implement HasSize.
  • Match failure and expectation descriptions are now properly indented.

API changes

  • The minimum supported Rust version is now 1.67.0.

  • The trait HasSize has been removed. The matchers which depended on it now just require the actual value to support IntoIterator.

    If you implemented HasSize for one of your collections, just remove the impl HasSize since it is not needed.

  • The matcher eq_ignoring_ascii_case has been removed. Use eq("...").ignoring_ascii_case() instead:

    OLD:

    verify_that!("ABC", eq_ignoring_ascii_case("abc"))
    

    NEW:

    verify_that!("ABC", eq("abc").ignoring_ascii_case())
    
  • One should no longer take a reference to a slice when using the size macher:

    OLD:

    let value = &[1, 2, 3];
    verify_that(&value[0..1], size(eq(1)))?;
    

    NEW:

    let value = &[1, 2, 3];
    verify_that(value[0..1], size(eq(1)))?;
    

0.3.0

31 Jan 14:47
Compare
Choose a tag to compare
0.3.0 Pre-release
Pre-release

New additions

  • The new macros expect_that! and expect_pred! can be used for non-fatal assertions. They are equivalent to verify_*!(...).and_log_failure().
  • The new macros contains_each! and is_contained_in! allow for matching on containers containing some set of elements, or contained in some superset of elements, specified by matchers. These are analogous to superset_of and subset_of but the arguments are matchers rather than values.
  • There is now an extension method or (in the trait OrMatcherExt) which can be used to express disjunction in matchers: eq(123).or(eq(234)). This is analogous to the existing and method.

Other improvements

  • All assertion macros which produce Result are now annotated with #[must_use] so that the compiler will produce a warning if the result is ignored.
  • Improvements to the readability and usefulness of test assertion failure messages. In particular, actual values are now pretty-printed, redundant display has been removed, and mismatches from nested matchers are more consistently explained.
  • The struct TestAssertionFailure now implements From<T> for all T: std::error::Error, so the ? operator works transparently in tests.
  • Test assertion failure messages for the tuple! macro now produce more detailed information about which tuple elements failed to match.
  • The macros elements_are!, unordered_elements_are! now support trailing commas.
  • Documentation pages for empty and internal-only modules should no longer be published on docs.rs.

API changes

  • The trait Describe has been folded into Matcher and removed. Existing matchers must be updated with the new version. To do this, move the describe method implementation into the impl Matcher block, like so:

    OLD:

    impl Matcher<T> for MyMatcher {
        fn matches(&self, actual: &T) -> MatcherResult {...}
    }
    
    impl Describe for MyMatcher {
        fn describe(&self, matcher_result: MatcherResult) -> String {...}
    }
    

    NEW:

    impl Matcher<T> for MyMatcher {
        fn matches(&self, actual: &T) -> MatcherResult {...}
    
        fn describe(&self, matcher_result: MatcherResult) -> String {...}
    }
    
  • The extension method err_to_test_failure and its associated trait MapErrorToTestFailure are no longer needed and have been removed. The ? operator should now work transparently as long as the Err type of the Result implements std::error::Error (which is standard practice). Calls to err_to_test_failure can be removed:
    OLD:

    #[test]
    fn test_that_something_works() -> Result<()> {
        do_something().err_to_test_failure()?;
        ...
    }
    

    NEW:

    #[test]
    fn test_that_something_works() -> Result<()> {
        do_something()?;
        ...
    }
    

    If the output of such a call is used directly in a return statement or expression, then it should be replaced by Ok(...?):
    OLD:

    fn run_do_something() -> Result<Something> {
        do_something().err_to_test_failure()
    }
    

    NEW:

    fn run_do_something() -> Result<Something> {
        Ok(do_something()?)
    }
    

0.2.0

27 Dec 08:53
Compare
Choose a tag to compare
0.2.0 Pre-release
Pre-release
  • Introduced assert_that! and assert_pred! macros which panic on failure, acting more like other Rust test libraries.
  • Introduced a tuple! matcher macro to match plain (non-struct) tuples by supplying matchers for each entry.
  • Modified contains(...).times(...) to take a matcher rather than a plain count as input. Now one can match on containers containing, say, more than a given number of elements meeting the criteria.
  • Folded the attribute macro #[google_test_wrapper] into #[google_test].