All notable changes to this project will be documented in this file. This project adheres to Semantic Versioning.
mock!
and#[automock]
now supportunsafe
traits. (#313)
- Bump
predicates
to v2.0.1, see all v2 changes in predicates' changelog. (#325)
- Fixed nondeterministic code generation in methods with multiple lifetime parameters. (#333)
-
Fix mocking specializing methods of non-generic structs, a regression in v0.10.0. (#309)
-
Fix mocking generic methods of generic structs returning nonstatic, a regression in v0.10.0. (#312)
- Fix mocking trait methods whose return values have lifetime parameters, a regression in v0.10.0. (#304)
-
mock!
will now allow both methods and trait impls to be gated with#[cfg()]]
attributes. The attributes will be forwarded to all generated code. This allows for example only mocking certain traits on certain OSes. (#297) -
automock will now automatically generate Debug implementations for traits and structs. mock! will to, if you put
#[derive(Debug)]
above the struct's name. (#289) -
Added support for specific impls. A specific impl is an implementation of a trait on a generic struct with specified generic parameters. For example,
impl Foo for Bar<i32>
as opposed toimpl<T> Foo for Bar<T>
. Mockall does not yet support generic methods in such traits. (#274)
- Mockall is pickier now about how you mock a trait on a generic struct.
Previously you could usually omit the generics. Now, they're required.
i.e.,
should now be written as
mock!{ MyStruct<T: Bounds> {...} impl Foo for MyStruct {...} }
(#274)mock!{ MyStruct<T: Bounds> {...} impl<T: Bounds> Foo for MyStruct<T> {...} }
- Fixed setting simultaneous expectations with different generic types on generic methods whose generic parameters appear in neither the arguments nor the return type. (#272)
-
When a test fails because of a method sequence violation, the error message will now show the method's arguments. This requires the
nightly
feature, and requires that the arguments implementDebug
. (#247) -
When a test fails because a mock object receives an unexpected call, the error message will now show the method's arguments. This requires the
nightly
feature, and requires that the arguments implementDebug
. (#246)
-
Fixed Clippy warnings in generated code with Rustc 1.52.0. (#255)
-
Fixed using
#[automock]
with#[tracing::instrument]
. The mock function won't be instrumented, but at least it will compile. (#256)
-
Added the ability to mock methods returning
impl Future
orimpl Stream
. Unlike other traits, these two aren't very useful in aBox
. Instead, Mockall will now change the Expectation's return type toPin<Box<_>>
. (#229) -
Added the ability to mock methods returning references to trait objects. (#213)
-
mock!
supports a new syntax: "impl Trait for". It has two benefits:- It can implement a generic trait for specific generic type(s).
- It allows mocking a non-local trait. The syntax looks like this:
mock! { Bar {} impl Foo<i32> for Bar { fn foo(&self, x: i32) -> i32; } }
(#205)
-
#[automock]
now works on modules even without thenightly
feature, and no longer requires#[feature(proc_macro_hygiene)]
. (#198)
-
mock!
now requires visibility specifiers for inherent methods. (#207) -
Changed the syntax for mocking foreign functions. Instead of using
#[automock]
directly on theextern
block, you must wrap theextern
block in a module, and#[automock]
that module. The old method is deprecated. (#201)
-
Fixed mocking methods that return
Self
inside of a trait object with multiple bounds. For example:-> impl Future<Output=Self> + Send
(3400916) -
Fixed setting multiple expectations on generic methods whose only generic type is the return. (#238)
-
Fixed mocking generic structs with generic methods whose only generic types are lifetimes. This is useful for mocking generic structs that implement traits like
Future
andStream
. (#225) (#226) (#228)
- Removed
times_any
andtimes_range
methods from Expectations. They've been deprecated since 0.3.0. (#197)
- Suppressed
default_trait_access
pedantic Clippy lint in generated code (#222)
- Fixed Clippy warnings for mocked methods with
Vec
orString
arguments. (#195)
- Fixed using
<X as Y>::Z
syntax in a where clause or a return type. (#208)
-
Added support for mocking structs and traits with associated constants. (#187)
-
Methods returning slices can now be mocked. Their expectations take
Vec
s. (#185) -
Compatibility with the
#[async_trait]
macro. (#183) -
Better support for non-Send types:
- Added
return_const_st
for returning non-Send
constants, similar toreturning_st
. - Added
return_once_st
for static methods. It was already available for non-static methods. (#178)
- Added
-
Support mocking methods with arbitrary receivers like
self: Box<Self>
(#176) -
Support mocking methods with trait object arguments that use implicit lifetimes. (#174)
-
Raised the minimum supported Rust version (MSRV) to 1.42.0. (#175)
-
Mocked modules now have the same visibility as the original module. (#169)
-
Fixed mocking modules including functions that use "impl Trait" or mutable arguments. (#169)
-
Fixed mocking methods whose generic types include
super::
. (#167) -
Fixed mocking generic methods with where clauses returning references. (#166)
-
Fixed mocking generic methods returning mutable references. (#165)
-
Suppressed
incomplete_features
warnings in the latest nightly. (#161)
-
Fixed handling function attributes. They already worked on methods, but not foreign functions or module functions. (#129)
-
Propagate doc comments for module functions to the generated mock functions. (#132)
-
Fix the formatting of generated doc comments for context methods (#132)
-
Fixed some visibility issues in the generated mocks for modules and extern functions. (#133)
-
Fixed mocking methods with complicated types including a
super::
component. (#137) -
Mocked generic static methods can now use
return_const
. This capability was omitted as an oversight from PR #47. (#141) -
Suppressed
unused unit
warnings from Clippy in the latest nightly. (#148)
-
mock!
now allows doc comments in any position (#102) -
Added the ability to match non-
Send
arguments withwithf_st
(#93) -
Added the ability to mock non-
'static
structs (but not their constructor methods) (#114)
-
Fixed the docs for
mockall_examples
(#103) -
Fixed the build with nightly compilers 2020-03-11 and later. This also raises the MSRV to 1.36.0. (#108)
-
The proc macros will now build successfully in crates that set
#![deny(missing_docs)]
(#107) -
Fixed mocking methods with an explicit receiver lifetime like
&'a self
(#112)
- Added the ability to mock generic methods whose return values' lifetimes are
chosen by the caller. Especially useful with
std::future::Future
(#86)
-
Fixed using
prediate::always
andprediate::never
with?Sized
types (#80) -
Fixed mocking methods when a custom
Result
type is in-scope. (#74)
- Mock objects' checkpoint methods will no longer check static expectations. This behavior is more useful where static and regular methods are both used in the same test. The old behavior was a relic from release 0.3.0 and before, when static methods did not yet have Context objects of their own. (#64)
- Fixed hygiene violations in some of mockall_derive's warnings. (#63)
-
Fixed using super:: in the signature of a bare function (#54)
-
Fixed automocking modules that contain use statements importing types that are used in function signatures. (#53)
-
Many generic methods with lifetime parameters can now be mocked. The condition is that they may not also have generic type parameters, and their return values must be
'static
. (#48) -
Reexport more traits from the predicates crate (09746e9)
return_const
now works for static methods with no precedingwith
orwithf
. (#47)
-
Warnings for misued expectations and context objects (#37)
-
Methods with closure arguments and where clauses can now be mocked. (#35)
-
Mocked static methods and free functions now use a Context object to manage their expectations. The context object will validate call counts when it drops, and clean up any leftover expectations. This makes it practical to use mocked free functions from multiple test cases. The user still will most likely need to provide his own synchronization to prevent such test cases from running concurrently. (#34)
- Better panic messages when an expectation fails its expected call count. (#33)
-
Fixed mocking methods that return
'static
deref types, like&'static str
(#39) -
Methods returning non-
'static
references (mutable or otherwise) will now return a default value if no return value is set, if the output type implementsDefault
and thenightly
feature is enabled. This more closely matches existing behavior for methods returning non-reference types. (#32)
- Methods with closure arguments can now be mocked. Technically they always
could be, but until now it wasn't possible to call the closure argument from
withf
orreturning
. No special tricks are required by the user. Similarly, methods with bare fn arguments can be mocked, too. (#15)
-
It is no longer necessary for consuming crates to explicitly depend on fragile, downcast, or predicates-tree. Mockall now reexports them. (#29)
-
The MSRV is now Rust 1.35.0 (#15)
-
The
times
method now accepts ranges as arguments.types_any
andtimes_range
are deprecated. (#14)
-
Fixed mocking methods with arguments or return values that use
Self
as an associated type of some other trait. (#28) -
Fixed mocking structs and traits with more than one static method. (#22)
-
Methods of generic structs and traits that reference
Self
(such as constructors or comparators) can now be mocked without any hacks. (#21) (#25) -
Specializing methods of generic structs (and traits) can now be mocked without the hack of duplicating the struct's (or trait's) generic parameters. (#20)
-
Static methods of generic structs (and traits) can now be mocked without the hack of duplicating the struct's (or trait's) generic parameters. (#19)
- Fixed some hygiene problems introduced in 0.2.0 (db25804)
-
Support mocking generic specializing methods. (#13)
-
Correctly handle where clauses on mocked methods. (#13)
-
Allow mocking generic constructor methods (#11)
-
Allow mocking methods that use
super
somewhere in their signatures. (#8)
-
Fixed
#[automock]
fornew
methods with arguments. (#3) -
Fixed the
never
method, which never actually worked. (#10) -
Fixed mocking generic traits or structs with generic methods (6126359)
-
Fixed an issue with using associated types in generic parameter bounds (116e5a2)
-
Fixed mocking methods with mutable arguments (8058701)
- Removed
expectation!
, used to manually mock methods in rare circumstances. Nowmock!
and#[automock]
are the only way to use Mockall. (#12)
- Fixed some issues in the API docs. No functional change. (ba88fd1)