fix macro by denying trailing slashes. also other stuff

This commit is contained in:
Pat Hickey
2021-01-28 12:23:48 -08:00
parent 20e9169cc7
commit 1196e216e9
22 changed files with 77 additions and 72 deletions

View File

@@ -33,7 +33,8 @@ pub fn instantiate(data: &[u8], bin_name: &str, workspace: Option<&Path>) -> any
builder = builder builder = builder
.env("ERRNO_MODE_WINDOWS", "1")? .env("ERRNO_MODE_WINDOWS", "1")?
.env("NO_DANGLING_SYMLINKS", "1")? .env("NO_DANGLING_SYMLINKS", "1")?
.env("NO_FD_ALLOCATE", "1")?; .env("NO_FD_ALLOCATE", "1")?
.env("NO_RENAME_DIR_TO_EMPTY_DIR", "1")?;
} }
#[cfg(unix)] #[cfg(unix)]
{ {

View File

@@ -8,12 +8,11 @@ unsafe fn test_close_preopen(dir_fd: wasi::Fd) {
assert_gt!(dir_fd, pre_fd, "dir_fd number"); assert_gt!(dir_fd, pre_fd, "dir_fd number");
// Try to close a preopened directory handle. // Try to close a preopened directory handle.
assert_eq!( assert_errno!(
wasi::fd_close(pre_fd) wasi::fd_close(pre_fd)
.expect_err("closing a preopened file descriptor") .expect_err("closing a preopened file descriptor")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTSUP, wasi::ERRNO_NOTSUP
"errno should ERRNO_NOTSUP",
); );
// Try to renumber over a preopened directory handle. // Try to renumber over a preopened directory handle.
@@ -21,7 +20,7 @@ unsafe fn test_close_preopen(dir_fd: wasi::Fd) {
wasi::fd_renumber(dir_fd, pre_fd) wasi::fd_renumber(dir_fd, pre_fd)
.expect_err("renumbering over a preopened file descriptor") .expect_err("renumbering over a preopened file descriptor")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTSUP, wasi::ERRNO_NOTSUP
); );
// Ensure that dir_fd is still open. // Ensure that dir_fd is still open.
@@ -37,7 +36,7 @@ unsafe fn test_close_preopen(dir_fd: wasi::Fd) {
wasi::fd_renumber(pre_fd, dir_fd) wasi::fd_renumber(pre_fd, dir_fd)
.expect_err("renumbering over a preopened file descriptor") .expect_err("renumbering over a preopened file descriptor")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTSUP, wasi::ERRNO_NOTSUP
); );
// Ensure that dir_fd is still open. // Ensure that dir_fd is still open.

View File

@@ -19,7 +19,7 @@ unsafe fn test_dangling_symlink(dir_fd: wasi::Fd) {
wasi::path_open(dir_fd, 0, "symlink", 0, 0, 0, 0) wasi::path_open(dir_fd, 0, "symlink", 0, 0, 0, 0)
.expect_err("opening a dangling symlink as a file") .expect_err("opening a dangling symlink as a file")
.raw_error(), .raw_error(),
wasi::ERRNO_LOOP, wasi::ERRNO_LOOP
); );
// Clean up. // Clean up.

View File

@@ -28,7 +28,7 @@ unsafe fn test_directory_seek(dir_fd: wasi::Fd) {
wasi::fd_seek(fd, 0, wasi::WHENCE_CUR) wasi::fd_seek(fd, 0, wasi::WHENCE_CUR)
.expect_err("seek on a directory") .expect_err("seek on a directory")
.raw_error(), .raw_error(),
wasi::ERRNO_BADF, wasi::ERRNO_BADF
); );
// Check if we obtained the right to seek. // Check if we obtained the right to seek.

View File

@@ -61,7 +61,7 @@ unsafe fn test_file_seek_tell(dir_fd: wasi::Fd) {
wasi::fd_seek(file_fd, -2000, wasi::WHENCE_CUR) wasi::fd_seek(file_fd, -2000, wasi::WHENCE_CUR)
.expect_err("seeking before byte 0 should be an error") .expect_err("seeking before byte 0 should be an error")
.raw_error(), .raw_error(),
wasi::ERRNO_INVAL, wasi::ERRNO_INVAL
); );
// Check that fd_read properly updates the file offset // Check that fd_read properly updates the file offset

View File

@@ -17,7 +17,7 @@ unsafe fn test_interesting_paths(dir_fd: wasi::Fd, arg: &str) {
wasi::path_open(dir_fd, 0, "/dir/nested/file", 0, 0, 0, 0) wasi::path_open(dir_fd, 0, "/dir/nested/file", 0, 0, 0, 0)
.expect_err("opening a file with an absolute path") .expect_err("opening a file with an absolute path")
.raw_error(), .raw_error(),
wasi::ERRNO_PERM, wasi::ERRNO_PERM
); );
// Now open it with a path containing "..". // Now open it with a path containing "..".
@@ -43,7 +43,7 @@ unsafe fn test_interesting_paths(dir_fd: wasi::Fd, arg: &str) {
wasi::path_open(dir_fd, 0, "dir/nested/file\0", 0, 0, 0, 0) wasi::path_open(dir_fd, 0, "dir/nested/file\0", 0, 0, 0, 0)
.expect_err("opening a file with a trailing NUL") .expect_err("opening a file with a trailing NUL")
.raw_error(), .raw_error(),
wasi::ERRNO_ILSEQ, wasi::ERRNO_ILSEQ
); );
// Now open it with a trailing slash. // Now open it with a trailing slash.
@@ -52,7 +52,7 @@ unsafe fn test_interesting_paths(dir_fd: wasi::Fd, arg: &str) {
.expect_err("opening a file with a trailing slash should fail") .expect_err("opening a file with a trailing slash should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTDIR, wasi::ERRNO_NOTDIR,
wasi::ERRNO_NOENT, wasi::ERRNO_NOENT
); );
// Now open it with trailing slashes. // Now open it with trailing slashes.
@@ -61,7 +61,7 @@ unsafe fn test_interesting_paths(dir_fd: wasi::Fd, arg: &str) {
.expect_err("opening a file with trailing slashes should fail") .expect_err("opening a file with trailing slashes should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTDIR, wasi::ERRNO_NOTDIR,
wasi::ERRNO_NOENT, wasi::ERRNO_NOENT
); );
// Now open the directory with a trailing slash. // Now open the directory with a trailing slash.
@@ -90,7 +90,7 @@ unsafe fn test_interesting_paths(dir_fd: wasi::Fd, arg: &str) {
wasi::path_open(dir_fd, 0, &bad_path, 0, 0, 0, 0) wasi::path_open(dir_fd, 0, &bad_path, 0, 0, 0, 0)
.expect_err("opening a file with too many \"..\"s in the path should fail") .expect_err("opening a file with too many \"..\"s in the path should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_PERM, wasi::ERRNO_PERM
); );
wasi::path_unlink_file(dir_fd, "dir/nested/file") wasi::path_unlink_file(dir_fd, "dir/nested/file")
.expect("unlink_file on a symlink should succeed"); .expect("unlink_file on a symlink should succeed");

View File

