-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
Let user add directories for auto-discovering tests/bins/... #5766
Comments
This seems plausible to me! I don't believe we've had previous requests to change the directories for auto-inference, but I don't see why not! Recently we added keys like |
@alexcrichton Sounds great! I wasn't sure whether we could have different types for one key (bool vs. string vs. array). But if that's possible, that would be great! Then I'd suggest that
How would we go about implementing this? Does this need an RFC? How are "unstable" things handled in Cargo? Would it need a |
Seems plausible to me! For implementation that can basically happen at any time, so long as it's a nightly feature. We've got a system for handling unstable nightly-only feautres in Cargo (similar to rustc) and the UI would basically require something like:
|
@alexcrichton I have a question. So I started working on this and already spotted the place where most changes are necessary: But now after having a rough understanding of the module, I feel like it could use some cleanup. And I don't mean small things, but basically a rewrite of this module. Why? I think the whole code can be significantly shortened and made faster. For example, right now, many functions return So my question is: what is the policy on cleanup/partial rewrite PRs? So of course, cleanup commits are annoying for files that are frequently changed by many people. This (if I were to rewrite that module, I would of course write a lot of documentation/comments to clarify things) |
Fixes, cleanup, and documentation are all more than welcome! I know @matklad may have some thoughts about this module, but IIRC it's historically a relatively unloved module that would definitely appreciate some love |
Yes, we love rewrites for readability! I would be especially thrilled if the |
Two things. First, my work on this will be a bit delayed. Secondly: I initially liked the
So if we instead let the user add the path to all tests in a |
A project I'm working on has dozens of tests that need to be run without the harness. Currently they're exhaustively listed with
This would address my use case certainly. As I see it, the expansion to Cargo.toml
The The logic to special-case ./src/bin, ./examples, ./tests, etc could presumably be moved atop or merged with the work to achieve the above. The other option that would also address my use case is adding another key at the |
@LukasKalbertodt I don't think we have a great way to interpret multiple paths per test though, right now each test in target is a crate (aka one rustc invocation), but multiple paths necessitate multiple crates? @alecmocatta your use case definitely makes sense! We may be able to do something like @LukasKalbertodt is mentioning though one way or another to solve that? I'm not entirely sure what it might look like though |
This would be great for bins too, right now automatic discovery is only available for |
To provide a concrete example, I am writing Project Euler solutions and as a result have hundreds of small bins. For organizational reasons I'd prefer they were not in a flat tree, and for stylistic reasons I'd rather they were not in In my case a glob could be effective, it would be something like For now I have a small script to generate |
For the original project, one workaround isn't mentioned: have a |
For making it easier to configure a bunch of tests, we have another issue about setting defaults for crate kinds (bin, test, etc). For a lot of bins, I suspect "cargo script", maybe combined with workspace support, would be a better fit. For the original request here, it doesn't sound too bad. However, we've had related requests that mostly exist to have projects deviate from the standard (#2725, #12672) and we've closed those due to the challenges that a lack of consistency would cause end-users contributing. Since we closed those, I'm going to go ahead and close this. If there is a reason we should re-evaluate, let us know! |
Please excuse if this has been asked before -- I couldn't find anything.
Hi there!
Cargo auto-discovers certain things: integration tests, binaries, benchmarks and examples. For each of those categories, Cargo looks in a specific folder (
tests/
, ...). Thanks to #5330 we can now disable or enable auto-discovery explicitly.I think it would be really useful if the user can specify custom directories that are used for auto discovery. For example, consider my use case: I am working on a proc-macro and want to make sure that certain programs compile fine with my macro (run-pass) and that other programs will result in a compiler error (compile-fail).
compile-fail
tests are not supported by Cargo, but at least I can write my own script (withharness=false
) that will execute my custom tests.run-pass
tests are of course normal integration tests supported by Cargo.All my compile-fail tests are in
tests/compile-fail/
. It would be neat if I could place my run-pass tests intotests/run-pass/
... to have some kind of symmetry. Sadly, as I understand it, it's not currently possible without listing every single run-pass test with its own[[test]]
section inCargo.toml
.To be specific, what I'd like to have is the following. Folder layout:
Cargo.toml
src/
tests/
compile-fail/
.rs
filesrun-pass
.rs
filescompile_fail.rs
The
compile_fail.rs
script uses all files incompile-fail/
as a single test and executes them accordingly with my own logic.Cargo.toml
:The only way to do this right now is:
tests/
directly which leads to asymmetryCargo.toml
as a seperate[[test]]
sectioncompile-fail
)All possibilities are sub-optimal, I think.
Please note that I don't care about the syntax. I think the wildcard above is pretty natural, but I'm also fine with other solutions, such as
auto-discover = "tests/run-pass/"
.So....
Thanks!
The text was updated successfully, but these errors were encountered: