convert all errno assertions to assert_errno!

This commit is contained in:
Pat Hickey
2021-01-27 18:10:38 -08:00
parent 4f655001c0
commit 2ae1dee642
25 changed files with 147 additions and 233 deletions

View File

@@ -1,15 +1,14 @@
use std::{env, process};
use wasi_tests::{create_file, open_scratch_directory};
use wasi_tests::{assert_errno, create_file, open_scratch_directory};
unsafe fn test_path_symlink_trailing_slashes(dir_fd: wasi::Fd) {
// XXX following section invalid on windows because its a dangling symlink
// Dangling symlink: Link destination shouldn't end with a slash.
assert_eq!(
assert_errno!(
wasi::path_symlink("source", dir_fd, "target/")
.expect_err("link destination ending with a slash should fail")
.raw_error(),
wasi::ERRNO_NOENT,
"errno should be ERRNO_NOENT"
);
// Dangling symlink: Without the trailing slash, this should succeed.
@@ -19,24 +18,22 @@ unsafe fn test_path_symlink_trailing_slashes(dir_fd: wasi::Fd) {
// Link destination already exists, target has trailing slash.
wasi::path_create_directory(dir_fd, "target").expect("creating a directory");
// XXX windows gives NOENT
assert_eq!(
assert_errno!(
wasi::path_symlink("source", dir_fd, "target/")
.expect_err("link destination already exists")
.raw_error(),
wasi::ERRNO_EXIST,
"errno should be ERRNO_EXIST"
);
wasi::path_remove_directory(dir_fd, "target").expect("removing a directory");
// Link destination already exists, target has no trailing slash.
wasi::path_create_directory(dir_fd, "target").expect("creating a directory");
// XXX windows gives NOENT
assert_eq!(
assert_errno!(
wasi::path_symlink("source", dir_fd, "target")
.expect_err("link destination already exists")
.raw_error(),
wasi::ERRNO_EXIST,
"errno should be ERRNO_EXIST"
);
wasi::path_remove_directory(dir_fd, "target").expect("removing a directory");
@@ -44,13 +41,12 @@ unsafe fn test_path_symlink_trailing_slashes(dir_fd: wasi::Fd) {
create_file(dir_fd, "target");
// XXX windows gives NOENT
let dir_symlink_errno = wasi::path_symlink("source", dir_fd, "target/")
.expect_err("link destination already exists")
.raw_error();
assert!(
dir_symlink_errno == wasi::ERRNO_EXIST || dir_symlink_errno == wasi::ERRNO_NOTDIR,
"errno should be ERRNO_EXIST or ERRNO_NOTDIR, got {}",
dir_symlink_errno
assert_errno!(
wasi::path_symlink("source", dir_fd, "target/")
.expect_err("link destination already exists")
.raw_error(),
wasi::ERRNO_EXIST,
wasi::ERRNO_NOTDIR,
);
wasi::path_unlink_file(dir_fd, "target").expect("removing a file");
@@ -58,12 +54,11 @@ unsafe fn test_path_symlink_trailing_slashes(dir_fd: wasi::Fd) {
create_file(dir_fd, "target");
// XXX windows gives NOENT
assert_eq!(
assert_errno!(
wasi::path_symlink("source", dir_fd, "target")
.expect_err("link destination already exists")
.raw_error(),
wasi::ERRNO_EXIST,
"errno should be ERRNO_EXIST"
);
wasi::path_unlink_file(dir_fd, "target").expect("removing a file");
}