Skip to content

Commit cb5733d

Browse files
committed
Improve code style
1 parent 85628e8 commit cb5733d

File tree

9 files changed

+41
-21
lines changed

9 files changed

+41
-21
lines changed

src/libtest/cli.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -329,7 +329,11 @@ fn get_test_threads(matches: &getopts::Matches) -> OptPartRes<Option<usize>> {
329329
Ok(test_threads)
330330
}
331331

332-
fn get_format(matches: &getopts::Matches, quiet: bool, allow_unstable: bool) -> OptPartRes<OutputFormat> {
332+
fn get_format(
333+
matches: &getopts::Matches,
334+
quiet: bool,
335+
allow_unstable: bool
336+
) -> OptPartRes<OutputFormat> {
333337
let format = match matches.opt_str("format").as_ref().map(|s| &**s) {
334338
None if quiet => OutputFormat::Terse,
335339
Some("pretty") | None => OutputFormat::Pretty,

src/libtest/event.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,12 @@ pub struct CompletedTest {
1414
}
1515

1616
impl CompletedTest {
17-
pub fn new(desc: TestDesc, result: TestResult, exec_time: Option<TestExecTime>, stdout: Vec<u8>) -> Self {
17+
pub fn new(
18+
desc: TestDesc,
19+
result: TestResult,
20+
exec_time: Option<TestExecTime>,
21+
stdout: Vec<u8>
22+
) -> Self {
1823
Self {
1924
desc,
2025
result,

src/libtest/formatters/json.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ impl<T: Write> OutputFormatter for JsonFormatter<T> {
9292
stdout: &[u8],
9393
state: &ConsoleTestState,
9494
) -> io::Result<()> {
95-
let stdout = if (state.options.display_output || *result != TestResult::TrOk) && stdout.len() > 0 {
95+
let display_stdout = state.options.display_output || *result != TestResult::TrOk;
96+
let stdout = if display_stdout && stdout.len() > 0 {
9697
Some(String::from_utf8_lossy(stdout))
9798
} else {
9899
None

src/libtest/formatters/terse.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,9 @@ impl<T: Write> OutputFormatter for TerseFormatter<T> {
196196
) -> io::Result<()> {
197197
match *result {
198198
TestResult::TrOk => self.write_ok(),
199-
TestResult::TrFailed | TestResult::TrFailedMsg(_) | TestResult::TrTimedFail => self.write_failed(),
199+
TestResult::TrFailed
200+
| TestResult::TrFailedMsg(_)
201+
| TestResult::TrTimedFail => self.write_failed(),
200202
TestResult::TrIgnored => self.write_ignored(),
201203
TestResult::TrAllowedFail => self.write_allowed_fail(),
202204
TestResult::TrBench(ref bs) => {

src/libtest/helpers/isatty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,4 @@ pub fn stdout_isatty() -> bool {
3030
let mut out = 0;
3131
GetConsoleMode(handle, &mut out) != 0
3232
}
33-
}
33+
}

src/libtest/lib.rs

+8-4
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ pub mod test {
4646
test_result::{TestResult, TrFailed, TrFailedMsg, TrIgnored, TrOk},
4747
time::{TestTimeOptions, TestExecTime},
4848
types::{
49-
DynTestFn, DynTestName, StaticBenchFn, StaticTestFn, StaticTestName, TestDesc, TestDescAndFn,
50-
TestName, TestType,
49+
DynTestFn, DynTestName, StaticBenchFn, StaticTestFn, StaticTestName,
50+
TestDesc, TestDescAndFn, TestName, TestType,
5151
},
5252
assert_test_result, filter_tests, run_test, test_main, test_main_static,
5353
};
@@ -199,7 +199,11 @@ pub fn assert_test_result<T: Termination>(result: T) {
199199
);
200200
}
201201

202-
pub fn run_tests<F>(opts: &TestOpts, tests: Vec<TestDescAndFn>, mut notify_about_test_event: F) -> io::Result<()>
202+
pub fn run_tests<F>(
203+
opts: &TestOpts,
204+
tests: Vec<TestDescAndFn>,
205+
mut notify_about_test_event: F
206+
) -> io::Result<()>
203207
where
204208
F: FnMut(TestEvent) -> io::Result<()>,
205209
{
@@ -325,7 +329,7 @@ where
325329
_ => {
326330
// We've got a result, stop the loop.
327331
break;
328-
}
332+
}
329333
}
330334
} else {
331335
res = rx.recv().map_err(|_| RecvTimeoutError::Disconnected);

src/libtest/test_result.rs

+6-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
21
use std::any::Any;
32

43
use super::bench::BenchSamples;
@@ -50,11 +49,15 @@ pub fn calc_result<'a>(
5049
if desc.allow_fail {
5150
TestResult::TrAllowedFail
5251
} else {
53-
TestResult::TrFailedMsg(format!("panic did not include expected string '{}'", msg))
52+
TestResult::TrFailedMsg(
53+
format!("panic did not include expected string '{}'", msg)
54+
)
5455
}
5556
}
5657
}
57-
(&ShouldPanic::Yes, Ok(())) => TestResult::TrFailedMsg("test did not panic as expected".to_string()),
58+
(&ShouldPanic::Yes, Ok(())) => {
59+
TestResult::TrFailedMsg("test did not panic as expected".to_string())
60+
}
5861
_ if desc.allow_fail => TestResult::TrAllowedFail,
5962
_ => TestResult::TrFailed,
6063
};

src/libtest/tests.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ use crate::{
77
time::{TimeThreshold, TestTimeOptions},
88
formatters::PrettyFormatter,
99
test::{
10-
filter_tests, parse_opts, run_test, DynTestFn, DynTestName, MetricMap, RunIgnored, RunStrategy,
10+
filter_tests, parse_opts, run_test, DynTestFn, DynTestName, MetricMap,
11+
RunIgnored, RunStrategy, ShouldPanic, StaticTestName, TestDesc,
12+
TestDescAndFn, TestOpts, TrIgnored, TrOk,
13+
// FIXME (introduced by #65251)
1114
// ShouldPanic, StaticTestName, TestDesc, TestDescAndFn, TestOpts, TestTimeOptions,
1215
// TestType, TrFailedMsg, TrIgnored, TrOk,
13-
ShouldPanic, StaticTestName, TestDesc, TestDescAndFn, TestOpts,
14-
TrIgnored, TrOk,
1516
},
1617
};
1718
use std::sync::mpsc::channel;
@@ -104,7 +105,7 @@ pub fn ignored_tests_result_in_ignored() {
104105
assert!(result == TrIgnored);
105106
}
106107

107-
// FIXME: Re-enable emscripten once it can catch panics again
108+
// FIXME: Re-enable emscripten once it can catch panics again (introduced by #65251)
108109
#[test]
109110
#[cfg(not(target_os = "emscripten"))]
110111
fn test_should_panic() {
@@ -127,7 +128,7 @@ fn test_should_panic() {
127128
assert!(result == TrOk);
128129
}
129130

130-
// FIXME: Re-enable emscripten once it can catch panics again
131+
// FIXME: Re-enable emscripten once it can catch panics again (introduced by #65251)
131132
#[test]
132133
#[cfg(not(target_os = "emscripten"))]
133134
fn test_should_panic_good_message() {
@@ -150,7 +151,7 @@ fn test_should_panic_good_message() {
150151
assert!(result == TrOk);
151152
}
152153

153-
// FIXME: Re-enable emscripten once it can catch panics again
154+
// FIXME: Re-enable emscripten once it can catch panics again (introduced by #65251)
154155
#[test]
155156
#[cfg(not(target_os = "emscripten"))]
156157
fn test_should_panic_bad_message() {
@@ -176,7 +177,7 @@ fn test_should_panic_bad_message() {
176177
assert!(result == TrFailedMsg(format!("{} '{}'", failed_msg, expected)));
177178
}
178179

179-
// FIXME: Re-enable emscripten once it can catch panics again
180+
// FIXME: Re-enable emscripten once it can catch panics again (introduced by #65251)
180181
#[test]
181182
#[cfg(not(target_os = "emscripten"))]
182183
fn test_should_panic_but_succeeds() {

src/libtest/time.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//! execution.
33
//! Two main purposes of this module:
44
//! - Check whether test is timed out.
5-
//! - Provide helpers for `report-time` and `measure-time` options.
5+
//! - Provide helpers for `report-time` and `measure-time` options.
66
77
use std::time::{Duration, Instant};
88
use std::str::FromStr;
@@ -55,7 +55,7 @@ pub mod time_constants {
5555
}
5656

5757
/// Returns an `Instance` object denoting when the test should be considered
58-
/// timed out.
58+
/// timed out.
5959
pub fn get_default_test_timeout() -> Instant {
6060
Instant::now() + Duration::from_secs(TEST_WARN_TIMEOUT_S)
6161
}

0 commit comments

Comments
 (0)