Update WASI tests to use wasi crate v0.9.0 (#743)
This commit updates _all_ WASI test programs to use the latest version of the `wasi` crate (`v0.9.0`). While at it, it also unifies asserting error conditions across all test programs.
This commit is contained in:
@@ -1,28 +1,17 @@
|
||||
use std::{env, process};
|
||||
use wasi_old::wasi_unstable;
|
||||
use wasi_tests::open_scratch_directory;
|
||||
use wasi_tests::utils::{cleanup_file, create_file};
|
||||
use wasi_tests::wasi_wrappers::{wasi_path_readlink, wasi_path_symlink};
|
||||
use wasi_tests::{create_file, open_scratch_directory};
|
||||
|
||||
unsafe fn test_readlink(dir_fd: wasi_unstable::Fd) {
|
||||
unsafe fn test_readlink(dir_fd: wasi::Fd) {
|
||||
// Create a file in the scratch directory.
|
||||
create_file(dir_fd, "target");
|
||||
|
||||
// Create a symlink
|
||||
assert!(
|
||||
wasi_path_symlink("target", dir_fd, "symlink").is_ok(),
|
||||
"creating a symlink"
|
||||
);
|
||||
wasi::path_symlink("target", dir_fd, "symlink").expect("creating a symlink");
|
||||
|
||||
// Read link into the buffer
|
||||
let buf = &mut [0u8; 10];
|
||||
let mut bufused: usize = 0;
|
||||
let mut status = wasi_path_readlink(dir_fd, "symlink", buf, &mut bufused);
|
||||
assert_eq!(
|
||||
status,
|
||||
wasi_unstable::raw::__WASI_ESUCCESS,
|
||||
"readlink should succeed"
|
||||
);
|
||||
let mut bufused = wasi::path_readlink(dir_fd, "symlink", buf.as_mut_ptr(), buf.len())
|
||||
.expect("readlink should succeed");
|
||||
assert_eq!(bufused, 6, "should use 6 bytes of the buffer");
|
||||
assert_eq!(&buf[..6], b"target", "buffer should contain 'target'");
|
||||
assert_eq!(
|
||||
@@ -33,19 +22,14 @@ unsafe fn test_readlink(dir_fd: wasi_unstable::Fd) {
|
||||
|
||||
// Read link into smaller buffer than the actual link's length
|
||||
let buf = &mut [0u8; 4];
|
||||
let mut bufused: usize = 0;
|
||||
status = wasi_path_readlink(dir_fd, "symlink", buf, &mut bufused);
|
||||
assert_eq!(
|
||||
status,
|
||||
wasi_unstable::raw::__WASI_ESUCCESS,
|
||||
"readlink should succeed"
|
||||
);
|
||||
bufused = wasi::path_readlink(dir_fd, "symlink", buf.as_mut_ptr(), buf.len())
|
||||
.expect("readlink should succeed");
|
||||
assert_eq!(bufused, 4, "should use all 4 bytes of the buffer");
|
||||
assert_eq!(buf, b"targ", "buffer should contain 'targ'");
|
||||
|
||||
// Clean up.
|
||||
cleanup_file(dir_fd, "target");
|
||||
cleanup_file(dir_fd, "symlink");
|
||||
wasi::path_unlink_file(dir_fd, "target").expect("removing a file");
|
||||
wasi::path_unlink_file(dir_fd, "symlink").expect("removing a file");
|
||||
}
|
||||
|
||||
fn main() {
|
||||
|
||||
Reference in New Issue
Block a user