@@ -16,7 +16,7 @@ unsafe fn test_nofollow_errors(dir_fd: wasi::Fd) {
.expect_err("opening a directory symlink as a directory should fail") .expect_err("opening a directory symlink as a directory should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_LOOP, wasi::ERRNO_LOOP,
wasi::ERRNO_NOTDIR, wasi::ERRNO_NOTDIR
); );
// Try to open it with just O_NOFOLLOW. // Try to open it with just O_NOFOLLOW.
@@ -25,7 +25,7 @@ unsafe fn test_nofollow_errors(dir_fd: wasi::Fd) {
.expect_err("opening a symlink with O_NOFOLLOW should fail") .expect_err("opening a symlink with O_NOFOLLOW should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_LOOP, wasi::ERRNO_LOOP,
wasi::ERRNO_ACCES, wasi::ERRNO_ACCES
); );
// Try to open it as a directory without O_NOFOLLOW. // Try to open it as a directory without O_NOFOLLOW.
@@ -70,7 +70,7 @@ unsafe fn test_nofollow_errors(dir_fd: wasi::Fd) {
wasi::path_open(dir_fd, 0, "symlink", 0, 0, 0, 0) wasi::path_open(dir_fd, 0, "symlink", 0, 0, 0, 0)
.expect_err("opening a symlink with NOFOLLOW should fail") .expect_err("opening a symlink with NOFOLLOW should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_LOOP, wasi::ERRNO_LOOP
); );
// Try to open it as a directory without O_NOFOLLOW. // Try to open it as a directory without O_NOFOLLOW.
@@ -86,7 +86,7 @@ unsafe fn test_nofollow_errors(dir_fd: wasi::Fd) {
) )
.expect_err("opening a symlink to a file as a directory") .expect_err("opening a symlink to a file as a directory")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTDIR, wasi::ERRNO_NOTDIR
); );
// Clean up. // Clean up.

View File

@@ -92,7 +92,7 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
) )
.expect_err("ATIM & ATIM_NOW can't both be set") .expect_err("ATIM & ATIM_NOW can't both be set")
.raw_error(), .raw_error(),
wasi::ERRNO_INVAL, wasi::ERRNO_INVAL
); );
wasi::fd_close(file_fd).expect("closing a file"); wasi::fd_close(file_fd).expect("closing a file");

View File

@@ -148,7 +148,7 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) {
wasi::path_link(dir_fd, 0, "file", dir_fd, "link/") wasi::path_link(dir_fd, 0, "file", dir_fd, "link/")
.expect_err("creating a link to a file with trailing slash should fail") .expect_err("creating a link to a file with trailing slash should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_NOENT, wasi::ERRNO_NOENT
); );
// XXX windows doesnt support dangling symlinks - rest of file // XXX windows doesnt support dangling symlinks - rest of file
@@ -176,7 +176,7 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) {
wasi::path_link(dir_fd, 0, "file", dir_fd, "symlink") wasi::path_link(dir_fd, 0, "file", dir_fd, "symlink")
.expect_err("creating a link where target is a dangling symlink") .expect_err("creating a link where target is a dangling symlink")
.raw_error(), .raw_error(),
wasi::ERRNO_EXIST, wasi::ERRNO_EXIST
); );
wasi::path_unlink_file(dir_fd, "symlink").expect("removing a symlink"); wasi::path_unlink_file(dir_fd, "symlink").expect("removing a symlink");
@@ -194,7 +194,7 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) {
) )
.expect_err("calling path_link with LOOKUPFLAGS_SYMLINK_FOLLOW should fail") .expect_err("calling path_link with LOOKUPFLAGS_SYMLINK_FOLLOW should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_INVAL, wasi::ERRNO_INVAL
); );
// Clean up. // Clean up.

View File

@@ -15,7 +15,7 @@ unsafe fn test_path_open_create_existing(dir_fd: wasi::Fd) {
) )
.expect_err("trying to create a file that already exists") .expect_err("trying to create a file that already exists")
.raw_error(), .raw_error(),
wasi::ERRNO_EXIST, wasi::ERRNO_EXIST
); );
wasi::path_unlink_file(dir_fd, "file").expect("removing a file"); wasi::path_unlink_file(dir_fd, "file").expect("removing a file");
} }

View File

@@ -10,7 +10,7 @@ unsafe fn test_dirfd_not_dir(dir_fd: wasi::Fd) {
wasi::path_open(file_fd, 0, "foo", wasi::OFLAGS_CREAT, 0, 0, 0) wasi::path_open(file_fd, 0, "foo", wasi::OFLAGS_CREAT, 0, 0, 0)
.expect_err("non-directory base fd should get ERRNO_NOTDIR") .expect_err("non-directory base fd should get ERRNO_NOTDIR")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTDIR, wasi::ERRNO_NOTDIR
); );
wasi::fd_close(file_fd).expect("closing a file"); wasi::fd_close(file_fd).expect("closing a file");
} }

View File

@@ -1,6 +1,6 @@
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi_tests::{assert_errno, create_file, open_scratch_directory}; use wasi_tests::{assert_errno, create_file, open_scratch_directory, TESTCONFIG};
unsafe fn test_path_rename(dir_fd: wasi::Fd) { unsafe fn test_path_rename(dir_fd: wasi::Fd) {
// First, try renaming a dir to nonexistent path // First, try renaming a dir to nonexistent path
@@ -30,6 +30,7 @@ unsafe fn test_path_rename(dir_fd: wasi::Fd) {
wasi::fd_close(fd).expect("closing a file"); wasi::fd_close(fd).expect("closing a file");
wasi::path_remove_directory(dir_fd, "target").expect("removing a directory"); wasi::path_remove_directory(dir_fd, "target").expect("removing a directory");
if TESTCONFIG.support_rename_dir_to_empty_dir() {
// Now, try renaming renaming a dir to existing empty dir // Now, try renaming renaming a dir to existing empty dir
wasi::path_create_directory(dir_fd, "source").expect("creating a directory"); wasi::path_create_directory(dir_fd, "source").expect("creating a directory");
wasi::path_create_directory(dir_fd, "target").expect("creating a directory"); wasi::path_create_directory(dir_fd, "target").expect("creating a directory");
@@ -54,6 +55,7 @@ unsafe fn test_path_rename(dir_fd: wasi::Fd) {
wasi::fd_close(fd).expect("closing a file"); wasi::fd_close(fd).expect("closing a file");
wasi::path_remove_directory(dir_fd, "target").expect("removing a directory"); wasi::path_remove_directory(dir_fd, "target").expect("removing a directory");
}
// Now, try renaming a dir to existing non-empty dir // Now, try renaming a dir to existing non-empty dir
wasi::path_create_directory(dir_fd, "source").expect("creating a directory"); wasi::path_create_directory(dir_fd, "source").expect("creating a directory");
@@ -64,7 +66,8 @@ unsafe fn test_path_rename(dir_fd: wasi::Fd) {
wasi::path_rename(dir_fd, "source", dir_fd, "target") wasi::path_rename(dir_fd, "source", dir_fd, "target")
.expect_err("renaming directory to a nonempty directory") .expect_err("renaming directory to a nonempty directory")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTEMPTY windows => wasi::ERRNO_ACCES,
unix => wasi::ERRNO_NOTEMPTY
); );
// Try renaming dir to a file // Try renaming dir to a file
@@ -128,7 +131,6 @@ unsafe fn test_path_rename(dir_fd: wasi::Fd) {
wasi::fd_close(fd).expect("closing a file"); wasi::fd_close(fd).expect("closing a file");
wasi::path_unlink_file(dir_fd, "target").expect("removing a file"); wasi::path_unlink_file(dir_fd, "target").expect("removing a file");
// XXX windows does not support this operation
// Try renaming to an (empty) directory instead // Try renaming to an (empty) directory instead
create_file(dir_fd, "source"); create_file(dir_fd, "source");
wasi::path_create_directory(dir_fd, "target").expect("creating a directory"); wasi::path_create_directory(dir_fd, "target").expect("creating a directory");

View File

@@ -13,19 +13,19 @@ unsafe fn test_path_rename_trailing_slashes(dir_fd: wasi::Fd) {
wasi::path_rename(dir_fd, "source/", dir_fd, "target") wasi::path_rename(dir_fd, "source/", dir_fd, "target")
.expect_err("renaming a file with a trailing slash in the source name should fail") .expect_err("renaming a file with a trailing slash in the source name should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTDIR, wasi::ERRNO_NOTDIR
); );
assert_errno!( assert_errno!(
wasi::path_rename(dir_fd, "source", dir_fd, "target/") wasi::path_rename(dir_fd, "source", dir_fd, "target/")
.expect_err("renaming a file with a trailing slash in the destination name should fail") .expect_err("renaming a file with a trailing slash in the destination name should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTDIR, wasi::ERRNO_NOTDIR
); );
assert_errno!( assert_errno!(
wasi::path_rename(dir_fd, "source/", dir_fd, "target/") wasi::path_rename(dir_fd, "source/", dir_fd, "target/")
.expect_err("renaming a file with a trailing slash in the source and destination names should fail") .expect_err("renaming a file with a trailing slash in the source and destination names should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTDIR, wasi::ERRNO_NOTDIR
); );
wasi::path_unlink_file(dir_fd, "source").expect("removing a file"); wasi::path_unlink_file(dir_fd, "source").expect("removing a file");
} }

View File

@@ -8,7 +8,7 @@ unsafe fn test_path_symlink_trailing_slashes(dir_fd: wasi::Fd) {
wasi::path_symlink("source", dir_fd, "target/") wasi::path_symlink("source", dir_fd, "target/")
.expect_err("link destination ending with a slash should fail") .expect_err("link destination ending with a slash should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_NOENT, wasi::ERRNO_NOENT
); );
// Dangling symlink: Without the trailing slash, this should succeed. // Dangling symlink: Without the trailing slash, this should succeed.
@@ -34,7 +34,7 @@ unsafe fn test_path_symlink_trailing_slashes(dir_fd: wasi::Fd) {
wasi::path_symlink("source", dir_fd, "target") wasi::path_symlink("source", dir_fd, "target")
.expect_err("link destination already exists") .expect_err("link destination already exists")
.raw_error(), .raw_error(),
wasi::ERRNO_EXIST, wasi::ERRNO_EXIST
); );
wasi::path_remove_directory(dir_fd, "target").expect("removing a directory"); wasi::path_remove_directory(dir_fd, "target").expect("removing a directory");
@@ -47,7 +47,7 @@ unsafe fn test_path_symlink_trailing_slashes(dir_fd: wasi::Fd) {
.expect_err("link destination already exists") .expect_err("link destination already exists")
.raw_error(), .raw_error(),
wasi::ERRNO_EXIST, wasi::ERRNO_EXIST,
wasi::ERRNO_NOTDIR, wasi::ERRNO_NOTDIR
); );
wasi::path_unlink_file(dir_fd, "target").expect("removing a file"); wasi::path_unlink_file(dir_fd, "target").expect("removing a file");
@@ -59,7 +59,7 @@ unsafe fn test_path_symlink_trailing_slashes(dir_fd: wasi::Fd) {
wasi::path_symlink("source", dir_fd, "target") wasi::path_symlink("source", dir_fd, "target")
.expect_err("link destination already exists") .expect_err("link destination already exists")
.raw_error(), .raw_error(),
wasi::ERRNO_EXIST, wasi::ERRNO_EXIST
); );
wasi::path_unlink_file(dir_fd, "target").expect("removing a file"); wasi::path_unlink_file(dir_fd, "target").expect("removing a file");
} }

View File

@@ -21,7 +21,7 @@ unsafe fn test_empty_poll() {
wasi::poll_oneoff(r#in.as_ptr(), out.as_mut_ptr(), r#in.len()) wasi::poll_oneoff(r#in.as_ptr(), out.as_mut_ptr(), r#in.len())
.expect_err("empty poll_oneoff should fail") .expect_err("empty poll_oneoff should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_INVAL, wasi::ERRNO_INVAL
); );
} }
@@ -42,7 +42,7 @@ unsafe fn test_timeout() {
let out = poll_oneoff_impl(&r#in).unwrap(); let out = poll_oneoff_impl(&r#in).unwrap();
assert_eq!(out.len(), 1, "should return 1 event"); assert_eq!(out.len(), 1, "should return 1 event");
let event = &out[0]; let event = &out[0];
assert_errno!(event.error, wasi::ERRNO_SUCCESS,); assert_errno!(event.error, wasi::ERRNO_SUCCESS);
assert_eq!( assert_eq!(
event.r#type, event.r#type,
wasi::EVENTTYPE_CLOCK, wasi::EVENTTYPE_CLOCK,

View File

@@ -25,7 +25,7 @@ unsafe fn test_remove_directory_trailing_slashes(dir_fd: wasi::Fd) {
wasi::path_remove_directory(dir_fd, "file") wasi::path_remove_directory(dir_fd, "file")
.expect_err("remove_directory without a trailing slash on a file should fail") .expect_err("remove_directory without a trailing slash on a file should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTDIR, wasi::ERRNO_NOTDIR
); );
// Test that removing it with a trailing slash fails. // Test that removing it with a trailing slash fails.
@@ -34,7 +34,7 @@ unsafe fn test_remove_directory_trailing_slashes(dir_fd: wasi::Fd) {
wasi::path_remove_directory(dir_fd, "file/") wasi::path_remove_directory(dir_fd, "file/")
.expect_err("remove_directory with a trailing slash on a file should fail") .expect_err("remove_directory with a trailing slash on a file should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTDIR, wasi::ERRNO_NOTDIR
); );
wasi::path_unlink_file(dir_fd, "file").expect("removing a file"); wasi::path_unlink_file(dir_fd, "file").expect("removing a file");

View File

@@ -53,7 +53,7 @@ unsafe fn test_renumber(dir_fd: wasi::Fd) {
wasi::fd_close(fd_from) wasi::fd_close(fd_from)
.expect_err("closing already closed file descriptor") .expect_err("closing already closed file descriptor")
.raw_error(), .raw_error(),
wasi::ERRNO_BADF, wasi::ERRNO_BADF
); );
// Ensure that fd_to is still open. // Ensure that fd_to is still open.

View File

@@ -10,7 +10,7 @@ unsafe fn test_symlink_loop(dir_fd: wasi::Fd) {
wasi::path_open(dir_fd, 0, "symlink", 0, 0, 0, 0) wasi::path_open(dir_fd, 0, "symlink", 0, 0, 0, 0)
.expect_err("opening a self-referencing symlink") .expect_err("opening a self-referencing symlink")
.raw_error(), .raw_error(),
wasi::ERRNO_LOOP, wasi::ERRNO_LOOP
); );
// Clean up. // Clean up.

View File

@@ -68,7 +68,7 @@ unsafe fn test_truncation_rights(dir_fd: wasi::Fd) {
wasi::path_open(dir_fd, 0, "file", wasi::OFLAGS_TRUNC, 0, 0, 0) wasi::path_open(dir_fd, 0, "file", wasi::OFLAGS_TRUNC, 0, 0, 0)
.expect_err("truncating a file without path_filestat_set_size right") .expect_err("truncating a file without path_filestat_set_size right")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTCAPABLE, wasi::ERRNO_NOTCAPABLE
); );
} }

View File

@@ -11,7 +11,7 @@ unsafe fn test_unlink_file_trailing_slashes(dir_fd: wasi::Fd) {
wasi::path_unlink_file(dir_fd, "dir") wasi::path_unlink_file(dir_fd, "dir")
.expect_err("unlink_file on a directory should fail") .expect_err("unlink_file on a directory should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_ISDIR, wasi::ERRNO_ISDIR
); );
// Test that unlinking it with a trailing flash fails. // Test that unlinking it with a trailing flash fails.
@@ -20,7 +20,7 @@ unsafe fn test_unlink_file_trailing_slashes(dir_fd: wasi::Fd) {
wasi::path_unlink_file(dir_fd, "dir/") wasi::path_unlink_file(dir_fd, "dir/")
.expect_err("unlink_file on a directory should fail") .expect_err("unlink_file on a directory should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_ISDIR, wasi::ERRNO_ISDIR
); );
// Clean up. // Clean up.
@@ -35,7 +35,7 @@ unsafe fn test_unlink_file_trailing_slashes(dir_fd: wasi::Fd) {
wasi::path_unlink_file(dir_fd, "file/") wasi::path_unlink_file(dir_fd, "file/")
.expect_err("unlink_file with a trailing slash should fail") .expect_err("unlink_file with a trailing slash should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTDIR, wasi::ERRNO_NOTDIR
); );
// Test that unlinking it with no trailing flash succeeds. // Test that unlinking it with no trailing flash succeeds.

