Skip to content

Commit

Permalink
style: Use inline format args
Browse files Browse the repository at this point in the history
  • Loading branch information
epage committed Sep 27, 2024
1 parent 028f0f6 commit f89452f
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 23 deletions.
6 changes: 3 additions & 3 deletions examples/example_fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use std::process;

fn run() -> Result<(), Box<dyn Error>> {
if let Ok(text) = env::var("stdout") {
println!("{}", text);
println!("{text}");
}
if let Ok(text) = env::var("stderr") {
eprintln!("{}", text);
eprintln!("{text}");
}

let code = env::var("exit")
Expand All @@ -27,7 +27,7 @@ fn main() {
let code = match run() {
Ok(_) => 0,
Err(ref e) => {
write!(&mut io::stderr(), "{}", e).expect("writing to stderr won't fail");
write!(&mut io::stderr(), "{e}").expect("writing to stderr won't fail");
1
}
};
Expand Down
8 changes: 4 additions & 4 deletions src/assert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ impl<'c> OutputAssertExt for &'c mut process::Command {
panic!("Failed to spawn {:?}: {}", self, err);
}
};
Assert::new(output).append_context("command", format!("{:?}", self))
Assert::new(output).append_context("command", format!("{self:?}"))
}
}

Expand Down Expand Up @@ -1084,13 +1084,13 @@ impl fmt::Display for AssertError {
writeln!(f, "Command interrupted")
}
AssertReason::UnexpectedReturnCode { case_tree } => {
writeln!(f, "Unexpected return code, failed {}", case_tree)
writeln!(f, "Unexpected return code, failed {case_tree}")
}
AssertReason::UnexpectedStdout { case_tree } => {
writeln!(f, "Unexpected stdout, failed {}", case_tree)
writeln!(f, "Unexpected stdout, failed {case_tree}")
}
AssertReason::UnexpectedStderr { case_tree } => {
writeln!(f, "Unexpected stderr, failed {}", case_tree)
writeln!(f, "Unexpected stderr, failed {case_tree}")
}
}?;
write!(f, "{}", self.assert)
Expand Down
6 changes: 3 additions & 3 deletions src/bin/bin_fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use std::process;

fn run() -> Result<(), Box<dyn Error>> {
if let Ok(text) = env::var("stdout") {
println!("{}", text);
println!("{text}");
}
if let Ok(text) = env::var("stderr") {
eprintln!("{}", text);
eprintln!("{text}");
}

if let Some(timeout) = env::var("sleep").ok().and_then(|s| s.parse().ok()) {
Expand All @@ -31,7 +31,7 @@ fn main() {
let code = match run() {
Ok(_) => 0,
Err(ref e) => {
write!(&mut io::stderr(), "{}", e).expect("writing to stderr won't fail");
write!(&mut io::stderr(), "{e}").expect("writing to stderr won't fail");
1
}
};
Expand Down
4 changes: 2 additions & 2 deletions src/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ impl Error for CargoError {}
impl fmt::Display for CargoError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
if let Some(ref cause) = self.cause {
writeln!(f, "Cause: {}", cause)?;
writeln!(f, "Cause: {cause}")?;
}
Ok(())
}
Expand Down Expand Up @@ -222,7 +222,7 @@ pub fn cargo_bin<S: AsRef<str>>(name: S) -> path::PathBuf {
}

fn cargo_bin_str(name: &str) -> path::PathBuf {
let env_var = format!("CARGO_BIN_EXE_{}", name);
let env_var = format!("CARGO_BIN_EXE_{name}");
env::var_os(env_var)
.map(|p| p.into())
.unwrap_or_else(|| target_dir().join(format!("{}{}", name, env::consts::EXE_SUFFIX)))
Expand Down
2 changes: 1 addition & 1 deletion src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -648,7 +648,7 @@ impl<'c> OutputAssertExt for &'c mut Command {
let output = match self.output() {
Ok(output) => output,
Err(err) => {
panic!("Failed to spawn {:?}: {}", self, err);
panic!("Failed to spawn {self:?}: {err}");
}
};
let assert = Assert::new(output).append_context("command", format!("{:?}", self.cmd));
Expand Down
12 changes: 6 additions & 6 deletions src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ impl<'c> OutputOkExt for &'c mut process::Command {
if output.status.success() {
Ok(output)
} else {
let error = OutputError::new(output).set_cmd(format!("{:?}", self));
let error = OutputError::new(output).set_cmd(format!("{self:?}"));
Err(error)
}
}
Expand Down Expand Up @@ -266,8 +266,8 @@ enum OutputCause {
impl fmt::Display for OutputCause {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match *self {
OutputCause::Expected(ref e) => write!(f, "{:#}", e),
OutputCause::Unexpected(ref e) => write!(f, "{:#}", e),
OutputCause::Expected(ref e) => write!(f, "{e:#}"),
OutputCause::Unexpected(ref e) => write!(f, "{e:#}"),
}
}
}
Expand Down Expand Up @@ -369,9 +369,9 @@ fn format_bytes(data: &[u8], f: &mut impl fmt::Write) -> fmt::Result {
.as_bstr()
.lines_with_terminator()
.skip(LINES_MAX_START + lines_omitted);
writeln!(f, "<{} lines total>", lines_total)?;
writeln!(f, "<{lines_total} lines total>")?;
write_debug_bstrs(f, true, start_lines)?;
writeln!(f, "<{} lines omitted>", lines_omitted)?;
writeln!(f, "<{lines_omitted} lines omitted>")?;
write_debug_bstrs(f, true, end_lines)
} else if BYTES_MIN_OVERFLOW <= data.len() {
write!(
Expand Down Expand Up @@ -434,7 +434,7 @@ mod test {
fn format_bytes() {
let mut s = String::new();
for i in 0..80 {
s.push_str(&format!("{}\n", i));
s.push_str(&format!("{i}\n"));
}

let mut buf = String::new();
Expand Down
8 changes: 4 additions & 4 deletions tests/cargo.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ fn mod_example() {
.unwrap();
let mut cmd = bin_under_test.command();
let output = cmd.unwrap();
println!("{:?}", output);
println!("{output:?}");
}
}

Expand All @@ -43,20 +43,20 @@ fn mod_example() {
fn trait_example() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
let output = cmd.unwrap();
println!("{:?}", output);
println!("{output:?}");
}

#[test]
#[should_panic] // No bin named `assert_cmd
fn cargo_bin_example_1() {
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
let output = cmd.unwrap();
println!("{:?}", output);
println!("{output:?}");
}

#[test]
fn cargo_bin_example_2() {
let mut cmd = Command::cargo_bin("bin_fixture").unwrap();
let output = cmd.unwrap();
println!("{:?}", output);
println!("{output:?}");
}

0 comments on commit f89452f

Please sign in to comment.