even simpler test case

This commit is contained in:
Pat Hickey
2021-02-02 13:40:35 -08:00
parent 330902f44e
commit a06b23a308

View File

@@ -336,18 +336,24 @@ mod test {
} }
#[test] #[test]
fn rename_dir_to_existing_file() { fn std_rename_dir_to_existing_file() {
use std::path::Path; let tempdir = tempfile::Builder::new()
fn cleanup(p: &Path) { .prefix("cap-std-sync")
if p.exists() { .tempdir()
if p.is_dir() { .expect("create temporary dir");
std::fs::remove_dir_all(p).expect("delete dir"); let target_path = tempdir.path().join("target");
} else { let source_path = tempdir.path().join("source");
std::fs::remove_file(p).expect("delete file");
}
}
}
let file = std::fs::File::create(&target_path).expect("create target file");
drop(file);
std::fs::create_dir(&source_path).expect("create source dir");
std::fs::rename(&source_path, &target_path)
.expect_err("it should be impossible to rename a directory to an existing file");
}
#[test]
fn rename_dir_to_existing_file() {
let tempdir = tempfile::Builder::new() let tempdir = tempfile::Builder::new()
.prefix("cap-std-sync") .prefix("cap-std-sync")
.tempdir() .tempdir()
@@ -355,22 +361,9 @@ mod test {
let preopen_dir = unsafe { cap_std::fs::Dir::open_ambient_dir(tempdir.path()) } let preopen_dir = unsafe { cap_std::fs::Dir::open_ambient_dir(tempdir.path()) }
.expect("open ambient temporary dir"); .expect("open ambient temporary dir");
/* DEBUG - non-temporary directory
let preopen_dir = unsafe { cap_std::fs::Dir::open_ambient_dir("c:\\") }
.expect("open ambient temporary dir");
*/
let preopen_dir = Dir::from_cap_std(preopen_dir); let preopen_dir = Dir::from_cap_std(preopen_dir);
let wasi_dir: &dyn WasiDir = &preopen_dir; let wasi_dir: &dyn WasiDir = &preopen_dir;
let target_path = tempdir.path().join("target");
/* DEBUG - non-temporary directory
let target_path = Path::new("c:\\target");
*/
// Clean up in case last test run
cleanup(&target_path);
let source_path = tempdir.path().join("source");
cleanup(&source_path);
let file = wasi_dir let file = wasi_dir
.open_file( .open_file(
false, false,