Releases: google/googletest-rust
0.4.2
API additions
- A new method
times
on the matchercontains_substring
allows asserting on the number of times the actual string contains the given substring. - The enum
MatcherResult
can now be converted to and frombool
(representingMatcherResult::Matches
) via theInto
andFrom
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
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
New additions
- The new matcher
StrMatcher
combines string equality (usingeq
withString
or&str
),starts_with
,ends_with
, andcontains_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!
, andsize
no longer require the actual value to implementHasSize
.- 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 supportIntoIterator
.If you implemented
HasSize
for one of your collections, just remove theimpl HasSize
since it is not needed. -
The matcher
eq_ignoring_ascii_case
has been removed. Useeq("...").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
New additions
- The new macros
expect_that!
andexpect_pred!
can be used for non-fatal assertions. They are equivalent toverify_*!(...).and_log_failure()
. - The new macros
contains_each!
andis_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 tosuperset_of
andsubset_of
but the arguments are matchers rather than values. - There is now an extension method
or
(in the traitOrMatcherExt
) which can be used to express disjunction in matchers:eq(123).or(eq(234))
. This is analogous to the existingand
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 implementsFrom<T>
for allT: 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 intoMatcher
and removed. Existing matchers must be updated with the new version. To do this, move thedescribe
method implementation into theimpl 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 traitMapErrorToTestFailure
are no longer needed and have been removed. The?
operator should now work transparently as long as theErr
type of theResult
implementsstd::error::Error
(which is standard practice). Calls toerr_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 byOk(...?)
:
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
- Introduced
assert_that!
andassert_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].