From 61e0e70b97e6e0b7e56bbbc26c1fb75008b4f0e3 Mon Sep 17 00:00:00 2001 From: Alan Somers Date: Thu, 12 Mar 2020 17:33:41 -0600 Subject: [PATCH] Demonstrate mocking a module in mockall_examples --- mockall_derive/src/automock.rs | 5 +++++ mockall_examples/Cargo.toml | 7 +++++++ mockall_examples/src/lib.rs | 10 ++++++++++ 3 files changed, 22 insertions(+) diff --git a/mockall_derive/src/automock.rs b/mockall_derive/src/automock.rs index 538ff356..78bc9ded 100644 --- a/mockall_derive/src/automock.rs +++ b/mockall_derive/src/automock.rs @@ -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 }) } diff --git a/mockall_examples/Cargo.toml b/mockall_examples/Cargo.toml index 4ddc3c41..5ef4d6bd 100644 --- a/mockall_examples/Cargo.toml +++ b/mockall_examples/Cargo.toml @@ -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 = [] diff --git a/mockall_examples/src/lib.rs b/mockall_examples/src/lib.rs index 7b0f20df..6f156dd8 100644 --- a/mockall_examples/src/lib.rs +++ b/mockall_examples/src/lib.rs @@ -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!() + } +}