Skip to content

Commit 32a354e

Browse files
committed
Test error case of std::fs::rename
1 parent 056a68d commit 32a354e

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

tests/run-pass/fs.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,8 +169,16 @@ fn test_rename() {
169169

170170
let file = File::create(&path1).unwrap();
171171
drop(file);
172+
173+
// Renaming should succeed
172174
rename(&path1, &path2).unwrap();
175+
// Check that the old file path isn't present
173176
assert_eq!(ErrorKind::NotFound, path1.metadata().unwrap_err().kind());
177+
// Check that the file has moved successfully
174178
assert!(path2.metadata().unwrap().is_file());
179+
180+
// Renaming a nonexistent file should fail
181+
assert_eq!(ErrorKind::NotFound, rename(&path1, &path2).unwrap_err().kind());
182+
175183
remove_file(&path2).unwrap();
176184
}

0 commit comments

Comments
 (0)