#How do I use code from the `tests` module within my doc-tests?

18 messages · Page 1 of 1 (latest)

sonic root
#

I've written some code that models, amongst other things, a connection and communication between different processors. Thanks to #981431562786725948, I created an mpsc channel and was able to mock-up a mode of communication, thereby having some unit tests with which to work.

Now I've moved onto the documentation tests, and I was hoping to use the same code again. However, the doc-tests don't seem to find the tests module I've created, so I'm stuck.

#

It's as if anything annotated with #[cfg(test)] disappears while the doc-tests are run compiled.

#

(Complication: The test module uses std, while the rest of the crate does not.)

#

I tried replacing #[cfg(test)] with #[cfg(any(test, doc))], but to no avail.

tough dock
#

You have basically one option, use a custom cfg flag to enable the module and build your doctests with that cfg flag enabled

tough dock
sonic root
#

The latter already exists.

#

Though, from what I just read, there is such a thing as a doctest attribute.

tough dock
sonic root
#

But I included it, and it still doesn't work.

tough dock
sonic root
#

CRAP.

sonic root
tough dock
#

This is a common pattern

sonic root
#

…that actually sounds tolerable.

tough dock
#

And also hide the macro rules with a #[doc(hidden)]

tough dock