]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #1184 - divergentdave:rename-error-test, r=RalfJung
authorbors <bors@rust-lang.org>
Fri, 21 Feb 2020 07:36:14 +0000 (07:36 +0000)
committerbors <bors@rust-lang.org>
Fri, 21 Feb 2020 07:36:14 +0000 (07:36 +0000)
Test error case of std::fs::rename

As suggested [here](https://github.com/rust-lang/miri/pull/1158#issuecomment-586459463) this PR adds an additional test case for calling rename on a file path that doesn't exist.

tests/run-pass/fs.rs

index 453432f64f10570e260bd504b4bd3d09bd5962df..a6ce8627cde7c24003b3d0f62e935b90f7e43f6a 100644 (file)
@@ -169,8 +169,16 @@ fn test_rename() {
 
     let file = File::create(&path1).unwrap();
     drop(file);
+
+    // Renaming should succeed
     rename(&path1, &path2).unwrap();
+    // Check that the old file path isn't present
     assert_eq!(ErrorKind::NotFound, path1.metadata().unwrap_err().kind());
+    // Check that the file has moved successfully
     assert!(path2.metadata().unwrap().is_file());
+
+    // Renaming a nonexistent file should fail
+    assert_eq!(ErrorKind::NotFound, rename(&path1, &path2).unwrap_err().kind());
+
     remove_file(&path2).unwrap();
 }