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