-
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
When running cargo test, cargo also re-builds all examples #6675
Labels
C-bug
Category: bug
Comments
The workaround to just run unit tests is invoking |
link2xt
added a commit
to deltachat/deltachat-core-rust
that referenced
this issue
Jul 10, 2023
When `cargo test` is executed, all examples are built by default to ensure that they can be compiled. This is a documented and expected behaviour, even though it was previously reported as a bug: <rust-lang/cargo#6675> In particular, `examples/simple.rs` is built into a 67M binary `target/debug/examples/simple`. This is unnecessary to do so every time you change a line in the `deltachat` crate and want to rerun the tests. Workaround is to run `cargo test --tests`, but it is easy to forget and is not discoverable unless you read the "Target Selection" section of `cargo help test`. We have a maintained example at https://github.com/deltachat-bot/echo, so there is no need for an example in the core repository.
link2xt
added a commit
to deltachat/deltachat-core-rust
that referenced
this issue
Jul 10, 2023
When `cargo test` is executed, all examples are built by default to ensure that they can be compiled. This is a documented and expected behaviour, even though it was previously reported as a bug: <rust-lang/cargo#6675> In particular, `examples/simple.rs` is built into a 67M binary `target/debug/examples/simple`. This is unnecessary to do so every time you change a line in the `deltachat` crate and want to rerun the tests. Workaround is to run `cargo test --tests`, but it is easy to forget and is not discoverable unless you read the "Target Selection" section of `cargo help test`. We have a maintained example at https://github.com/deltachat-bot/echo, so there is no need for an example in the core repository.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Problem
When running
cargo test
, cargo re-builds all examples, even though they are never run. This makes re-running tests very slow, because if you only want to re-run one test, you have to wait for all examples to build - and especially since cargo for some reason compiles the code and the examples twice, the compilation times for re-running just a single test are extreme. Right now, rebuilding just one single test takes 1m 50s on my machine, this isn't good.Steps
I am not sure if you can observe this with an empty example. I noticed it because of the progress bar at the bottom - every time I change a test and re-run
cargo test
, it shows this:1 minute 44 seconds to re-run a single test - and I just added a space to the test, didn't even refactor anything. The repository I was working on is azul. If you want to reproduce it, please clone the repository, change a single test (so it recompiles) and watch the progress bar. On a hello world repository it's probably not noticable, but technically the steps are:
cargo new --bin my_example
(example)
This happens even when I specify the test name case. I.e. I can specify "test_issue_93" to run, but it will still compile the examples, for no reason.
Possible Solution(s)
Don't compile examples when the user provides a test name case or passes
--doc-tests
(to only run doc tests) and provide a flag like--no-examples
to stop the examples from being compiled. Also, cache the examples and make the build faster, but that's probably more advanced. I mean, why would I need to re-build all examples if all I want to do is to re-build a single test case?Notes
Output of
cargo version
:cargo 1.34.0-nightly (865cb7010 2019-02-10)
Additional information
This happens on all versions of cargo from 1.30 to 1.34.
The text was updated successfully, but these errors were encountered: