nrxus / faux

Struct mocking library for Rust
https://nrxus.github.io/faux/
MIT License
411 stars 14 forks source link

Mock an entire module #12

Open nrxus opened 4 years ago

nrxus commented 4 years ago

Ideally something like this would work

// imagine this is the start of a module
#![faux::mock]

struct Foo {}

impl Foo {}

/* more structs and impls here */

Unfortunately custom inner attributes are not supported

I would also be okay with

#[faux::mock]
mod foo; // mocks all of foo.rs

But this currently returns a ModItem with no body.

The alternative is:

// inside foo.rs
#[faux::mock]
mod inner_foo {
  struct Foo {}

  impl Foo {}
}

pub use inner_foo::*;

There is a clear ergonomic hit to this latter approach though. I would very much dislike foricng the user to write this kind of code just to support faux. This makes me unsure if a mod-level macro would be that useful until either option 1 or 2 are allowed.