Add ability to gate doctests on cfgs #93083
Labels
A-doctests
Area: Documentation tests, run by rustdoc
T-rustdoc
Relevant to the rustdoc team, which will review and decide on the PR/issue.
Currently, if a doctest uses specific cargo features, you have one of two options for dealing with it:
(A) You can decide to always use
--all-features
when runningcargo test
. This is not great: if you want to test specific features you cannot do so. and also not all crates work with--all-features
since features may be mutually exclusive.(B) You can do the following:
Here, you're conditionally gating the test on the cfg. This works, but it has a major downside: the test will be reported as passing (as opposed to "ignored") in the
cargo test
output, which is misleading and not at all the behavior you want around tests. It's also hacky boilerplate that is necessary for a rather common task.rustdoc
has access to cfg-parsing, it should be possible for it to compile-time-ignore
tests based on acfg()
spec put on top of the code block.The text was updated successfully, but these errors were encountered: