我正在制作一个 proc_macro 箱子,其中的示例/目录中有 2 个示例。
当我运行cargo test
时,这 2 个示例已编译,但其中一个示例故意失败,导致测试无法运行。我想制作一个无法编译的示例来向用户展示它是如何工作的。
According to the doc此行为的目的是:
They must compile as executables (with a main() function) and load in the library by using
extern crate <library-name>
. They are compiled when you run your tests to protect them from bitrotting.
这很好,但是我如何禁用失败示例的编译?
最佳答案
我找到了!
您可以通过将 autoexamples = false
添加到 [package]
来禁用示例的自动发现
然后您可以通过以下方式自己枚举所有示例:
[package]
...
autoexamples = false
[[example]]
name = "basic"
path = "examples/basic.rs"
关于testing - 使用 cargo 运行测试时如何忽略示例?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60375324/