Skip to content

Commit

Permalink
Demonstrate mocking a module in mockall_examples
Browse files Browse the repository at this point in the history
  • Loading branch information
asomers committed Mar 13, 2020
1 parent aeddf90 commit 61e0e70
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions mockall_derive/src/automock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -615,7 +615,12 @@ fn mock_module(mod_: ItemMod) -> TokenStream {
/// Verify that all current expectations for this function are
/// satisfied and clear them.
pub fn checkpoint() { #cp_body }).to_tokens(&mut body);
let docstr = {
let inner_ds = format!("Mock version of the `{}` module", mod_.ident);
quote!( #[doc = #inner_ds])
};
quote!(
#docstr
pub mod #modname { #body })
}

Expand Down
7 changes: 7 additions & 0 deletions mockall_examples/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,10 @@ Examples of autogenerated mock objects by Mockall

[dependencies]
mockall = { version = "= 0.6.0", path = "../mockall" }

[package.metadata.docs.rs]
features = ["nightly"]

[features]
# Extra features for the nightly compiler only
nightly = []
10 changes: 10 additions & 0 deletions mockall_examples/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,13 @@ extern "C" {
/// A foreign "C" function
pub fn ffi_func();
}

#[cfg(all(doc, feature = "nightly"))]
/// Mock this entire module
#[automock]
mod a_module {
/// A function in a mocked module
pub fn modfunc() {
unimplemented!()
}
}

0 comments on commit 61e0e70

Please sign in to comment.