Mocktopus icon indicating copy to clipboard operation
Mocktopus copied to clipboard

Injecting functions in external crates

Open CodeSandwich opened this issue 7 years ago • 3 comments

No idea, how to do it, compiler plugin passed to rustc maybe?

CodeSandwich avatar Jun 30 '17 17:06 CodeSandwich

Current research direction: Cargo plugin, which copies all dependencies, injects them automatically with mocking code and compile the original project with these modified crates.

CodeSandwich avatar Jan 15 '18 18:01 CodeSandwich

I have been using mocktopus for this purpose and a strategy similar to test_double. At the moment I am creating a layer of abstraction with third-party libraries which adds a #[mockable] wrapper around the functions and structs being used from the third party libs.

The wrappers actually call the third-party functions internally so that the interface is enforced by the compiler so when they change upstream, it should be obvious through compilation errors. Keeping the interfaces consistent with the upstream is not the most trivial thing in the world but if this is a good approach I am thinking of adding a macro to make these definitions easier.

Any ideas, or other suggestions?

behos avatar Oct 01 '18 17:10 behos

Nice to see Mocktopus being used! For now it seems that you've explored all it has to offer for you. Automatic making dependencies mockable is around pre-alpha state, but blocked by https://github.com/alexcrichton/proc-macro2/issues/89.

CodeSandwich avatar Oct 01 '18 21:10 CodeSandwich