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

Use optflag for --report-time #93479

Merged
merged 1 commit into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 3 additions & 11 deletions library/test/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,10 @@ fn optgroups() -> getopts::Options {
unstable-options = Allow use of experimental features",
"unstable-options",
)
.optflagopt(
.optflag(
"",
"report-time",
"Show execution time of each test. Available values:
plain = do not colorize the execution time (default);
colored = colorize output according to the `color` parameter value;
"Show execution time of each test.

Threshold values for colorized output can be configured via
`RUST_TEST_TIME_UNIT`, `RUST_TEST_TIME_INTEGRATION` and
Expand All @@ -125,7 +123,6 @@ fn optgroups() -> getopts::Options {
is 0.5 seconds, and the critical time is 2 seconds.

Not available for --format=terse",
"plain|colored",
)
.optflag(
"",
Expand Down Expand Up @@ -319,17 +316,12 @@ fn get_time_options(
allow_unstable: bool,
) -> OptPartRes<Option<TestTimeOptions>> {
let report_time = unstable_optflag!(matches, allow_unstable, "report-time");
let colored_opt_str = matches.opt_str("report-time");
let mut report_time_colored = report_time && colored_opt_str == Some("colored".into());
let ensure_test_time = unstable_optflag!(matches, allow_unstable, "ensure-time");

// If `ensure-test-time` option is provided, time output is enforced,
// so user won't be confused if any of tests will silently fail.
let options = if report_time || ensure_test_time {
if ensure_test_time && !report_time {
report_time_colored = true;
}
Some(TestTimeOptions::new_from_env(ensure_test_time, report_time_colored))
Some(TestTimeOptions::new_from_env(ensure_test_time))
} else {
None
};
Expand Down
2 changes: 1 addition & 1 deletion library/test/src/formatters/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ impl<T: Write> PrettyFormatter<T> {
if let (Some(opts), Some(time)) = (self.time_options, exec_time) {
let time_str = format!(" <{}>", time);

let color = if opts.colored {
let color = if self.use_color {
if opts.is_critical(desc, time) {
Some(term::color::RED)
} else if opts.is_warn(desc, time) {
Expand Down
1 change: 0 additions & 1 deletion library/test/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,6 @@ fn test_time_options_threshold() {

let options = TestTimeOptions {
error_on_excess: false,
colored: false,
unit_threshold: unit.clone(),
integration_threshold: integration.clone(),
doctest_threshold: doc.clone(),
Expand Down
5 changes: 2 additions & 3 deletions library/test/src/time.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,13 @@ pub struct TestTimeOptions {
/// Denotes if the test critical execution time limit excess should be considered
/// a test failure.
pub error_on_excess: bool,
pub colored: bool,
pub unit_threshold: TimeThreshold,
pub integration_threshold: TimeThreshold,
pub doctest_threshold: TimeThreshold,
}

impl TestTimeOptions {
pub fn new_from_env(error_on_excess: bool, colored: bool) -> Self {
pub fn new_from_env(error_on_excess: bool) -> Self {
let unit_threshold = TimeThreshold::from_env_var(time_constants::UNIT_ENV_NAME)
.unwrap_or_else(Self::default_unit);

Expand All @@ -155,7 +154,7 @@ impl TestTimeOptions {
let doctest_threshold = TimeThreshold::from_env_var(time_constants::DOCTEST_ENV_NAME)
.unwrap_or_else(Self::default_doctest);

Self { error_on_excess, colored, unit_threshold, integration_threshold, doctest_threshold }
Self { error_on_excess, unit_threshold, integration_threshold, doctest_threshold }
}

pub fn is_warn(&self, test: &TestDesc, exec_time: &TestExecTime) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/doc/rustc/src/tests/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ Controls the format of the output. Valid options:

Writes the results of the tests to the given file.

#### `--report-time` _FORMAT_
#### `--report-time`

⚠️ 🚧 This option is [unstable](#unstable-options), and requires the `-Z
unstable-options` flag. See [tracking issue
Expand Down
7 changes: 2 additions & 5 deletions src/doc/unstable-book/src/compiler-flags/report-time.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,8 @@ Sample usage command:
Available options:

```sh
--report-time [plain|colored]
Show execution time of each test. Available values:
plain = do not colorize the execution time (default);
colored = colorize output according to the `color`
parameter value;
--report-time
Show execution time of each test.
Threshold values for colorized output can be
configured via
`RUST_TEST_TIME_UNIT`, `RUST_TEST_TIME_INTEGRATION`
Expand Down