View File

@@ -2,6 +2,7 @@ pub struct TestConfig {
errno_mode: ErrnoMode, errno_mode: ErrnoMode,
no_dangling_symlinks: bool, no_dangling_symlinks: bool,
no_fd_allocate: bool, no_fd_allocate: bool,
no_rename_dir_to_empty_dir: bool,
} }
enum ErrnoMode { enum ErrnoMode {
@@ -21,10 +22,12 @@ impl TestConfig {
}; };
let no_dangling_symlinks = std::env::var("NO_DANGLING_SYMLINKS").is_ok(); let no_dangling_symlinks = std::env::var("NO_DANGLING_SYMLINKS").is_ok();
let no_fd_allocate = std::env::var("NO_FD_ALLOCATE").is_ok(); let no_fd_allocate = std::env::var("NO_FD_ALLOCATE").is_ok();
let no_rename_dir_to_empty_dir = std::env::var("NO_RENAME_DIR_TO_EMPTY_DIR").is_ok();
TestConfig { TestConfig {
errno_mode, errno_mode,
no_dangling_symlinks, no_dangling_symlinks,
no_fd_allocate, no_fd_allocate,
no_rename_dir_to_empty_dir,
} }
} }
pub fn errno_expect_unix(&self) -> bool { pub fn errno_expect_unix(&self) -> bool {
@@ -45,4 +48,7 @@ impl TestConfig {
pub fn support_fd_allocate(&self) -> bool { pub fn support_fd_allocate(&self) -> bool {
!self.no_fd_allocate !self.no_fd_allocate
} }
pub fn support_rename_dir_to_empty_dir(&self) -> bool {
!self.no_rename_dir_to_empty_dir
}
} }

View File

@@ -69,23 +69,20 @@ pub unsafe fn drop_rights(fd: wasi::Fd, drop_base: wasi::Rights, drop_inheriting
#[macro_export] #[macro_export]
macro_rules! assert_errno { macro_rules! assert_errno {
($s:expr, $( $i:expr ),+,) => { ($s:expr, windows => $i:expr, $( $rest:tt )+) => {
assert_errno!($s, $( $i ),+)
};
($s:expr, windows => $i:expr, $( $rest:expr ),+) => {
let e = $s; let e = $s;
if $crate::TESTCONFIG.errno_expect_windows() { if $crate::TESTCONFIG.errno_expect_windows() {
assert_errno!(e, $i); assert_errno!(e, $i);
} else { } else {
assert_errno!(e, $($rest),+, $i); assert_errno!(e, $($rest)+, $i);
} }
}; };
($s:expr, unix => $i:expr, $( $rest:expr ),+) => { ($s:expr, unix => $i:expr, $( $rest:tt )+) => {
let e = $s; let e = $s;
if $crate::TESTCONFIG.errno_expect_unix() { if $crate::TESTCONFIG.errno_expect_unix() {
assert_errno!(e, $i); assert_errno!(e, $i);
} else { } else {
assert_errno!(e, $($rest),+, $i); assert_errno!(e, $($rest)+, $i);
} }
}; };
($s:expr, $( $i:expr ),+) => { ($s:expr, $( $i:expr ),+) => {