Rollup merge of #105889 - Nilstrieb:fmt-libtest, r=thomcc

Fix `uninlined_format_args` in libtest

Done using clippy with a quick manual review.
This commit is contained in:
Dylan DPC 2022-12-19 14:41:37 +05:30 committed by GitHub
commit 2a57493fa1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 15 additions and 24 deletions

View file

@ -354,8 +354,7 @@ fn get_shuffle_seed(matches: &getopts::Matches, allow_unstable: bool) -> OptPart
Err(e) => { Err(e) => {
return Err(format!( return Err(format!(
"argument for --shuffle-seed must be a number \ "argument for --shuffle-seed must be a number \
(error: {})", (error: {e})"
e
)); ));
} }
}, },
@ -383,8 +382,7 @@ fn get_test_threads(matches: &getopts::Matches) -> OptPartRes<Option<usize>> {
Err(e) => { Err(e) => {
return Err(format!( return Err(format!(
"argument for --test-threads must be a number > 0 \ "argument for --test-threads must be a number > 0 \
(error: {})", (error: {e})"
e
)); ));
} }
}, },
@ -418,8 +416,7 @@ fn get_format(
Some(v) => { Some(v) => {
return Err(format!( return Err(format!(
"argument for --format must be pretty, terse, json or junit (was \ "argument for --format must be pretty, terse, json or junit (was \
{})", {v})"
v
)); ));
} }
}; };
@ -436,8 +433,7 @@ fn get_color_config(matches: &getopts::Matches) -> OptPartRes<ColorConfig> {
Some(v) => { Some(v) => {
return Err(format!( return Err(format!(
"argument for --color must be auto, always, or never (was \ "argument for --color must be auto, always, or never (was \
{})", {v})"
v
)); ));
} }
}; };

View file

@ -53,7 +53,7 @@ fn write_event(
self.write_message(&*format!(r#", "stdout": "{}""#, EscapedString(stdout)))?; self.write_message(&*format!(r#", "stdout": "{}""#, EscapedString(stdout)))?;
} }
if let Some(extra) = extra { if let Some(extra) = extra {
self.write_message(&*format!(r#", {}"#, extra))?; self.write_message(&*format!(r#", {extra}"#))?;
} }
self.writeln_message(" }") self.writeln_message(" }")
} }
@ -62,13 +62,12 @@ fn write_event(
impl<T: Write> OutputFormatter for JsonFormatter<T> { impl<T: Write> OutputFormatter for JsonFormatter<T> {
fn write_run_start(&mut self, test_count: usize, shuffle_seed: Option<u64>) -> io::Result<()> { fn write_run_start(&mut self, test_count: usize, shuffle_seed: Option<u64>) -> io::Result<()> {
let shuffle_seed_json = if let Some(shuffle_seed) = shuffle_seed { let shuffle_seed_json = if let Some(shuffle_seed) = shuffle_seed {
format!(r#", "shuffle_seed": {}"#, shuffle_seed) format!(r#", "shuffle_seed": {shuffle_seed}"#)
} else { } else {
String::new() String::new()
}; };
self.writeln_message(&*format!( self.writeln_message(&*format!(
r#"{{ "type": "suite", "event": "started", "test_count": {}{} }}"#, r#"{{ "type": "suite", "event": "started", "test_count": {test_count}{shuffle_seed_json} }}"#
test_count, shuffle_seed_json
)) ))
} }

View file

@ -38,5 +38,5 @@ pub(crate) fn write_stderr_delimiter(test_output: &mut Vec<u8>, test_name: &Test
Some(_) => test_output.push(b'\n'), Some(_) => test_output.push(b'\n'),
None => (), None => (),
} }
writeln!(test_output, "---- {} stderr ----", test_name).unwrap(); writeln!(test_output, "---- {test_name} stderr ----").unwrap();
} }

View file

@ -47,7 +47,7 @@ pub fn write_failed(&mut self) -> io::Result<()> {
pub fn write_ignored(&mut self, message: Option<&'static str>) -> io::Result<()> { pub fn write_ignored(&mut self, message: Option<&'static str>) -> io::Result<()> {
if let Some(message) = message { if let Some(message) = message {
self.write_short_result(&format!("ignored, {}", message), term::color::YELLOW) self.write_short_result(&format!("ignored, {message}"), term::color::YELLOW)
} else { } else {
self.write_short_result("ignored", term::color::YELLOW) self.write_short_result("ignored", term::color::YELLOW)
} }

View file

@ -213,8 +213,7 @@ pub fn assert_test_result<T: Termination>(result: T) -> Result<(), String> {
} else { } else {
Err(format!( Err(format!(
"the test returned a termination value with a non-zero status code \ "the test returned a termination value with a non-zero status code \
({}) which indicates a failure", ({code}) which indicates a failure"
code
)) ))
} }
} }
@ -750,7 +749,7 @@ fn spawn_test_subprocess(
})() { })() {
Ok(r) => r, Ok(r) => r,
Err(e) => { Err(e) => {
write!(&mut test_output, "Unexpected error: {}", e).unwrap(); write!(&mut test_output, "Unexpected error: {e}").unwrap();
TrFailed TrFailed
} }
}; };

View file

@ -44,9 +44,8 @@ pub fn calc_result<'a>(
} else if let Some(panic_str) = maybe_panic_str { } else if let Some(panic_str) = maybe_panic_str {
TestResult::TrFailedMsg(format!( TestResult::TrFailedMsg(format!(
r#"panic did not contain expected string r#"panic did not contain expected string
panic message: `{:?}`, panic message: `{panic_str:?}`,
expected substring: `{:?}`"#, expected substring: `{msg:?}`"#
panic_str, msg
)) ))
} else { } else {
TestResult::TrFailedMsg(format!( TestResult::TrFailedMsg(format!(

View file

@ -107,16 +107,14 @@ pub fn from_env_var(env_var_name: &str) -> Option<Self> {
let durations_str = env::var(env_var_name).ok()?; let durations_str = env::var(env_var_name).ok()?;
let (warn_str, critical_str) = durations_str.split_once(',').unwrap_or_else(|| { let (warn_str, critical_str) = durations_str.split_once(',').unwrap_or_else(|| {
panic!( panic!(
"Duration variable {} expected to have 2 numbers separated by comma, but got {}", "Duration variable {env_var_name} expected to have 2 numbers separated by comma, but got {durations_str}"
env_var_name, durations_str
) )
}); });
let parse_u64 = |v| { let parse_u64 = |v| {
u64::from_str(v).unwrap_or_else(|_| { u64::from_str(v).unwrap_or_else(|_| {
panic!( panic!(
"Duration value in variable {} is expected to be a number, but got {}", "Duration value in variable {env_var_name} is expected to be a number, but got {v}"
env_var_name, v
) )
}) })
}; };