From 7e6e9c291e630f0fb4a08ba0d70048c158888a3d Mon Sep 17 00:00:00 2001 From: Nicolas Boichat Date: Tue, 22 Jul 2025 17:19:45 +0800 Subject: [PATCH] uutests: Change dir_exists to take a templated AsRef Similar to what file_exists does, allows us to pass an OsStr to the function. Also change symlink_exists, for consistency. --- tests/by-util/test_cp.rs | 2 +- tests/by-util/test_mv.rs | 12 ++++++------ tests/uutests/src/lib/util.rs | 4 ++-- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/tests/by-util/test_cp.rs b/tests/by-util/test_cp.rs index 7a3b28d23..8575d1959 100644 --- a/tests/by-util/test_cp.rs +++ b/tests/by-util/test_cp.rs @@ -5837,7 +5837,7 @@ fn test_dir_perm_race_with_preserve_mode_and_ownership() { start_time.elapsed() < timeout, "timed out: cp took too long to create destination directory" ); - if at.dir_exists(&format!("{DEST_DIR}/{SRC_DIR}")) { + if at.dir_exists(format!("{DEST_DIR}/{SRC_DIR}")) { break; } sleep(Duration::from_millis(100)); diff --git a/tests/by-util/test_mv.rs b/tests/by-util/test_mv.rs index 7b984cfde..62c12c1d2 100644 --- a/tests/by-util/test_mv.rs +++ b/tests/by-util/test_mv.rs @@ -228,8 +228,8 @@ fn test_mv_multiple_folders() { .succeeds() .no_stderr(); - assert!(at.dir_exists(&format!("{target_dir}/{dir_a}"))); - assert!(at.dir_exists(&format!("{target_dir}/{dir_b}"))); + assert!(at.dir_exists(format!("{target_dir}/{dir_a}"))); + assert!(at.dir_exists(format!("{target_dir}/{dir_b}"))); } #[test] @@ -555,7 +555,7 @@ fn test_mv_hardlink_to_symlink() { .arg(hardlink_to_symlink_file) .succeeds(); assert!(!at2.symlink_exists(symlink_file)); - assert!(at2.symlink_exists(&format!("{hardlink_to_symlink_file}~"))); + assert!(at2.symlink_exists(format!("{hardlink_to_symlink_file}~"))); } #[test] @@ -649,7 +649,7 @@ fn test_mv_simple_backup_for_directory() { assert!(!at.dir_exists(dir_a)); assert!(at.dir_exists(dir_b)); - assert!(at.dir_exists(&format!("{dir_b}~"))); + assert!(at.dir_exists(format!("{dir_b}~"))); assert!(at.file_exists(format!("{dir_b}/file_a"))); assert!(at.file_exists(format!("{dir_b}~/file_b"))); } @@ -1353,7 +1353,7 @@ fn test_mv_backup_dir() { assert!(!at.dir_exists(dir_a)); assert!(at.dir_exists(dir_b)); - assert!(at.dir_exists(&format!("{dir_b}~"))); + assert!(at.dir_exists(format!("{dir_b}~"))); } #[test] @@ -1572,7 +1572,7 @@ fn test_mv_dir_into_dir_with_source_name_a_prefix_of_target_name() { ucmd.arg(source).arg(target).succeeds().no_output(); - assert!(at.dir_exists(&format!("{target}/{source}"))); + assert!(at.dir_exists(format!("{target}/{source}"))); } #[test] diff --git a/tests/uutests/src/lib/util.rs b/tests/uutests/src/lib/util.rs index 3fa3ed477..154a7aa18 100644 --- a/tests/uutests/src/lib/util.rs +++ b/tests/uutests/src/lib/util.rs @@ -1243,14 +1243,14 @@ impl AtPath { } /// Decide whether the named symbolic link exists in the test directory. - pub fn symlink_exists(&self, path: &str) -> bool { + pub fn symlink_exists>(&self, path: P) -> bool { match fs::symlink_metadata(self.plus(path)) { Ok(m) => m.file_type().is_symlink(), Err(_) => false, } } - pub fn dir_exists(&self, path: &str) -> bool { + pub fn dir_exists>(&self, path: P) -> bool { match fs::metadata(self.plus(path)) { Ok(m) => m.is_dir(), Err(_) => false,