-
Notifications
You must be signed in to change notification settings - Fork 2.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cargo package
could run tests in the packaged tree
#14685
Comments
cargo package
could run tests in the packaged tree
Nothing forces a crate to include tests. In fact, there are valid reasons (circular dependencies) for people to setup their package for their dev dependencies to be stripped, making the package untestable. There is likely other content that would be relevant for restarting a project that would be missing and I don't think a
Where do we draw the line on validating a
When considering CLI flags, I ask the questions
If we do this, I wonder if this would instead be better served with by a
In #13491, someone suggests we split |
The cargo team discussed this today and overall we felt like this would need more design work and exploration. There are two orthogonal things to consider, should it be possible to run tests from a packaged crate, and separately how to run those tests. Another consideration is that "running tests" for some projects can be a relatively complex thing. One option is to have a config option for opting-in to running tests after packaging. It's not really clear how that opt-in should look exactly. I would encourage experimenting with a plugin to move forward. We have been trying to consider how high- or low-level commands like |
That all makes sense, thanks. I'm content for you to close this unless you especially want to keep it. |
For now, I think its worth keeping open. When discussing #14941, the question came up if the verify step is a packaging sanity check or a baseline quality check. As a packaging check, we likely don't need to run tests. As a quality check, opting into tests and maybe ratcheting up on that could be useful. I plan to write up more on that discussion and do some investigation when I'm back at my computer. |
Like with #14941, a big question is what the role of the verify step should be
(see #14941 for more details on) So the first question: is running tests on a
For a last-ditch baseline quality check, how much is verification is sufficient?
So the second question is how much verification is "enough"?
Now the third question is whether If configuring verification is focused on plumbing, then it could be in config (which includes env variables and If configuration verification is focused on porcelain, then any transient configuration can easily be forgotten between invocations which would favor putting it in a config file or the manifest. |
A reason that would limit people implementing this on their own is that we don't expose the details necessary for them to mix |
Problem
Today, cargo package has an option (by default on) to run a build in the packaged tree, to increase confidence that the package will build when downloaded.
Some users would like to check that the tests also pass in the package crate.
Distro packaging of Rust tools
In particular, Debian and probably other distributions that repackage Rust software would like to:
However in cargo-mutants we found that the tests didn't pass in a tree unpacked from a cargo crate, because some testdata files were excluded. (See https://sources.debian.org/patches/rust-cargo-mutants/23.10.0-1/disable-tests-missing-testdata.patch/, and cc @jelmer.)
Archiving packages
Arguably there's also value in crates.io archiving a copy of the tree that's sufficiently complete that someone could resume development from that crate if the VCS repository was lost, and this will be much more feasible if the tests are known to pass. For widely cloned git repos this might seem unlikely, but there might be some crates where the released source is open but the VCS is not.
Proposed Solution
If this is acceptable in principle I could send a PR that adds
cargo package --test
(andcargo publish --test
) that will run the tests in a copy of the packaged tree. The option would be off by default.Counter-arguments
Package size
One conceivable argument against this is that including all the tests and testdata to make the tests pass will make the package larger, which will increase bandwidth consumption for both crates.io and users. Probably a large majority of clients that download packages do not run or even build their tests, as they only want to build the library or binary.
Perhaps some crates have very large testdata directories that today are excluded, but adding this option might motivate their authors to include them in the package.
I think that might happen at the margin but I don't think it's a conclusive reason not to do it:
Not strictly necessary
Another conceivable and reasonable argument against adding this feature is that it's not that hard to unpack the tarball and run the tests yourself, so it's not worth adding the complexity of another feature to cargo.
Against this I think there are some reasons to have it built in:
The text was updated successfully, but these errors were encountered: