testing - 使用 cargo 运行测试时如何忽略示例?

标签 testing rust rust-cargo

我正在制作一个 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/

相关文章:

rust - 如何在 Rust 2018 中惯用地为箱子起别名?

shared-libraries - 从 cargo dylib 命名中删除哈希扩展

testing - 如何找到用于 Cargo 测试的资源?

ruby-on-rails - RSpec:如何正确测试循环通过集合/调用实例方法的类方法

可以生成图形的性能测试工具

mongodb - 如何使用 Rust MongoDB 驱动程序从添加到 GridFS 的文件中获取 ID?

rust - 参数数量/类型不匹配

html - 如何从 Selenium IDE 的下拉无序列表中选择一个元素

node.js - 为 nightwatch.js 添加链接 .not() 自定义断言

sockets - Rust 中的原始套接字