How to define test-only dependencies?

RustRust Cargo

Rust Problem Overview


I have a Rust library that implements a lint plugin. I want to include compiletest, but not require it outside of testing. What is the correct way to specify that the dependency is for testing only?

Rust Solutions


Solution 1 - Rust

Yes. Use dev-dependencies. From the 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.

When possible, you should also use Cargo's resolver version 2 to better handle complicated dev-dependency cases.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionllogiqView Question on Stackoverflow
Solution 1 - RustShepmasterView Answer on Stackoverflow