Description
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:
Building [===================================================> ]
205/215: azul, calculator(example), dragger(example), list(example)
[...]
running 1 test
test style::test_case_issue_93 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 11 filtered out
running 1 test
test css::test_case_issue_93 ... ok
test result: ok. 1 passed; 0 failed; 0 ignored; 0 measured; 78 filtered out
Running target/debug/deps/azul_native_style-bd6572d92ecb73f1
running 0 tests
test result: ok. 0 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out
[...]
real 0m40,153s
user 1m44,308s
sys 0m17,192s
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
- Create a 50 empty examples and 50 doc-tests
- Watch the bar at the bottom fill with
(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.
rustc 1.34.0-nightly (a9410cd1a 2019-02-15)
binary: rustc
commit-hash: a9410cd1af7c1194fbda1457c74b8ab25547e1e6
commit-date: 2019-02-15
host: x86_64-unknown-linux-gnu
release: 1.34.0-nightly
LLVM version: 8.0