Skip to content

Commit

Permalink
clippy: it is more idiomatic to use 'Option<&T>' instead of '&Option<T>'
Browse files Browse the repository at this point in the history
  • Loading branch information
sylvestre committed Nov 28, 2024
1 parent 7993b0f commit 480456d
Showing 1 changed file with 9 additions and 8 deletions.
17 changes: 9 additions & 8 deletions tests/common/util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ pub fn is_ci() -> bool {
}

/// Read a test scenario fixture, returning its bytes
fn read_scenario_fixture<S: AsRef<OsStr>>(tmpd: &Option<Rc<TempDir>>, file_rel_path: S) -> Vec<u8> {
fn read_scenario_fixture<S: AsRef<OsStr>>(tmpd: Option<&Rc<TempDir>>, file_rel_path: S) -> Vec<u8> {
let tmpdir_path = tmpd.as_ref().unwrap().as_ref().path();
AtPath::new(tmpdir_path).read_bytes(file_rel_path.as_ref().to_str().unwrap())
}
Expand Down Expand Up @@ -517,7 +517,7 @@ impl CmdResult {
/// like `stdout_is()`, but expects the contents of the file at the provided relative path
#[track_caller]
pub fn stdout_is_fixture<T: AsRef<OsStr>>(&self, file_rel_path: T) -> &Self {
let contents = read_scenario_fixture(&self.tmpd, file_rel_path);
let contents = read_scenario_fixture(self.tmpd.as_ref(), file_rel_path);
self.stdout_is(String::from_utf8(contents).unwrap())
}

Expand All @@ -539,7 +539,7 @@ impl CmdResult {
/// ```
#[track_caller]
pub fn stdout_is_fixture_bytes<T: AsRef<OsStr>>(&self, file_rel_path: T) -> &Self {
let contents = read_scenario_fixture(&self.tmpd, file_rel_path);
let contents = read_scenario_fixture(self.tmpd.as_ref(), file_rel_path);
self.stdout_is_bytes(contents)
}

Expand All @@ -552,7 +552,7 @@ impl CmdResult {
template_vars: &[(&str, &str)],
) -> &Self {
let mut contents =
String::from_utf8(read_scenario_fixture(&self.tmpd, file_rel_path)).unwrap();
String::from_utf8(read_scenario_fixture(self.tmpd.as_ref(), file_rel_path)).unwrap();
for kv in template_vars {
contents = contents.replace(kv.0, kv.1);
}
Expand All @@ -566,7 +566,8 @@ impl CmdResult {
file_rel_path: T,
template_vars: &[Vec<(String, String)>],
) {
let contents = String::from_utf8(read_scenario_fixture(&self.tmpd, file_rel_path)).unwrap();
let contents =
String::from_utf8(read_scenario_fixture(self.tmpd.as_ref(), file_rel_path)).unwrap();
let possible_values = template_vars.iter().map(|vars| {
let mut contents = contents.clone();
for kv in vars {
Expand Down Expand Up @@ -604,7 +605,7 @@ impl CmdResult {
/// Like `stdout_is_fixture`, but for stderr
#[track_caller]
pub fn stderr_is_fixture<T: AsRef<OsStr>>(&self, file_rel_path: T) -> &Self {
let contents = read_scenario_fixture(&self.tmpd, file_rel_path);
let contents = read_scenario_fixture(self.tmpd.as_ref(), file_rel_path);
self.stderr_is(String::from_utf8(contents).unwrap())
}

Expand All @@ -629,7 +630,7 @@ impl CmdResult {
/// like `stdout_only()`, but expects the contents of the file at the provided relative path
#[track_caller]
pub fn stdout_only_fixture<T: AsRef<OsStr>>(&self, file_rel_path: T) -> &Self {
let contents = read_scenario_fixture(&self.tmpd, file_rel_path);
let contents = read_scenario_fixture(self.tmpd.as_ref(), file_rel_path);
self.stdout_only_bytes(contents)
}

Expand Down Expand Up @@ -1384,7 +1385,7 @@ impl UCommand {

/// like `pipe_in()`, but uses the contents of the file at the provided relative path as the piped in data
pub fn pipe_in_fixture<S: AsRef<OsStr>>(&mut self, file_rel_path: S) -> &mut Self {
let contents = read_scenario_fixture(&self.tmpd, file_rel_path);
let contents = read_scenario_fixture(self.tmpd.as_ref(), file_rel_path);
self.pipe_in(contents)
}

Expand Down

0 comments on commit 480456d

Please sign in to comment.