如何生成#[CFG(TEST)]背后模块的文档?
在一个生锈项目中,有一个带有实用程序支持测试的模块,包装在模块test_utils
中:
#[cfg(test)]
pub mod test_utils;
是否有一种方法来制作货物doc
也生成的文档test_utils
模块和内部的东西?
In a Rust project there is a module with utilities to support testing, packed in a module test_utils
:
#[cfg(test)]
pub mod test_utils;
Is there a way to make cargo doc
generate also the documentation for test_utils
module and the things inside?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
可能有多种用于测试文档的方法,但是我认为更容易的方法是使用
cargo Rustdoc
生成文档,并传递-CFG Test
通过:There are probably multiple ways of generating documentation for tests, but I think the easier approach is to generate the documentation with
cargo rustdoc
and pass the--cfg test
flag through:我刚刚发现这也有效:
虽然文档是常规的
I just found that this works too:
While documentation is generated with regular
我认为
#[CFG(ANY(test,doc))]
可能还不够,它将在没有功能信息的情况下生成DOC。为了与实用程序进行文档支持测试,也许
[CFG_ATTR(非(doc),test)]
是必要的。添加
之后[CFG_ATTR(非(doc),test)]
上面的测试用例:I think
#[cfg(any(test, doc))]
is probably not enough, it will generate doc with no function information.In order to doc with utilities to support testing, perhaps
[cfg_attr(not(doc), test)]
is necessary.After added
[cfg_attr(not(doc), test)]
above test cases: