我有一个实现了 lint 插件的 Rust 库。我想包括 compiletest
,但在测试之外不需要它。指定依赖项仅用于测试的正确方法是什么?
最佳答案
是的。使用 dev-dependencies
。来自Cargo docs :
You can add a
[dev-dependencies]
section to yourCargo.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/