nrxus / faux

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

emit #[cfg(any(test, rustdoc))] in the macro expansions #19

Closed nrxus closed 4 years ago

nrxus commented 4 years ago

per: https://users.rust-lang.org/t/announcing-faux-a-traitless-mocking-library/37303/2

nrxus commented 4 years ago

After more thought and a quick implementation I've realized this is actually not what I want.

The goal of this was to allow the user to do:

#[faux::create]
struct Foo {}

#[faux::methods]
impl Foo {}

rather than:

#[cfg_attr(test, faux::create)]
struct Foo {}

#[cfg_attr(test, faux::methods)]
impl Foo {}

But this would force faux to be a real dependency rather than a dev-dependency, which leaves room to accidentally leak faux through in a real implementation (the user now has to trust faux to guard everything correctly). faux is for testing only and thus should be a dev-dependency only, forcing the user to have faux as a dependency feels wrong.

Closing since I think it would harm more than benefit.

Super Off-Topic stuff below

I had an idea a while ago to have attribute aliases but I never got around submitting an RFC for it to allow something like

// made up syntax I did not give much thought to
#[cfg_alias(mock_struct = "cfg_attr(test, faux::create)")]
#[cfg_alias(mock_methods = "cfg_attr(test, faux::methods)")]

which would then allow for something like:

#[mock_struct]
struct Foo {}

#[mock_methods]
impl Foo {}

I think this would be the "ideal" solution for me, but alas is not currently doable in Rust.