I'm in the process of learning Rust and putting together my first crate (a simple clone of
wc). I was reading through the Cargo Manifest format's exclude field docs and am wondering if the best practice is to exclude the files in the
Here's what the
Cargo.toml would look like for what I'm asking:
I searched online to try to find an answer, but I didn't seem to find any answers.
A little more context: I've got one test file,
test/cli.rs and three fixture text files that the tests run against.
The fixture text files and test file aren't necessary for actually running the program, so should they be distributed with the packaged project or excluded to reduce the size?
If you had an especially large test data file (megabytes), it might make practical sense to exclude it, and the test that needs it, to save download time and disk space. But if reasonable, you should just publish your package with its tests.
An advantage of doing so is that if at any time some question of “did this code ever work? is my system weird?” comes up (which can happen, for example, if dependencies of your package make accidental incompatible changes, or if something in the external software environment not managed by
cargo changes), people can run your tests in the version you published to crates.io (as opposed to having to cross-reference with your repository commits).
More definitely, the Rust compiler developers use a tool called
crater to run many crates' tests against specific compiler versions. This is used to discover bugs and also to answer questions like “If we changed this tiny little detail, would anything that we can find break?” So, by publishing your package with tests, you're contributing to the future of Rust.
That all makes so much sense, thank you!
This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.