知识卡片

普通读书笔记卡 · 6075.a.4

文档示例可纳入测试

理解等级:中级

Rust文档中的代码示例通常可由rustdoc包装为测试,cargo test –doc可单独检查相应示例,使接口改动及时暴露用法漂移。no_run、ignore、compile_fail等标记会改变处理方式,不能把有代码块等同实际执行过。示例应同时清楚解释预期和适用条件。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 5. Tooling Doc Tests · 查看原书依据

      Doc Tests Item 27 described the inclusion of short code samples in documentation comments, to illustrate the use of a particular public API item. Each such chunk of code is enclosed in an implicit fn main() { ... } and run as part of cargo test, effectively making it an additional test case for your code, known as a doc test. Individual tests can also be exe

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第5章《Doc Tests》(spine9;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch05.html;u154-ch05-024)。 - 结论依据:原文在“Doc Tests”附近的定义、例子或代码支撑本卡核心说明:Rust文档中的代码示例通常可由rustdoc包装为测试,cargo test --doc可单独检查相应示例,使接口改动及时暴露用法漂移。边界按已读前提解释;示例未执行。 - 原始内容:Doc Tests Item 27 described the inclusion of short code samples in documentation comments, to illustrate the use of a particular public API item. Each such chunk of code is enclosed in an implicit fn main() { ... } and run as part of cargo test, effectively making it an additional test case for your code, known as a doc test. Individual tests can also be exe