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,6 +1,6 @@
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi_tests::open_scratch_directory; use wasi_tests::{assert_errno, open_scratch_directory};
unsafe fn test_close_preopen(dir_fd: wasi::Fd) { unsafe fn test_close_preopen(dir_fd: wasi::Fd) {
let pre_fd: wasi::Fd = (libc::STDERR_FILENO + 1) as wasi::Fd; let pre_fd: wasi::Fd = (libc::STDERR_FILENO + 1) as wasi::Fd;
@@ -17,12 +17,11 @@ unsafe fn test_close_preopen(dir_fd: wasi::Fd) {
); );
// Try to renumber over a preopened directory handle. // Try to renumber over a preopened directory handle.
assert_eq!( assert_errno!(
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,
"errno should be ERRNO_NOTSUP",
); );
// Ensure that dir_fd is still open. // Ensure that dir_fd is still open.
@@ -34,12 +33,11 @@ unsafe fn test_close_preopen(dir_fd: wasi::Fd) {
); );
// Try to renumber a preopened directory handle. // Try to renumber a preopened directory handle.
assert_eq!( assert_errno!(
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,
"errno should be ERRNO_NOTSUP",
); );
// Ensure that dir_fd is still open. // Ensure that dir_fd is still open.

View File

@@ -1,26 +1,25 @@
use std::{env, process}; use std::{env, process};
use wasi_tests::open_scratch_directory; use wasi_tests::{assert_errno, open_scratch_directory};
unsafe fn test_dangling_symlink(dir_fd: wasi::Fd) { unsafe fn test_dangling_symlink(dir_fd: wasi::Fd) {
// First create a dangling symlink. // First create a dangling symlink.
wasi::path_symlink("target", dir_fd, "symlink").expect("creating a symlink"); wasi::path_symlink("target", dir_fd, "symlink").expect("creating a symlink");
// Try to open it as a directory with O_NOFOLLOW. // Try to open it as a directory with O_NOFOLLOW.
let dir_open_errno = wasi::path_open(dir_fd, 0, "symlink", wasi::OFLAGS_DIRECTORY, 0, 0, 0) assert_errno!(
wasi::path_open(dir_fd, 0, "symlink", wasi::OFLAGS_DIRECTORY, 0, 0, 0)
.expect_err("opening a dangling symlink as a directory") .expect_err("opening a dangling symlink as a directory")
.raw_error(); .raw_error(),
assert!( wasi::ERRNO_NOTDIR,
dir_open_errno == wasi::ERRNO_NOTDIR || dir_open_errno == wasi::ERRNO_LOOP, wasi::ERRNO_LOOP
"errno should be ERRNO_NOTDIR or ERRNO_LOOP",
); );
// Try to open it as a file with O_NOFOLLOW. // Try to open it as a file with O_NOFOLLOW.
assert_eq!( assert_errno!(
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,
"errno should be ERRNO_LOOP",
); );
// Clean up. // Clean up.

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::open_scratch_directory; use wasi_tests::{assert_errno, open_scratch_directory};
unsafe fn test_directory_seek(dir_fd: wasi::Fd) { unsafe fn test_directory_seek(dir_fd: wasi::Fd) {
// Create a directory in the scratch directory. // Create a directory in the scratch directory.
@@ -24,12 +24,11 @@ unsafe fn test_directory_seek(dir_fd: wasi::Fd) {
); );
// Attempt to seek. // Attempt to seek.
assert_eq!( assert_errno!(
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,
"errno should be BADF"
); );
// Check if we obtained the right to seek. // Check if we obtained the right to seek.

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::open_scratch_directory; use wasi_tests::{assert_errno, open_scratch_directory};
unsafe fn test_file_seek_tell(dir_fd: wasi::Fd) { unsafe fn test_file_seek_tell(dir_fd: wasi::Fd) {
// Create a file in the scratch directory. // Create a file in the scratch directory.
@@ -57,16 +57,16 @@ unsafe fn test_file_seek_tell(dir_fd: wasi::Fd) {
wasi::fd_seek(file_fd, 1000, wasi::WHENCE_CUR).expect("seeking beyond the end of the file"); wasi::fd_seek(file_fd, 1000, wasi::WHENCE_CUR).expect("seeking beyond the end of the file");
// Seek before byte 0 is an error though // Seek before byte 0 is an error though
assert_eq!( assert_errno!(
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,
"errno should be ERRNO_INVAL",
); );
// Check that fd_read properly updates the file offset // Check that fd_read properly updates the file offset
wasi::fd_seek(file_fd, 0, wasi::WHENCE_SET).expect("seeking to the beginning of the file again"); wasi::fd_seek(file_fd, 0, wasi::WHENCE_SET)
.expect("seeking to the beginning of the file again");
let buffer = &mut [0u8; 100]; let buffer = &mut [0u8; 100];
let iovec = wasi::Iovec { let iovec = wasi::Iovec {

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::{create_file, open_scratch_directory}; use wasi_tests::{assert_errno, create_file, open_scratch_directory};
unsafe fn test_interesting_paths(dir_fd: wasi::Fd, arg: &str) { unsafe fn test_interesting_paths(dir_fd: wasi::Fd, arg: &str) {
// Create a directory in the scratch directory. // Create a directory in the scratch directory.
@@ -13,12 +13,11 @@ unsafe fn test_interesting_paths(dir_fd: wasi::Fd, arg: &str) {
create_file(dir_fd, "dir/nested/file"); create_file(dir_fd, "dir/nested/file");
// Now open it with an absolute path. // Now open it with an absolute path.
assert_eq!( assert_errno!(
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,
"errno should be ERRNO_PERM"
); );
// Now open it with a path containing "..". // Now open it with a path containing "..".
@@ -40,34 +39,29 @@ unsafe fn test_interesting_paths(dir_fd: wasi::Fd, arg: &str) {
wasi::fd_close(file_fd).expect("closing a file"); wasi::fd_close(file_fd).expect("closing a file");
// Now open it with a trailing NUL. // Now open it with a trailing NUL.
assert_eq!( assert_errno!(
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,
"errno should be ERRNO_ILSEQ",
); );
// Now open it with a trailing slash. // Now open it with a trailing slash.
let one_trailing_slash_errno = wasi::path_open(dir_fd, 0, "dir/nested/file/", 0, 0, 0, 0) assert_errno!(
wasi::path_open(dir_fd, 0, "dir/nested/file/", 0, 0, 0, 0)
.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(),
assert!( wasi::ERRNO_NOTDIR,
one_trailing_slash_errno == wasi::ERRNO_NOTDIR wasi::ERRNO_NOENT,
|| one_trailing_slash_errno == wasi::ERRNO_NOENT,
"errno should be ERRNO_NOTDIR or ERRNO_NOENT, got {}",
one_trailing_slash_errno
); );
// Now open it with trailing slashes. // Now open it with trailing slashes.
let multi_trailing_slash_errno = wasi::path_open(dir_fd, 0, "dir/nested/file///", 0, 0, 0, 0) assert_errno!(
wasi::path_open(dir_fd, 0, "dir/nested/file///", 0, 0, 0, 0)
.expect_err("opening a file with trailing slashes should fail") .expect_err("opening a file with trailing slashes should fail")
.raw_error(); .raw_error(),
assert!( wasi::ERRNO_NOTDIR,
multi_trailing_slash_errno == wasi::ERRNO_NOTDIR wasi::ERRNO_NOENT,
|| multi_trailing_slash_errno == wasi::ERRNO_NOENT,
"errno should be ERRNO_NOTDIR or ERRNO_NOENT, got {}",
multi_trailing_slash_errno,
); );
// Now open the directory with a trailing slash. // Now open the directory with a trailing slash.
@@ -92,12 +86,11 @@ unsafe fn test_interesting_paths(dir_fd: wasi::Fd, arg: &str) {
// Now open it with a path containing too many ".."s. // Now open it with a path containing too many ".."s.
let bad_path = format!("dir/nested/../../../{}/dir/nested/file", arg); let bad_path = format!("dir/nested/../../../{}/dir/nested/file", arg);
assert_eq!( assert_errno!(
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,
"errno should be 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

@@ -1,7 +1,7 @@
use libc; use libc;
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, process}; use std::{env, process};
use wasi_tests::open_scratch_directory; use wasi_tests::{assert_errno, open_scratch_directory};
unsafe fn test_nofollow_errors(dir_fd: wasi::Fd) { unsafe fn test_nofollow_errors(dir_fd: wasi::Fd) {
// Create a directory for the symlink to point to. // Create a directory for the symlink to point to.
@@ -11,23 +11,21 @@ unsafe fn test_nofollow_errors(dir_fd: wasi::Fd) {
wasi::path_symlink("target", dir_fd, "symlink").expect("creating a symlink"); wasi::path_symlink("target", dir_fd, "symlink").expect("creating a symlink");
// Try to open it as a directory with O_NOFOLLOW again. // Try to open it as a directory with O_NOFOLLOW again.
let dir_open_errno = wasi::path_open(dir_fd, 0, "symlink", wasi::OFLAGS_DIRECTORY, 0, 0, 0) assert_errno!(
wasi::path_open(dir_fd, 0, "symlink", wasi::OFLAGS_DIRECTORY, 0, 0, 0)
.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(),
assert!( wasi::ERRNO_LOOP,
dir_open_errno == wasi::ERRNO_LOOP || dir_open_errno == wasi::ERRNO_NOTDIR, wasi::ERRNO_NOTDIR,
"errno should be ERRNO_LOOP or ERRNO_NOTDIR, got {}",
dir_open_errno,
); );
// Try to open it with just O_NOFOLLOW. // Try to open it with just O_NOFOLLOW.
let file_open_errno = wasi::path_open(dir_fd, 0, "symlink", 0, 0, 0, 0) assert_errno!(
wasi::path_open(dir_fd, 0, "symlink", 0, 0, 0, 0)
.expect_err("opening a symlink with O_NOFOLLOW should fail") .expect_err("opening a symlink with O_NOFOLLOW should fail")
.raw_error(); .raw_error(),
assert!( wasi::ERRNO_LOOP,
file_open_errno == wasi::ERRNO_LOOP || file_open_errno == wasi::ERRNO_ACCES, wasi::ERRNO_ACCES,
"errno should be ERRNO_LOOP or ERRNO_ACCES, got {}",
file_open_errno,
); );
// Try to open it as a directory without O_NOFOLLOW. // Try to open it as a directory without O_NOFOLLOW.
@@ -59,25 +57,24 @@ unsafe fn test_nofollow_errors(dir_fd: wasi::Fd) {
wasi::path_symlink("target", dir_fd, "symlink").expect("creating a symlink"); wasi::path_symlink("target", dir_fd, "symlink").expect("creating a symlink");
// Try to open it as a directory with O_NOFOLLOW again. // Try to open it as a directory with O_NOFOLLOW again.
let dir_open_errno = wasi::path_open(dir_fd, 0, "symlink", wasi::OFLAGS_DIRECTORY, 0, 0, 0) assert_errno!(
wasi::path_open(dir_fd, 0, "symlink", wasi::OFLAGS_DIRECTORY, 0, 0, 0)
.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(),
assert!( wasi::ERRNO_LOOP,
dir_open_errno == wasi::ERRNO_LOOP || dir_open_errno == wasi::ERRNO_NOTDIR, wasi::ERRNO_NOTDIR
"errno should be ERRNO_LOOP or ERRNO_NOTDIR",
); );
// Try to open it with just O_NOFOLLOW. // Try to open it with just O_NOFOLLOW.
assert_eq!( assert_errno!(
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,
"errno should be ERRNO_LOOP",
); );
// Try to open it as a directory without O_NOFOLLOW. // Try to open it as a directory without O_NOFOLLOW.
assert_eq!( assert_errno!(
wasi::path_open( wasi::path_open(
dir_fd, dir_fd,
wasi::LOOKUPFLAGS_SYMLINK_FOLLOW, wasi::LOOKUPFLAGS_SYMLINK_FOLLOW,
@@ -90,7 +87,6 @@ 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,
"errno should be ERRNO_NOTDIR",
); );
// Clean up. // Clean up.

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::open_scratch_directory; use wasi_tests::{assert_errno, open_scratch_directory};
unsafe fn test_path_filestat(dir_fd: wasi::Fd) { unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
let mut fdstat = wasi::fd_fdstat_get(dir_fd).expect("fd_fdstat_get"); let mut fdstat = wasi::fd_fdstat_get(dir_fd).expect("fd_fdstat_get");
@@ -58,7 +58,7 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
.expect("reading file stats after path_filestat_set_times"); .expect("reading file stats after path_filestat_set_times");
assert_eq!(modified_file_stat.mtim, new_mtim, "mtim should change"); assert_eq!(modified_file_stat.mtim, new_mtim, "mtim should change");
assert_eq!( assert_errno!(
wasi::path_filestat_set_times( wasi::path_filestat_set_times(
dir_fd, dir_fd,
0, 0,
@@ -69,8 +69,7 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
) )
.expect_err("MTIM and MTIM_NOW can't both be set") .expect_err("MTIM and MTIM_NOW can't both be set")
.raw_error(), .raw_error(),
wasi::ERRNO_INVAL, wasi::ERRNO_INVAL
"errno should be ERRNO_INVAL"
); );
// check if the times were untouched // check if the times were untouched
@@ -82,7 +81,7 @@ unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
); );
// Invalid arguments to set_times: // Invalid arguments to set_times:
assert_eq!( assert_errno!(
wasi::path_filestat_set_times( wasi::path_filestat_set_times(
dir_fd, dir_fd,
0, 0,
@@ -94,7 +93,6 @@ 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,
"errno should be ERRNO_INVAL"
); );
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::{create_file, open_scratch_directory}; use wasi_tests::{assert_errno, create_file, open_scratch_directory};
const TEST_RIGHTS: wasi::Rights = wasi::RIGHTS_FD_READ const TEST_RIGHTS: wasi::Rights = wasi::RIGHTS_FD_READ
| wasi::RIGHTS_PATH_LINK_SOURCE | wasi::RIGHTS_PATH_LINK_SOURCE
@@ -102,33 +102,30 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) {
// Create a link to a path that already exists // Create a link to a path that already exists
create_file(dir_fd, "link"); create_file(dir_fd, "link");
assert_eq!( assert_errno!(
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 existing path should fail") .expect_err("creating a link to existing path should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_EXIST, wasi::ERRNO_EXIST
"errno should be ERRNO_EXIST"
); );
wasi::path_unlink_file(dir_fd, "link").expect("removing a file"); wasi::path_unlink_file(dir_fd, "link").expect("removing a file");
// Create a link to itself // Create a link to itself
assert_eq!( assert_errno!(
wasi::path_link(dir_fd, 0, "file", dir_fd, "file") wasi::path_link(dir_fd, 0, "file", dir_fd, "file")
.expect_err("creating a link to itself should fail") .expect_err("creating a link to itself should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_EXIST, wasi::ERRNO_EXIST
"errno should be ERRNO_EXIST"
); );
// Create a link where target is a directory // Create a link where target is a directory
wasi::path_create_directory(dir_fd, "link").expect("creating a dir"); wasi::path_create_directory(dir_fd, "link").expect("creating a dir");
assert_eq!( assert_errno!(
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 where target is a directory should fail") .expect_err("creating a link where target is a directory should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_EXIST, wasi::ERRNO_EXIST
"errno should be ERRNO_EXIST"
); );
wasi::path_remove_directory(dir_fd, "link").expect("removing a dir"); wasi::path_remove_directory(dir_fd, "link").expect("removing a dir");
@@ -136,23 +133,22 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) {
wasi::path_create_directory(dir_fd, "subdir").expect("creating a subdirectory"); wasi::path_create_directory(dir_fd, "subdir").expect("creating a subdirectory");
let subdir_fd = create_or_open(dir_fd, "subdir", wasi::OFLAGS_DIRECTORY); let subdir_fd = create_or_open(dir_fd, "subdir", wasi::OFLAGS_DIRECTORY);
let path_link_errno = wasi::path_link(dir_fd, 0, "subdir", dir_fd, "link") assert_errno!(
wasi::path_link(dir_fd, 0, "subdir", dir_fd, "link")
.expect_err("creating a link to a directory should fail") .expect_err("creating a link to a directory should fail")
.raw_error(); .raw_error(),
assert!( wasi::ERRNO_PERM,
path_link_errno == wasi::ERRNO_PERM || path_link_errno == wasi::ERRNO_ACCES, wasi::ERRNO_ACCES
"errno should be ERRNO_PERM or ERRNO_ACCES"
); );
wasi::fd_close(subdir_fd).expect("close subdir before deleting it"); wasi::fd_close(subdir_fd).expect("close subdir before deleting it");
wasi::path_remove_directory(dir_fd, "subdir").expect("removing a subdirectory"); wasi::path_remove_directory(dir_fd, "subdir").expect("removing a subdirectory");
// Create a link to a file with trailing slash // Create a link to a file with trailing slash
assert_eq!( assert_errno!(
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,
"errno should be ERRNO_NOENT"
); );
// XXX windows doesnt support dangling symlinks - rest of file // XXX windows doesnt support dangling symlinks - rest of file
@@ -176,12 +172,11 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) {
// Create a link where target is a dangling symlink // Create a link where target is a dangling symlink
wasi::path_symlink("target", dir_fd, "symlink").expect("creating a dangling symlink"); wasi::path_symlink("target", dir_fd, "symlink").expect("creating a dangling symlink");
assert_eq!( assert_errno!(
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,
"errno should be ERRNO_EXIST"
); );
wasi::path_unlink_file(dir_fd, "symlink").expect("removing a symlink"); wasi::path_unlink_file(dir_fd, "symlink").expect("removing a symlink");
@@ -189,7 +184,7 @@ unsafe fn test_path_link(dir_fd: wasi::Fd) {
wasi::path_symlink("target", dir_fd, "symlink").expect("creating a dangling symlink"); wasi::path_symlink("target", dir_fd, "symlink").expect("creating a dangling symlink");
// Symlink following with path_link is rejected // Symlink following with path_link is rejected
assert_eq!( assert_errno!(
wasi::path_link( wasi::path_link(
dir_fd, dir_fd,
wasi::LOOKUPFLAGS_SYMLINK_FOLLOW, wasi::LOOKUPFLAGS_SYMLINK_FOLLOW,
@@ -200,7 +195,6 @@ 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,
"errno should be ERRNO_INVAL"
); );
// Clean up. // Clean up.

View File

@@ -1,9 +1,9 @@
use std::{env, process}; 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_open_create_existing(dir_fd: wasi::Fd) { unsafe fn test_path_open_create_existing(dir_fd: wasi::Fd) {
create_file(dir_fd, "file"); create_file(dir_fd, "file");
assert_eq!( assert_errno!(
wasi::path_open( wasi::path_open(
dir_fd, dir_fd,
0, 0,
@@ -16,7 +16,6 @@ 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,
"errno should be 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

@@ -1,17 +1,16 @@
use std::{env, process}; use std::{env, process};
use wasi_tests::open_scratch_directory; use wasi_tests::{assert_errno, open_scratch_directory};
unsafe fn test_dirfd_not_dir(dir_fd: wasi::Fd) { unsafe fn test_dirfd_not_dir(dir_fd: wasi::Fd) {
// Open a file. // Open a file.
let file_fd = let file_fd =
wasi::path_open(dir_fd, 0, "file", wasi::OFLAGS_CREAT, 0, 0, 0).expect("opening a file"); wasi::path_open(dir_fd, 0, "file", wasi::OFLAGS_CREAT, 0, 0, 0).expect("opening a file");
// Now try to open a file underneath it as if it were a directory. // Now try to open a file underneath it as if it were a directory.
assert_eq!( assert_errno!(
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,
"errno should be ERRNO_NOTDIR"
); );
wasi::fd_close(file_fd).expect("closing a file"); wasi::fd_close(file_fd).expect("closing a file");
} }

View File

@@ -1,21 +1,15 @@
use std::{env, process}; use std::{env, process};
use wasi_tests::{open_scratch_directory}; use wasi_tests::{assert_errno, open_scratch_directory};
unsafe fn test_path_open_missing(dir_fd: wasi::Fd) { unsafe fn test_path_open_missing(dir_fd: wasi::Fd) {
assert_eq!( assert_errno!(
wasi::path_open( wasi::path_open(
dir_fd, dir_fd, 0, "file", 0, // not passing O_CREAT here
0, 0, 0, 0,
"file",
0, // not passing O_CREAT here
0,
0,
0,
) )
.expect_err("trying to open a file that doesn't exist") .expect_err("trying to open a file that doesn't exist")
.raw_error(), .raw_error(),
wasi::ERRNO_NOENT, wasi::ERRNO_NOENT
"errno should be ERRNO_NOENT"
); );
} }

View File

@@ -1,6 +1,5 @@
use std::{env, process}; use std::{env, process};
use wasi_tests::open_scratch_directory; use wasi_tests::{assert_errno, create_file, drop_rights, fd_get_rights, open_scratch_directory};
use wasi_tests::{create_file, drop_rights, fd_get_rights};
const TEST_FILENAME: &'static str = "file"; const TEST_FILENAME: &'static str = "file";
@@ -27,12 +26,11 @@ unsafe fn try_read_file(dir_fd: wasi::Fd) {
}; };
// Since we no longer have the right to fd_read, trying to read a file // Since we no longer have the right to fd_read, trying to read a file
// should be an error. // should be an error.
assert_eq!( assert_errno!(
wasi::fd_read(fd, &[iovec]) wasi::fd_read(fd, &[iovec])
.expect_err("reading bytes from file should fail") .expect_err("reading bytes from file should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTCAPABLE, wasi::ERRNO_NOTCAPABLE
"the errno should be ENOTCAPABLE"
); );
} }

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::{create_file, open_scratch_directory}; use wasi_tests::{assert_errno, create_file, open_scratch_directory};
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
@@ -11,12 +11,11 @@ unsafe fn test_path_rename(dir_fd: wasi::Fd) {
wasi::path_rename(dir_fd, "source", dir_fd, "target").expect("renaming a directory"); wasi::path_rename(dir_fd, "source", dir_fd, "target").expect("renaming a directory");
// Check that source directory doesn't exist anymore // Check that source directory doesn't exist anymore
assert_eq!( assert_errno!(
wasi::path_open(dir_fd, 0, "source", wasi::OFLAGS_DIRECTORY, 0, 0, 0) wasi::path_open(dir_fd, 0, "source", wasi::OFLAGS_DIRECTORY, 0, 0, 0)
.expect_err("opening a nonexistent path as a directory should fail") .expect_err("opening a nonexistent path as a directory should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_NOENT, wasi::ERRNO_NOENT
"errno should be ERRNO_NOENT"
); );
// Check that target directory exists // Check that target directory exists
@@ -37,12 +36,11 @@ unsafe fn test_path_rename(dir_fd: wasi::Fd) {
wasi::path_rename(dir_fd, "source", dir_fd, "target").expect("renaming a directory"); wasi::path_rename(dir_fd, "source", dir_fd, "target").expect("renaming a directory");
// Check that source directory doesn't exist anymore // Check that source directory doesn't exist anymore
assert_eq!( assert_errno!(
wasi::path_open(dir_fd, 0, "source", wasi::OFLAGS_DIRECTORY, 0, 0, 0) wasi::path_open(dir_fd, 0, "source", wasi::OFLAGS_DIRECTORY, 0, 0, 0)
.expect_err("opening a nonexistent path as a directory") .expect_err("opening a nonexistent path as a directory")
.raw_error(), .raw_error(),
wasi::ERRNO_NOENT, wasi::ERRNO_NOENT
"errno should be ERRNO_NOENT"
); );
// Check that target directory exists // Check that target directory exists
@@ -62,21 +60,19 @@ unsafe fn test_path_rename(dir_fd: wasi::Fd) {
wasi::path_create_directory(dir_fd, "target").expect("creating a directory"); wasi::path_create_directory(dir_fd, "target").expect("creating a directory");
create_file(dir_fd, "target/file"); create_file(dir_fd, "target/file");
assert_eq!( assert_errno!(
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, wasi::ERRNO_NOTEMPTY
"errno should be ERRNO_NOTEMPTY"
); );
// Try renaming dir to a file // Try renaming dir to a file
assert_eq!( assert_errno!(
wasi::path_rename(dir_fd, "source", dir_fd, "target/file") wasi::path_rename(dir_fd, "source", dir_fd, "target/file")
.expect_err("renaming a directory to a file") .expect_err("renaming a directory to a file")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTDIR, wasi::ERRNO_NOTDIR
"errno should be ERRNO_NOTDIR"
); );
wasi::path_unlink_file(dir_fd, "target/file").expect("removing a file"); wasi::path_unlink_file(dir_fd, "target/file").expect("removing a file");
@@ -88,12 +84,11 @@ unsafe fn test_path_rename(dir_fd: wasi::Fd) {
wasi::path_rename(dir_fd, "source", dir_fd, "target").expect("renaming a file"); wasi::path_rename(dir_fd, "source", dir_fd, "target").expect("renaming a file");
// Check that source file doesn't exist anymore // Check that source file doesn't exist anymore
assert_eq!( assert_errno!(
wasi::path_open(dir_fd, 0, "source", 0, 0, 0, 0) wasi::path_open(dir_fd, 0, "source", 0, 0, 0, 0)
.expect_err("opening a nonexistent path should fail") .expect_err("opening a nonexistent path should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_NOENT, wasi::ERRNO_NOENT
"errno should be ERRNO_NOENT"
); );
// Check that target file exists // Check that target file exists
@@ -115,12 +110,11 @@ unsafe fn test_path_rename(dir_fd: wasi::Fd) {
.expect("renaming file to another existing file"); .expect("renaming file to another existing file");
// Check that source file doesn't exist anymore // Check that source file doesn't exist anymore
assert_eq!( assert_errno!(
wasi::path_open(dir_fd, 0, "source", 0, 0, 0, 0) wasi::path_open(dir_fd, 0, "source", 0, 0, 0, 0)
.expect_err("opening a nonexistent path") .expect_err("opening a nonexistent path")
.raw_error(), .raw_error(),
wasi::ERRNO_NOENT, wasi::ERRNO_NOENT
"errno should be ERRNO_NOENT"
); );
// Check that target file exists // Check that target file exists
@@ -139,12 +133,11 @@ unsafe fn test_path_rename(dir_fd: wasi::Fd) {
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");
assert_eq!( 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 to existing directory should fail") .expect_err("renaming a file to existing directory should fail")
.raw_error(), .raw_error(),
wasi::ERRNO_ISDIR, wasi::ERRNO_ISDIR
"errno should be ERRNO_ISDIR"
); );
wasi::path_remove_directory(dir_fd, "target").expect("removing a directory"); wasi::path_remove_directory(dir_fd, "target").expect("removing a directory");

View File

@@ -1,5 +1,5 @@
use std::{env, process}; 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_rename_trailing_slashes(dir_fd: wasi::Fd) { unsafe fn test_path_rename_trailing_slashes(dir_fd: wasi::Fd) {
// Test renaming a file with a trailing slash in the name. // Test renaming a file with a trailing slash in the name.
@@ -9,26 +9,23 @@ unsafe fn test_path_rename_trailing_slashes(dir_fd: wasi::Fd) {
.expect("no trailing slashes rename works"); .expect("no trailing slashes rename works");
wasi::path_rename(dir_fd, "target", dir_fd, "source").expect("rename it back to source"); wasi::path_rename(dir_fd, "target", dir_fd, "source").expect("rename it back to source");
assert_eq!( 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 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,
"errno should be ERRNO_NOTDIR"
); );
assert_eq!( 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,
"errno should be ERRNO_NOTDIR"
); );
assert_eq!( 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,
"errno should be 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

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

@@ -1,6 +1,6 @@
use more_asserts::assert_gt; use more_asserts::assert_gt;
use std::{env, mem::MaybeUninit, process}; use std::{env, mem::MaybeUninit, process};
use wasi_tests::open_scratch_directory; use wasi_tests::{assert_errno, open_scratch_directory};
const CLOCK_ID: wasi::Userdata = 0x0123_45678; const CLOCK_ID: wasi::Userdata = 0x0123_45678;
@@ -17,12 +17,11 @@ unsafe fn poll_oneoff_impl(r#in: &[wasi::Subscription]) -> Result<Vec<wasi::Even
unsafe fn test_empty_poll() { unsafe fn test_empty_poll() {
let r#in = []; let r#in = [];
let mut out: Vec<wasi::Event> = Vec::new(); let mut out: Vec<wasi::Event> = Vec::new();
let error = wasi::poll_oneoff(r#in.as_ptr(), out.as_mut_ptr(), r#in.len()) assert_errno!(
.expect_err("empty poll_oneoff should fail"); wasi::poll_oneoff(r#in.as_ptr(), out.as_mut_ptr(), r#in.len())
assert_eq!( .expect_err("empty poll_oneoff should fail")
error.raw_error(), .raw_error(),
wasi::ERRNO_INVAL, wasi::ERRNO_INVAL,
"error should be EINVAL"
); );
} }
@@ -43,11 +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_eq!( assert_errno!(event.error, wasi::ERRNO_SUCCESS,);
event.error,
wasi::ERRNO_SUCCESS,
"the event.error should be set to ESUCCESS"
);
assert_eq!( assert_eq!(
event.r#type, event.r#type,
wasi::EVENTTYPE_CLOCK, wasi::EVENTTYPE_CLOCK,
@@ -89,11 +84,7 @@ unsafe fn test_fd_readwrite(fd: wasi::Fd, error_code: wasi::Errno) {
out[0].userdata, 1, out[0].userdata, 1,
"the event.userdata should contain fd userdata specified by the user" "the event.userdata should contain fd userdata specified by the user"
); );
assert_eq!( assert_errno!(out[0].error, error_code);
out[0].error, error_code,
"the event.error should be set to {}",
error_code
);
assert_eq!( assert_eq!(
out[0].r#type, out[0].r#type,
wasi::EVENTTYPE_FD_READ, wasi::EVENTTYPE_FD_READ,
@@ -103,11 +94,7 @@ unsafe fn test_fd_readwrite(fd: wasi::Fd, error_code: wasi::Errno) {
out[1].userdata, 2, out[1].userdata, 2,
"the event.userdata should contain fd userdata specified by the user" "the event.userdata should contain fd userdata specified by the user"
); );
assert_eq!( assert_errno!(out[1].error, error_code);
out[1].error, error_code,
"the event.error should be set to {}",
error_code
);
assert_eq!( assert_eq!(
out[1].r#type, out[1].r#type,
wasi::EVENTTYPE_FD_WRITE, wasi::EVENTTYPE_FD_WRITE,

View File

@@ -1,5 +1,5 @@
use std::mem::MaybeUninit; use std::mem::MaybeUninit;
use wasi_tests::{STDERR_FD, STDIN_FD, STDOUT_FD}; use wasi_tests::{assert_errno, STDERR_FD, STDIN_FD, STDOUT_FD};
const CLOCK_ID: wasi::Userdata = 0x0123_45678; const CLOCK_ID: wasi::Userdata = 0x0123_45678;
@@ -45,11 +45,7 @@ unsafe fn test_stdin_read() {
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_eq!( assert_errno!(event.error, wasi::ERRNO_SUCCESS);
event.error,
wasi::ERRNO_SUCCESS,
"the event.error should be set to ESUCCESS"
);
assert_eq!( assert_eq!(
event.r#type, event.r#type,
wasi::EVENTTYPE_CLOCK, wasi::EVENTTYPE_CLOCK,
@@ -94,11 +90,7 @@ unsafe fn test_stdout_stderr_write() {
out[0].userdata, 1, out[0].userdata, 1,
"the event.userdata should contain fd userdata specified by the user" "the event.userdata should contain fd userdata specified by the user"
); );
assert_eq!( assert_errno!(out[0].error, wasi::ERRNO_SUCCESS);
out[0].error,
wasi::ERRNO_SUCCESS,
"the event.error should be set to ERRNO_SUCCESS",
);
assert_eq!( assert_eq!(
out[0].r#type, out[0].r#type,
wasi::EVENTTYPE_FD_WRITE, wasi::EVENTTYPE_FD_WRITE,
@@ -108,11 +100,7 @@ unsafe fn test_stdout_stderr_write() {
out[1].userdata, 2, out[1].userdata, 2,
"the event.userdata should contain fd userdata specified by the user" "the event.userdata should contain fd userdata specified by the user"
); );
assert_eq!( assert_errno!(out[1].error, wasi::ERRNO_SUCCESS);
out[1].error,
wasi::ERRNO_SUCCESS,
"the event.error should be set to ERRNO_SUCCESS",
);
assert_eq!( assert_eq!(
out[1].r#type, out[1].r#type,
wasi::EVENTTYPE_FD_WRITE, wasi::EVENTTYPE_FD_WRITE,

View File

@@ -1,5 +1,5 @@
use std::{env, process}; 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_readlink(dir_fd: wasi::Fd) { unsafe fn test_readlink(dir_fd: wasi::Fd) {
// Create a file in the scratch directory. // Create a file in the scratch directory.
@@ -25,11 +25,7 @@ unsafe fn test_readlink(dir_fd: wasi::Fd) {
let err = wasi::path_readlink(dir_fd, "symlink", buf.as_mut_ptr(), buf.len()) let err = wasi::path_readlink(dir_fd, "symlink", buf.as_mut_ptr(), buf.len())
.err() .err()
.expect("readlink with too-small buffer should fail"); .expect("readlink with too-small buffer should fail");
assert_eq!( assert_errno!(err.raw_error(), wasi::ERRNO_RANGE);
err.raw_error(),
wasi::ERRNO_RANGE,
"readlink with too-small buffer should give ERANGE"
);
// Clean up. // Clean up.
wasi::path_unlink_file(dir_fd, "target").expect("removing a file"); wasi::path_unlink_file(dir_fd, "target").expect("removing a file");

View File

@@ -1,5 +1,5 @@
use std::{env, process}; 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_remove_directory_trailing_slashes(dir_fd: wasi::Fd) { unsafe fn test_remove_directory_trailing_slashes(dir_fd: wasi::Fd) {
// Create a directory in the scratch directory. // Create a directory in the scratch directory.
@@ -21,22 +21,20 @@ unsafe fn test_remove_directory_trailing_slashes(dir_fd: wasi::Fd) {
create_file(dir_fd, "file"); create_file(dir_fd, "file");
// Test that removing it with no trailing slash fails. // Test that removing it with no trailing slash fails.
assert_eq!( assert_errno!(
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,
"errno should be ERRNO_NOTDIR"
); );
// Test that removing it with a trailing slash fails. // Test that removing it with a trailing slash fails.
// XXX windows behavior here is NOENT instead of NOTDIR // XXX windows behavior here is NOENT instead of NOTDIR
assert_eq!( assert_errno!(
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,
"errno should be 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

@@ -1,5 +1,5 @@
use std::{env, process}; use std::{env, process};
use wasi_tests::open_scratch_directory; use wasi_tests::{assert_errno, open_scratch_directory};
unsafe fn test_remove_nonempty_directory(dir_fd: wasi::Fd) { unsafe fn test_remove_nonempty_directory(dir_fd: wasi::Fd) {
// Create a directory in the scratch directory. // Create a directory in the scratch directory.
@@ -9,12 +9,11 @@ unsafe fn test_remove_nonempty_directory(dir_fd: wasi::Fd) {
wasi::path_create_directory(dir_fd, "dir/nested").expect("creating a subdirectory"); wasi::path_create_directory(dir_fd, "dir/nested").expect("creating a subdirectory");
// Test that attempting to unlink the first directory returns the expected error code. // Test that attempting to unlink the first directory returns the expected error code.
assert_eq!( assert_errno!(
wasi::path_remove_directory(dir_fd, "dir") wasi::path_remove_directory(dir_fd, "dir")
.expect_err("remove_directory on a directory should return ENOTEMPTY") .expect_err("remove_directory on a directory should return ENOTEMPTY")
.raw_error(), .raw_error(),
wasi::ERRNO_NOTEMPTY, wasi::ERRNO_NOTEMPTY
"errno should be ERRNO_NOTEMPTY",
); );
// Removing the directories. // Removing the directories.

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::open_scratch_directory; use wasi_tests::{assert_errno, open_scratch_directory};
unsafe fn test_renumber(dir_fd: wasi::Fd) { unsafe fn test_renumber(dir_fd: wasi::Fd) {
let pre_fd: wasi::Fd = (libc::STDERR_FILENO + 1) as wasi::Fd; let pre_fd: wasi::Fd = (libc::STDERR_FILENO + 1) as wasi::Fd;
@@ -49,12 +49,11 @@ unsafe fn test_renumber(dir_fd: wasi::Fd) {
wasi::fd_renumber(fd_from, fd_to).expect("renumbering two descriptors"); wasi::fd_renumber(fd_from, fd_to).expect("renumbering two descriptors");
// Ensure that fd_from is closed // Ensure that fd_from is closed
assert_eq!( assert_errno!(
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,
"errno should be ERRNO_BADF"
); );
// Ensure that fd_to is still open. // Ensure that fd_to is still open.

View File

@@ -3,7 +3,7 @@ use std::{env, process};
use wasi_tests::open_scratch_directory; use wasi_tests::open_scratch_directory;
unsafe fn test_path_filestat(dir_fd: wasi::Fd) { unsafe fn test_path_filestat(dir_fd: wasi::Fd) {
let mut fdstat = wasi::fd_fdstat_get(dir_fd).expect("fd_fdstat_get"); let fdstat = wasi::fd_fdstat_get(dir_fd).expect("fd_fdstat_get");
assert_ne!( assert_ne!(
fdstat.fs_rights_base & wasi::RIGHTS_PATH_FILESTAT_GET, fdstat.fs_rights_base & wasi::RIGHTS_PATH_FILESTAT_GET,
0, 0,

View File

@@ -1,17 +1,16 @@
use std::{env, process}; use std::{env, process};
use wasi_tests::open_scratch_directory; use wasi_tests::{assert_errno, open_scratch_directory};
unsafe fn test_symlink_loop(dir_fd: wasi::Fd) { unsafe fn test_symlink_loop(dir_fd: wasi::Fd) {
// Create a self-referencing symlink. // Create a self-referencing symlink.
wasi::path_symlink("symlink", dir_fd, "symlink").expect("creating a symlink"); wasi::path_symlink("symlink", dir_fd, "symlink").expect("creating a symlink");
// Try to open it. // Try to open it.
assert_eq!( assert_errno!(
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,
"errno should be ERRNO_LOOP",
); );
// Clean up. // Clean up.

View File

@@ -1,5 +1,5 @@
use std::{env, process}; 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_truncation_rights(dir_fd: wasi::Fd) { unsafe fn test_truncation_rights(dir_fd: wasi::Fd) {
// Create a file in the scratch directory. // Create a file in the scratch directory.
@@ -64,12 +64,11 @@ unsafe fn test_truncation_rights(dir_fd: wasi::Fd) {
// Test that we can't truncate the file without the // Test that we can't truncate the file without the
// wasi_unstable::RIGHT_PATH_FILESTAT_SET_SIZE right. // wasi_unstable::RIGHT_PATH_FILESTAT_SET_SIZE right.
assert_eq!( assert_errno!(
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,
"errno should be ERRNO_NOTCAPABLE",
); );
} }

View File

@@ -1,5 +1,5 @@
use std::{env, process}; 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_unlink_file_trailing_slashes(dir_fd: wasi::Fd) { unsafe fn test_unlink_file_trailing_slashes(dir_fd: wasi::Fd) {
// Create a directory in the scratch directory. // Create a directory in the scratch directory.
@@ -7,22 +7,20 @@ unsafe fn test_unlink_file_trailing_slashes(dir_fd: wasi::Fd) {
// Test that unlinking it fails. // Test that unlinking it fails.
// XXX windows errno here is ACCES // XXX windows errno here is ACCES
assert_eq!( assert_errno!(
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,
"errno should be ERRNO_ISDIR"
); );
// Test that unlinking it with a trailing flash fails. // Test that unlinking it with a trailing flash fails.
// XXX windows errno here is ACCES // XXX windows errno here is ACCES
assert_eq!( assert_errno!(
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,
"errno should be ERRNO_ISDIR"
); );
// Clean up. // Clean up.
@@ -33,12 +31,11 @@ unsafe fn test_unlink_file_trailing_slashes(dir_fd: wasi::Fd) {
// Test that unlinking it with a trailing flash fails. // Test that unlinking it with a trailing flash fails.
// XXX windows errno here is NOENT // XXX windows errno here is NOENT
assert_eq!( assert_errno!(
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,
"errno should be ERRNO_NOTDIR"
); );
// Test that unlinking it with no trailing flash succeeds. // Test that unlinking it with no trailing flash succeeds.