uutests: Change dir_exists to take a templated AsRef<Path>

Similar to what file_exists does, allows us to pass an OsStr to the
function.

Also change symlink_exists, for consistency.
This commit is contained in:
Nicolas Boichat
2025-07-22 17:25:59 +08:00
parent 7a9b88011c
commit 7e6e9c291e
3 changed files with 9 additions and 9 deletions
+1 -1
View File
@@ -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));
+6 -6
View File
@@ -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]
+2 -2
View File
@@ -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<P: AsRef<Path>>(&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<P: AsRef<Path>>(&self, path: P) -> bool {
match fs::metadata(self.plus(path)) {
Ok(m) => m.is_dir(),
Err(_) => false,