-
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
"cargo test --benches" runs unit tests #6454
Comments
Can you explain more about what you are trying to do? If you are trying to build/run benchmarks in debug mode, then there is an open PR to add that (#6446). As a workaround, you can do |
I disagree. There's no way that this behavior is intended. For one thing, the help text is "Test all benches". Unit tests aren't benches; they aren't in the benches directory and don't have a
Yeah, I submitted that PR :). But then I discovered |
The I'm actually not able to reproduce the issue with
lib and bins can contain both unit tests and benchmarks. So to rephrase this, libs are benchmarkable. Integration tests aren't enabled for benchmarks by default because that probably isn't useful for most people. If you really want to benchmark an integration test, then you can set
Oh, haha, oops, sorry wasn't paying attention.
|
@ehuss you seem to be saying that
I think there are two alternatives that make sense:
I like option 1 better. I think it would be more intuitive. Plus, it would work for crates that use alternative benchmarking libraries, like criterion, easybench, etc. Option 2 would not. |
Depends on how you interpret it. "lib" is a benchmark by default, so it is running tests on lib.
I think that inconsistency makes sense. I definitely would not want
It will run anything marked
Cargo is not capable of doing that kind of introspection, and I doubt it ever will. You can always change the default behavior by setting
Cargo is not making any distinction here. When libtest is running, it runs |
There aren't many ways to interpret it. The help text says it will "Test all benches". Perhaps "lib" is a benchmark for purposes of this command, but that isn't documented anywhere in the help text or in the cargo reference guide. The fact that cargo does this doesn't mean that cargo should do this.
Nor would I. I also wouldn't want
It is a convenience that
Yes it is. It already does. That kind of introspection is what
Without making such a distinction, cargo's @ehuss I think you understand very well what cargo is doing. But you aren't thinking about what cargo should be doing. Its existing behavior is not very useful. Here's an informal survey. I have 988 crates in my |
As of this morning, a significant amount of new documentation was added. The most relevant part is probably https://github.com/rust-lang/cargo/blob/master/src/doc/man/options-targets.adoc which describes the
Ah, I misread what you wrote. I thought it said
It depends on what you are trying to accomplish. I hear what you are saying, though, and this is useful to work through. Others have pointed out confusion with It might also be helpful to distinguish between a target and a mode. |
Sorry to muddle the waters, but on |
@najamelan Can you show a sample project? It should say |
I had a look and it says "running x tests" and then next to the tests it says ignored indeed, so maybe it does not run them, but then why show them in the output for bench?
|
There may not be a specific reason why. That is part of libtest. I would suggest opening an issue on rust-lang/rust and discuss possible improvements there. The code for displaying that particular message is here. Tests are force-ignored here, and then benchmarks are run later below. I don't know why it does it that way. |
Bumping this because lib tests are most definitely not ignored as of Rust 1.69.0. (We're running our tests and benches separately because we're passing libtest harness options to our regular tests.) You can see this by checking out https://github.com/signalapp/libsignal/tree/v0.25.0 and running Sample output
|
(as reply to #6454 (comment))
Except that unfortunately Another use case might be for CI setups where you want to split the execution of the different test targets into separate steps so it is easier to see which of them failed. Also the workaround suggested in #6454 (comment) ( |
Considering that As for doctests, the help output has improved over time to clarify that those aren't normal build targets. With all of the prior documentation improvements, I'm not seeing anything more we can do with this issue. I'm going to propose to the cargo team that we close it.
I believe that sub-thread was referring to having a |
Even if this is working as intended (by the Cargo maintainers), could we have a |
This is definitely a documentation issue, a similar one like #10936. I am not sure if the doc is great enough to close this issue. Should we keep one of them? BTW the new testing-devex team might want to take care of the general confusion of test organization. |
Ah, if we have #10936 for the running of libs generally, then I would recommend we close in favor of that. |
Problem
Running
cargo test --benches
is supposed to build all benchmarks in debug mode and run them. It does that. But if there are unit tests, then it runs them, too. It shouldn't do that. In a workspace the problem is more complicated, because it's possible that there are unit tests in subcrates that have no benchmarks. In that case,cargo test --benches --all
doesn't build those unit tests. But if they've already been built, then it will run them too.Steps
I would expect two executables to run, containing 36 and 20 tests with names like
get_f32
andalloc_big
. Those are the benchmarks. But a third executable gets built and run, with two tests namedbytes::test_original_capacity_from_repr
andbytes::test_original_capacity_to_repr
. Those are unit tests.Here is another example, with a workspace repository.
Steps
I expect that eighteen benchmarks would run and the unit tests would be ignored, just as if I had typed
cargo +nightly bench --all
. But the unit tests don't get ignored, so a total of 26 tests and benchmarks get run.Notes
Output of
cargo version
:On FreeBSD x86_64:
cargo 1.33.0-nightly (28fb200 2018-12-09)
And on Linux x86_64:
cargo 1.31.0-nightly (2d0863f 2018-10-20)
The text was updated successfully, but these errors were encountered: