Skip to content
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 should show test execution time for slower tests #10208

Closed
nyurik opened this issue Dec 16, 2021 · 4 comments
Closed

cargo test should show test execution time for slower tests #10208

nyurik opened this issue Dec 16, 2021 · 4 comments
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`

Comments

@nyurik
Copy link
Contributor

nyurik commented Dec 16, 2021

Problem

cargo test only prints ok/FAILED after each test. In some cases, it might be very useful to see the test duration, similar to mocha-js. Of course this is not as good as having a comprehensive benchmark tests, but in many cases it would give general feedback of how long each test took.

Proposed Solution

Print the time each test took to run in ms, either always, or just for the tests that take longer than some magic number like 10ms:

running 2 tests
test tests::test_fast ... ok
test tests::test_slow ... ok (1200ms)

Notes

Not sure if it would be worth it to introduce attributes to set the expected execution time, something like #[test(slow = 5000)] -- this would clearly be a far wider discussion.

Example from the Mocha project

image

@nyurik nyurik added the C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted` label Dec 16, 2021
@ehuss
Copy link
Contributor

ehuss commented Dec 16, 2021

Thanks for the suggestion! I believe this is already implemented via the --report-time option. I'm going to close in favor of the tracking issue. For future reference, the test harness (the thing that runs the tests and prints the output) is tracked in the https://github.com/rust-lang/rust/ repository as it is not part of cargo.

@ehuss ehuss closed this as completed Dec 16, 2021
@nyurik
Copy link
Contributor Author

nyurik commented Dec 16, 2021

@ehuss thanks for the quick reply -- this is exactly what I was looking for! I so wish it was a bit more discoverable - I searched through the cargo test --help, but didn't realize some of the options were not part of that text (the cargo help test doesn't mention it either). Do you think it would be possible to somehow list all options available after the -- ?

@ehuss
Copy link
Contributor

ehuss commented Dec 17, 2021

cargo help test does point out how to get the information:

For details about libtest's arguments see the output of cargo test -- --help and check out the rustc book's chapter on how tests work at https://doc.rust-lang.org/rustc/tests/index.html.

I don't think we want to replicate all of the help content (and I don't think we can with the built-in help), but I think adding a small mention to run cargo test -- --help at the bottom of cargo test --help would be good. That goes here if you'd like to post a PR.

nyurik added a commit to nyurik/cargo that referenced this issue Dec 17, 2021
Per rust-lang#10208, make `cargo test -- --help` more discoverable.
@nyurik
Copy link
Contributor Author

nyurik commented Dec 17, 2021

Thanks @ehuss , submitted. I wasn't too sure what to call those options - it is not very clear what those options are, as they are part of the rustc default test harness i guess.

bors added a commit that referenced this issue Dec 17, 2021
Minor docs change for `cargo test --help`

Per #10208, make `cargo test -- --help` more discoverable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-feature-request Category: proposal for a feature. Before PR, ping rust-lang/cargo if this is not `Feature accepted`
Projects
None yet
Development

No branches or pull requests

2 participants