rust - 如何定义仅测试依赖项?

标签 rust rust-cargo

我有一个实现了 lint 插件的 Rust 库。我想包括 compiletest,但在测试之外不需要它。指定依赖项仅用于测试的正确方法是什么?

最佳答案

是的。使用 dev-dependencies。来自Cargo docs :

You can add a [dev-dependencies] section to your Cargo.toml whose format is equivalent to [dependencies]:

[dev-dependencies]
tempdir = "0.3"

Dev-dependencies are not used when compiling a package for building, but are used for compiling tests, examples, and benchmarks.

如果可能,您还应该使用 Cargo 的 resolver version 2更好地处理复杂的开发依赖案例。

关于rust - 如何定义仅测试依赖项?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29857002/

相关文章:

rust - 根据编译目标操作系统,Rust 中将不同类型的值分配给变量的惯用方式是什么?

rust - 错误 : could not compile `time` when using cargo to compile

我可以发布一个使用补丁的 crate 吗?

rust - 为什么#[derive(Show)] 不再起作用了?

rust - 获取字符的控制台宽度

function - 如何在 Rust 中将函数作为参数传递

rust - 为什么在使用 diesel::insert_into 时发现 "no method named ` execute`?

rust - 类型组的通用枚举

compiler-errors - Rust 编译错误 : process didn't exit successfully

rust - 入门Actix-web : failed to run custom build command for `brotli-sys v0.3.2` 时出错