diff --git a/CHANGELOG.md b/CHANGELOG.md index 313e879..2eebec7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,16 @@ # CHANGELOG +## v0.1.6 +* Support cloning mocks using `#[derive(Clone)]` + * If a mockable struct is annotated with `#[derive(Clone)]`, cloning + a mock instance of that struct will create a new mock instance + that shares any existing and future stubs between the two mock + instances. If this is not your desired behavior for mock cloning + you can still manually implement `Clone` and then use + `faux::when!(my_struct.clone()).then(..)` as you would any other + method. + * [test](/tests/clone.rs) + ## v0.1.5 * Be more explicit about stubbing vs mocking * Fixed issue where faux was requiring MSRV 1.54.0 because of doctests diff --git a/Cargo.toml b/Cargo.toml index 6e7ea83..18e1b31 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "faux" -version = "0.1.5" +version = "0.1.6" authors = ["Andres "] license = "MIT" description = "A library to mock structs" @@ -11,7 +11,7 @@ keywords = ["mock", "mocking", "test", "testing", "faux"] readme = "README.md" [dependencies] -faux_macros = { path = "faux_macros", version = "0.1.5" } +faux_macros = { path = "faux_macros", version = "0.1.6" } paste = "1.0.4" [dev-dependencies] diff --git a/README.md b/README.md index 7a2cd0b..9f4388b 100644 --- a/README.md +++ b/README.md @@ -114,7 +114,28 @@ attributes should be gated to `#[cfg(test)]`.** `faux` also provides easy-to-use argument matchers. -## Interactions With Other Proc Macros +## Interaction with `#[derive(...)]` and auto-traits. + +`faux` mocks will auto implement `Send` and `Sync` if the real +instance also implements it. Using `#[derive(...)]` for `Clone`, +`Debug`, and `Default` will also work as expected. Other derivable +traits are not supported as they are about data (e.g., `Eq`, or +`Hash`) but `faux` is about mocking behavior not data. Deriving traits +that are not part of the standard library is also not currently +supported. An escape hatch for this is to manually write the `impl` +for that trait. If you believe there is a derivable trait that `faux` +should support please file an issue explaining your use case. + +`Clone` is a bit of a special case in that it does not duplicate the +stubs but instead shares them with the cloned instance. If this is not +the desired behavior for cloning mocks you may instead implement +`Clone` manually and do normal method stubbing +(`faux::when!(my_struct.clone()).then_return(/* something */)`). Note +that for the cases of exhaustable stubs (e.g., +`faux::when!(my_struct.foo()).once()`) if either instance calls for +the stub that will count as exhausting the stub as they are shared. + +## Interactions with other proc macros While `faux` makes no guarantees that it will work with other macro libraries, it should "just" work. There are some caveats, however. For diff --git a/faux_macros/Cargo.toml b/faux_macros/Cargo.toml index 27795f7..5c4ac45 100644 --- a/faux_macros/Cargo.toml +++ b/faux_macros/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "faux_macros" -version = "0.1.5" +version = "0.1.6" authors = ["Andres "] edition = "2018" license = "MIT" @@ -13,7 +13,7 @@ keywords = ["mock", "mocking", "test", "testing", "faux"] syn = { version = "1.0.58", features = ["full", "extra-traits"] } quote = "1.0.8" proc-macro2 = "1.0.24" -darling = "0.12.0" +darling = "0.13" [dev-dependencies] faux = { path = "../" } diff --git a/src/lib.rs b/src/lib.rs index 9a66890..915252e 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -13,11 +13,15 @@ //! //! At a high level, `faux` is split into: //! -//! * [`#[create]`](create): transforms a struct into a mockable equivalent -//! * [`#[methods]`](methods): transforms the methods in an `impl` block into -//! their mockable equivalents -//! * [`when!`]: initializes a method stub by returning a [`When`]. Passing optional argument matchers restricts which arguments will invoke the stub. -//! * [`When`]: lets you stub a method's return value or implementation +//! * [`#[create]`](create): transforms a struct into a mockable +//! equivalent +//! * [`#[methods]`](methods): transforms the methods in an `impl` +//! block into their mockable equivalents +//! * [`when!`]: initializes a method stub by returning a +//! [`When`]. Passing optional argument matchers restricts which +//! arguments will invoke the stub. +//! * [`When`]: lets you stub a method's return value or +//! implementation //! //! # Getting Started //! @@ -239,6 +243,8 @@ //! * Generic struct methods //! * Methods with pointer self types (e.g., `self: Rc`) //! * Methods in external modules +//! * Support for `Debug`, `Default`, `Clone`, `Send`, and `Sync` +//! derive/auto traits. //! //! `faux` also provides easy-to-use argument matchers. //!