-
Notifications
You must be signed in to change notification settings - Fork 13.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Auto merge of #64873 - popzxc:prettify-test-time, r=wesleywiser
Enhance report-time option ## Short overview This PR is a follow-up to a previously closed #64714 PR. ## Changes introduced by this PR * `libtest` now retrieves the type of the test within `TestDesc` (available types are: `UnitTest`, `IntegrationTest`, `DocTest`, `Unknown`). * `--report-time` subcommand of the `libtest` now supports colored output (disabled by default). * Colorized output depends on the threshold values. Default values (proposed by @wesleywiser): - For unit-tests: 50ms warn/100ms critical, - For integration-tests: 500ms warn/1000ms critical, - For doctests: same as for integration tests, - For unknown tests: `TEST_WARN_TIMEOUT_S` warn/ `TEST_WARN_TIMEOUT_S * 2` critical (it will only applied single-threaded mode, because otherwise test will be interrupted after reaching `TEST_WARN_TIMEOUT_S`). - These values can be overrided by setting environment variables (since those thresholds are somewhat constant for every project, it's more flexible to use environment variables than command line arguments). * New optional flag `--ensure-test-time` for `libtest`. With this flag applied, exectuion time limit excesss will cause test failure. ## What have not been done There was a comment that it would be nice to have an entry in the Cargo book about it. However, changes introduced by this PR (and #64663 in which `report-time` flag was added) aren't related directly to `cargo`, it's more about `libtest` itself. I'm considering that [The Unstable Book](https://doc.rust-lang.org/unstable-book/) is more appropriate place, but not sure if I'm right (and if so, how exactly it should be described). As one possible option, this PR may be merged without denoting it in the documentation, and in the next PR adding support of this feature to the `cargo` itself, I'll add a note in the Cargo book. ## Scope of this PR Logical scope of this PR is `libtest` only. However, to get test types, I had to modify also `libsyntax_ext` and `librustdoc` for them to provide information about test type. ## Rationale Rationale for colored output was submitted in #64714 Providing the information about kind of test was also proposed in #64714, and as an additional benefit this information may be useful for the tools using `libtest` (e.g. `cargo`). Adding flag to treat time limits excess seems logical to me, so projects that do care about test execution time won't have to invent a wheel. ## Backward compatibility All the changes are completely backward compatible. ## Demo ![rustc_enhanced_time](https://user-images.githubusercontent.com/12111581/65818381-c04f6800-e219-11e9-9875-322463abe24f.gif) r? @wesleywiser
- Loading branch information
Showing
9 changed files
with
718 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# `report-time` | ||
|
||
The tracking issue for this feature is: [#64888] | ||
|
||
[#64888]: https://github.com/rust-lang/rust/issues/64888 | ||
|
||
------------------------ | ||
|
||
The `report-time` feature adds a possibility to report execution time of the | ||
tests generated via `libtest`. | ||
|
||
This is unstable feature, so you have to provide `-Zunstable-options` to get | ||
this feature working. | ||
|
||
Sample usage command: | ||
|
||
```sh | ||
./test_executable -Zunstable-options --report-time | ||
``` | ||
|
||
Available options: | ||
|
||
```sh | ||
--report-time [plain|colored] | ||
Show execution time of each test. Awailable values: | ||
plain = do not colorize the execution time (default); | ||
colored = colorize output according to the `color` | ||
parameter value; | ||
Threshold values for colorized output can be | ||
configured via | ||
`RUST_TEST_TIME_UNIT`, `RUST_TEST_TIME_INTEGRATION` | ||
and | ||
`RUST_TEST_TIME_DOCTEST` environment variables. | ||
Expected format of environment variable is | ||
`VARIABLE=WARN_TIME,CRITICAL_TIME`. | ||
Not available for --format=terse | ||
--ensure-time | ||
Treat excess of the test execution time limit as | ||
error. | ||
Threshold values for this option can be configured via | ||
`RUST_TEST_TIME_UNIT`, `RUST_TEST_TIME_INTEGRATION` | ||
and | ||
`RUST_TEST_TIME_DOCTEST` environment variables. | ||
Expected format of environment variable is | ||
`VARIABLE=WARN_TIME,CRITICAL_TIME`. | ||
`CRITICAL_TIME` here means the limit that should not be | ||
exceeded by test. | ||
``` | ||
|
||
Example of the environment variable format: | ||
|
||
```sh | ||
RUST_TEST_TIME_UNIT=100,200 | ||
``` | ||
|
||
where 100 stands for warn time, and 200 stands for critical time. | ||
|
||
## Examples | ||
|
||
```sh | ||
cargo test --tests -- -Zunstable-options --report-time | ||
Finished dev [unoptimized + debuginfo] target(s) in 0.02s | ||
Running target/debug/deps/example-27fb188025bec02c | ||
|
||
running 3 tests | ||
test tests::unit_test_quick ... ok <0.000s> | ||
test tests::unit_test_warn ... ok <0.055s> | ||
test tests::unit_test_critical ... ok <0.110s> | ||
|
||
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out | ||
|
||
Running target/debug/deps/tests-cedb06f6526d15d9 | ||
|
||
running 3 tests | ||
test unit_test_quick ... ok <0.000s> | ||
test unit_test_warn ... ok <0.550s> | ||
test unit_test_critical ... ok <1.100s> | ||
|
||
test result: ok. 3 passed; 0 failed; 0 ignored; 0 measured; 0 filtered out | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.