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

chore: Update from _rust template #366

Merged
merged 9 commits into from
Sep 27, 2024
2 changes: 2 additions & 0 deletions .github/workflows/pre-commit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ jobs:
steps:
- uses: actions/checkout@v4
- uses: actions/setup-python@v5
with:
python-version: '3.x'
- uses: pre-commit/[email protected]
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ We ask that commits are atomic, meaning they are complete and have a single resp
PRs should tell a cohesive story, with test and refactor commits that keep the
fix or feature commits simple and clear.

Specifically, we would encouage
Specifically, we would encourage
- File renames be isolated into their own commit
- Add tests in a commit before their feature or fix, showing the current behavior.
The diff for the feature/fix commit will then show how the behavior changed,
Expand Down
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ string_lit_as_bytes = "warn"
string_to_string = "warn"
todo = "warn"
trait_duplication_in_bounds = "warn"
uninlined_format_args = "warn"
verbose_file_reads = "warn"
wildcard_imports = "warn"
zero_sized_map_values = "warn"
2 changes: 1 addition & 1 deletion crates/snapbox/src/assert/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ impl std::fmt::Display for Error {
if let Some(backtrace) = self.backtrace.as_ref() {
writeln!(f)?;
writeln!(f, "Backtrace:")?;
writeln!(f, "{}", backtrace)?;
writeln!(f, "{backtrace}")?;
}
Ok(())
}
Expand Down
6 changes: 3 additions & 3 deletions crates/snapbox/src/assert/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ impl Assert {
crate::report::Styled::new(String::new(), Default::default())
} else if let Some(action_var) = self.action_var.as_deref() {
self.palette
.hint(format!("Update with {}=overwrite", action_var))
.hint(format!("Update with {action_var}=overwrite"))
} else {
crate::report::Styled::new(String::new(), Default::default())
};
Expand Down Expand Up @@ -338,7 +338,7 @@ impl Assert {
}
if ok {
use std::io::Write;
let _ = write!(stderr(), "{}", buffer);
let _ = write!(stderr(), "{buffer}");
match self.action {
Action::Skip => unreachable!("Bailed out earlier"),
Action::Ignore => {
Expand All @@ -365,7 +365,7 @@ impl Assert {
&mut buffer,
"{}",
self.palette
.hint(format_args!("Update with {}=overwrite", action_var))
.hint(format_args!("Update with {action_var}=overwrite"))
)
.unwrap();
}
Expand Down
10 changes: 5 additions & 5 deletions crates/snapbox/src/bin/snap-fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ 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 env::var("echo_large").as_deref() == Ok("1") {
for i in 0..(128 * 1024) {
println!("{}", i);
println!("{i}");
}
}

Expand All @@ -33,7 +33,7 @@ fn run() -> Result<(), Box<dyn Error>> {

if let Ok(path) = env::var("cat") {
let text = std::fs::read_to_string(path).unwrap();
eprintln!("{}", text);
eprintln!("{text}");
}

if let Some(timeout) = env::var("sleep").ok().and_then(|s| s.parse().ok()) {
Expand All @@ -53,7 +53,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
13 changes: 6 additions & 7 deletions crates/snapbox/src/cmd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ impl OutputAssert {

use std::fmt::Write;
let mut buf = String::new();
writeln!(&mut buf, "{}", desc).unwrap();
writeln!(&mut buf, "{desc}").unwrap();
self.write_stdout(&mut buf).unwrap();
self.write_stderr(&mut buf).unwrap();
panic!("{}", buf);
Expand Down Expand Up @@ -526,7 +526,7 @@ impl OutputAssert {

use std::fmt::Write;
let mut buf = String::new();
writeln!(&mut buf, "{}", desc).unwrap();
writeln!(&mut buf, "{desc}").unwrap();
self.write_stdout(&mut buf).unwrap();
self.write_stderr(&mut buf).unwrap();
panic!("{}", buf);
Expand All @@ -548,7 +548,7 @@ impl OutputAssert {

use std::fmt::Write;
let mut buf = String::new();
writeln!(&mut buf, "{}", desc).unwrap();
writeln!(&mut buf, "{desc}").unwrap();
self.write_stdout(&mut buf).unwrap();
self.write_stderr(&mut buf).unwrap();
panic!("{}", buf);
Expand Down Expand Up @@ -580,7 +580,7 @@ impl OutputAssert {

use std::fmt::Write;
let mut buf = String::new();
writeln!(&mut buf, "{}", desc).unwrap();
writeln!(&mut buf, "{desc}").unwrap();
self.write_stdout(&mut buf).unwrap();
self.write_stderr(&mut buf).unwrap();
panic!("{}", buf);
Expand Down Expand Up @@ -761,7 +761,7 @@ pub fn display_exit_status(status: std::process::ExitStatus) -> String {
libc::SIGTRAP => ", SIGTRAP: trace/breakpoint trap",
_ => "",
};
Some(format!("signal: {}{}", signal, name))
Some(format!("signal: {signal}{name}"))
}

#[cfg(windows)]
Expand Down Expand Up @@ -914,8 +914,7 @@ pub(crate) mod examples {
}

Err(crate::assert::Error::new(format!(
"Unknown error building example {}",
target_name
"Unknown error building example {target_name}"
)))
}

Expand Down
2 changes: 1 addition & 1 deletion crates/snapbox/src/data/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ pub trait ToDebug {

impl<D: std::fmt::Debug> ToDebug for D {
fn to_debug(&self) -> Data {
Data::text(format!("{:#?}\n", self))
Data::text(format!("{self:#?}\n"))
}
}

Expand Down
2 changes: 1 addition & 1 deletion crates/snapbox/src/filter/pattern.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,7 @@ mod test {
];
for (line, pattern, expected) in cases {
let actual = line_matches(line, pattern, &Redactions::new());
assert_eq!(expected, actual, "line={:?} pattern={:?}", line, pattern);
assert_eq!(expected, actual, "line={line:?} pattern={pattern:?}");
}
}
}
6 changes: 3 additions & 3 deletions crates/snapbox/src/filter/redactions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -327,14 +327,14 @@ fn replace_many<'a>(

fn validate_placeholder(placeholder: &'static str) -> crate::assert::Result<&'static str> {
if !placeholder.starts_with('[') || !placeholder.ends_with(']') {
return Err(format!("Key `{}` is not enclosed in []", placeholder).into());
return Err(format!("Key `{placeholder}` is not enclosed in []").into());
}

if placeholder[1..(placeholder.len() - 1)]
.find(|c: char| !c.is_ascii_uppercase() && c != '_')
.is_some()
{
return Err(format!("Key `{}` can only be A-Z but ", placeholder).into());
return Err(format!("Key `{placeholder}` can only be A-Z but ").into());
}

Ok(placeholder)
Expand All @@ -356,7 +356,7 @@ mod test {
];
for (placeholder, expected) in cases {
let actual = validate_placeholder(placeholder).is_ok();
assert_eq!(expected, actual, "placeholder={:?}", placeholder);
assert_eq!(expected, actual, "placeholder={placeholder:?}");
}
}
}
10 changes: 5 additions & 5 deletions crates/trycmd/src/bin/bin-fixture.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ 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 env::var("echo_large").as_deref() == Ok("1") {
for i in 0..(128 * 1024) {
println!("{}", i);
println!("{i}");
}
}

Expand All @@ -31,7 +31,7 @@ fn run() -> Result<(), Box<dyn Error>> {

if let Ok(path) = env::var("cat") {
let text = std::fs::read_to_string(path).unwrap();
eprintln!("{}", text);
eprintln!("{text}");
}

if let Some(timeout) = env::var("sleep").ok().and_then(|s| s.parse().ok()) {
Expand All @@ -55,7 +55,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
6 changes: 3 additions & 3 deletions crates/trycmd/src/runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ impl Case {
Err(e) => {
let output = Output::step(self.path.clone(), "setup".into());
return vec![Err(
output.error(format!("Failed to initialize sandbox: {}", e).into())
output.error(format!("Failed to initialize sandbox: {e}").into())
)];
}
};
Expand Down Expand Up @@ -283,7 +283,7 @@ impl Case {
if let Err(err) = fs_context.close() {
ok = false;
output.fs.context.push(FileStatus::Failure(
format!("Failed to cleanup sandbox: {}", err).into(),
format!("Failed to cleanup sandbox: {err}").into(),
));
}

Expand Down Expand Up @@ -758,7 +758,7 @@ impl std::fmt::Display for Stream {
f,
"{} {}:",
self.stream,
palette.error(format_args!("({})", msg))
palette.error(format_args!("({msg})"))
)?;
writeln!(f, "{}", palette.info(&self.content))?;
}
Expand Down
12 changes: 5 additions & 7 deletions crates/trycmd/src/schema.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ impl TryCmd {
}
} else if ext == std::ffi::OsStr::new("trycmd") || ext == std::ffi::OsStr::new("md") {
if stderr.is_some() && stderr != Some(&crate::Data::new()) {
panic!("stderr should have been merged: {:?}", stderr);
panic!("stderr should have been merged: {stderr:?}");
}
if let (Some(id), Some(stdout)) = (id, stdout) {
let step = self
Expand Down Expand Up @@ -245,9 +245,7 @@ impl TryCmd {
cmd_start = line_num;
stdout_start = line_num + 1;
} else {
return Err(
format!("Expected `$` on line {}, got `{}`", line_num, line).into()
);
return Err(format!("Expected `$` on line {line_num}, got `{line}`").into());
}
} else {
break 'outer;
Expand Down Expand Up @@ -296,7 +294,7 @@ impl TryCmd {

let bin = loop {
if cmdline.is_empty() {
return Err(format!("No bin specified on line {}", cmd_start).into());
return Err(format!("No bin specified on line {cmd_start}").into());
}
let next = cmdline.remove(0);
if let Some((key, value)) = next.split_once('=') {
Expand Down Expand Up @@ -593,7 +591,7 @@ impl Step {
) -> Result<snapbox::cmd::Command, crate::Error> {
let bin = match &self.bin {
Some(Bin::Path(path)) => Ok(path.clone()),
Some(Bin::Name(name)) => Err(format!("Unknown bin.name = {}", name).into()),
Some(Bin::Name(name)) => Err(format!("Unknown bin.name = {name}").into()),
Some(Bin::Ignore) => Err("Internal error: tried to run an ignored bin".into()),
Some(Bin::Error(err)) => Err(err.clone()),
None => Err("No bin specified".into()),
Expand Down Expand Up @@ -895,7 +893,7 @@ impl std::str::FromStr for CommandStatus {
_ => s
.parse::<i32>()
.map(Self::Code)
.map_err(|_| crate::Error::new(format!("Expected an exit code, got {}", s))),
.map_err(|_| crate::Error::new(format!("Expected an exit code, got {s}"))),
}
}
}
Expand Down
Loading