Skip to content

Commit 7e6e9c2

Browse files
committed
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.
1 parent 7a9b880 commit 7e6e9c2

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

tests/by-util/test_cp.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5837,7 +5837,7 @@ fn test_dir_perm_race_with_preserve_mode_and_ownership() {
58375837
start_time.elapsed() < timeout,
58385838
"timed out: cp took too long to create destination directory"
58395839
);
5840-
if at.dir_exists(&format!("{DEST_DIR}/{SRC_DIR}")) {
5840+
if at.dir_exists(format!("{DEST_DIR}/{SRC_DIR}")) {
58415841
break;
58425842
}
58435843
sleep(Duration::from_millis(100));

tests/by-util/test_mv.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -228,8 +228,8 @@ fn test_mv_multiple_folders() {
228228
.succeeds()
229229
.no_stderr();
230230

231-
assert!(at.dir_exists(&format!("{target_dir}/{dir_a}")));
232-
assert!(at.dir_exists(&format!("{target_dir}/{dir_b}")));
231+
assert!(at.dir_exists(format!("{target_dir}/{dir_a}")));
232+
assert!(at.dir_exists(format!("{target_dir}/{dir_b}")));
233233
}
234234

235235
#[test]
@@ -555,7 +555,7 @@ fn test_mv_hardlink_to_symlink() {
555555
.arg(hardlink_to_symlink_file)
556556
.succeeds();
557557
assert!(!at2.symlink_exists(symlink_file));
558-
assert!(at2.symlink_exists(&format!("{hardlink_to_symlink_file}~")));
558+
assert!(at2.symlink_exists(format!("{hardlink_to_symlink_file}~")));
559559
}
560560

561561
#[test]
@@ -649,7 +649,7 @@ fn test_mv_simple_backup_for_directory() {
649649

650650
assert!(!at.dir_exists(dir_a));
651651
assert!(at.dir_exists(dir_b));
652-
assert!(at.dir_exists(&format!("{dir_b}~")));
652+
assert!(at.dir_exists(format!("{dir_b}~")));
653653
assert!(at.file_exists(format!("{dir_b}/file_a")));
654654
assert!(at.file_exists(format!("{dir_b}~/file_b")));
655655
}
@@ -1353,7 +1353,7 @@ fn test_mv_backup_dir() {
13531353

13541354
assert!(!at.dir_exists(dir_a));
13551355
assert!(at.dir_exists(dir_b));
1356-
assert!(at.dir_exists(&format!("{dir_b}~")));
1356+
assert!(at.dir_exists(format!("{dir_b}~")));
13571357
}
13581358

13591359
#[test]
@@ -1572,7 +1572,7 @@ fn test_mv_dir_into_dir_with_source_name_a_prefix_of_target_name() {
15721572

15731573
ucmd.arg(source).arg(target).succeeds().no_output();
15741574

1575-
assert!(at.dir_exists(&format!("{target}/{source}")));
1575+
assert!(at.dir_exists(format!("{target}/{source}")));
15761576
}
15771577

15781578
#[test]

tests/uutests/src/lib/util.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1243,14 +1243,14 @@ impl AtPath {
12431243
}
12441244

12451245
/// Decide whether the named symbolic link exists in the test directory.
1246-
pub fn symlink_exists(&self, path: &str) -> bool {
1246+
pub fn symlink_exists<P: AsRef<Path>>(&self, path: P) -> bool {
12471247
match fs::symlink_metadata(self.plus(path)) {
12481248
Ok(m) => m.file_type().is_symlink(),
12491249
Err(_) => false,
12501250
}
12511251
}
12521252

1253-
pub fn dir_exists(&self, path: &str) -> bool {
1253+
pub fn dir_exists<P: AsRef<Path>>(&self, path: P) -> bool {
12541254
match fs::metadata(self.plus(path)) {
12551255
Ok(m) => m.is_dir(),
12561256
Err(_) => false,

0 commit comments

Comments
 (0)