Skip to content

v0.13.0

Pre-release
Pre-release
Compare
Choose a tag to compare
@bmoxb bmoxb released this 26 Nov 15:47

API Changes

  • Note that the minimum supported Rust version has increased from 1.66 to 1.70.

  • Rename #[googletest::test] to #[googletest::gtest] and add it to the prelude.

    Note that #[googletest::test] will not be deprecated because this spelling is useful for compatibility with the rstest crate.

  • Add assert_pred! to prelude.

New Features

  • Add test fixture support for synchronous tests.

    Various traits to represent different types of test fixtures have been added. The core Fixture trait may be used like this:

    struct MyFixture {...}
    
    impl Fixture for MyFixture {
        fn set_up() -> Result<MyFixture> {
            Ok(MyFixture {...})
        }
    
        fn tear_down(self) -> Result<()> {
            Ok(())
        }
    }
    
    #[googletest::test]
    fn test_with_fixture(my_fixture: &MyFixture) {...}
    

    ConsumableFixture has only a set_up method and no tear_down method.

    FixtureOf<T> adapts a T: Default into a ConsumableFixture.

    StaticFixture has a set_up_once method which is called only once before any tests are run.

  • Add impl Matcher<&()> for ().

  • Handle the printing of arguments passed to gtest macros that do not implement Debug using inherent method specialization.

  • Generalize verify_pred! such that it can take any expression and provide meaningful output of intermediate values on failure.

  • Add support for printing the two sides of a binary operator and traversing inside a unary operator in verify_pred!.

    For example, an assertion of the form verify_pred!(a == b) will print both the left and right-hand sides when it fails.

  • Add support for sequences (ordered and unordered) to expect_that! and assert_that!.

  • Add result_of! and result_of_ref! matchers for matching with a function applied to the value first.

    Example: verify_that!(100, result_of!(|value| value + 1, eq(101)))?; will pass.

  • Add special cases to verify_eq! so that, when doing eq matching on sequences of tuple elements, the matcher applies tuple matching, distributing eq pointwise.

    This improves the ergonomics of tests that check for tuple contents, such as:

    let hash_map: std::collections::HashMap<String, String> =
        std::collections::HashMap::from([
            ("a".into(), "A".into()),
            ("b".into(), "B".into())]);
    verify_eq!(hash_map, {("a", "A"), ("b", "B")})

    because the matcher for &str is compatible with &String.

    The specialization applies on the inner structure; without it, the general matcher on tuples doesn't apply in the above case due to the definition of PartialEq on whole tuples, which is currently limited by rust-lang/rust#105092.

  • Add is_true! and is_false! Boolean matchers.

Bug Fixes

  • Fix #[gtest] failing to compile when a user-declared std or core module is in scope.

  • Fix stack overflow that occurs when verify_pred! is used with nested function calls.

  • Fix bug in summarize_diff where actual and expected strings were considered equal despite only one of the two ending in a newline character.

Full Changelog: v0.12.0...v0.13.0