I have a function that can be uses in quite different ways. I would like to give an example for all possible usages, but the set-up required before calling the function is quite long (about 10 lines). Is it possible to share the set-up between multiple tests?
/// common set-up
/// ```
/// let graph = create_graph();
/// let a = graph.add_node();
/// let b = graph.add_node();
/// let c = graph.add_node();
/// ```
///
/// first usage
/// ```
/// foo(graph, a);
/// ```
///
/// second usage
/// ```
/// foo(graph, b);
/// ```
fn foo(g: Graph, node: Graph::Node);
Sorry, cfg(doctest) seems to work only when collecting items, and we cannot link them to the doctest executable.
My idea don't work, and I think such functions available only for doctests is not possible.
(Marking the setup function #[doc(hidden)] might be useful, but it is not elegant because it actually exports the function.)