diff --git a/Cargo.toml b/Cargo.toml index 61910f85c85..9baaf349685 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -15,7 +15,7 @@ version.workspace = true wasmer = { version = "=4.1.1", path = "lib/api", default-features = false } wasmer-compiler = { version = "=4.1.1", path = "lib/compiler", features = [ "compiler", -], optional=true } +], optional = true } wasmer-compiler-cranelift = { version = "=4.1.1", path = "lib/compiler-cranelift", optional = true } wasmer-compiler-singlepass = { version = "=4.1.1", path = "lib/compiler-singlepass", optional = true } wasmer-compiler-llvm = { version = "=4.1.1", path = "lib/compiler-llvm", optional = true } @@ -27,7 +27,11 @@ wasmer-cache = { version = "=4.1.1", path = "lib/cache", optional = true } wasmer-types = { version = "=4.1.1", path = "lib/types" } wasmer-middlewares = { version = "=4.1.1", path = "lib/middlewares", optional = true } cfg-if = "1.0" -tokio = { version = "1", features = [ "rt", "rt-multi-thread", "macros" ], optional = true } +tokio = { version = "1", features = [ + "rt", + "rt-multi-thread", + "macros", +], optional = true } [workspace] members = [ @@ -66,9 +70,7 @@ members = [ "tests/lib/wast", "tests/wasi-wast", ] -exclude = [ - "lib/wasi-web", -] +exclude = ["lib/wasi-web"] resolver = "2" [workspace.package] @@ -92,7 +94,8 @@ glob = "0.3" rustc_version = "0.4" [dev-dependencies] -wasmer = { version = "=4.1.1", path = "lib/api", default-features = false, features = [] } +wasmer = { version = "=4.1.1", path = "lib/api", default-features = false, features = [ +] } anyhow = "1.0" criterion = { version = "0.5", default-features = false } lazy_static = "1.4" diff --git a/tests/integration/cli/tests/snapshot.rs b/tests/integration/cli/tests/snapshot.rs index 6beddfa5811..b231512ed74 100644 --- a/tests/integration/cli/tests/snapshot.rs +++ b/tests/integration/cli/tests/snapshot.rs @@ -1268,3 +1268,12 @@ fn test_snapshot_quickjs() { .run_wasm(include_bytes!("./wasm/qjs.wasm")); assert_json_snapshot!(snapshot); } + +#[cfg_attr(any(target_env = "musl", target_os = "windows"), ignore)] +#[test] +fn test_snapshot_fs_rename() { + let snapshot = TestBuilder::new() + .with_name(function!()) + .run_wasm(include_bytes!("./wasm/fs-rename.wasm")); + assert_json_snapshot!(snapshot); +} diff --git a/tests/integration/cli/tests/snapshots/snapshot__snapshot_fs_rename.snap b/tests/integration/cli/tests/snapshots/snapshot__snapshot_fs_rename.snap new file mode 100644 index 00000000000..f50db203957 --- /dev/null +++ b/tests/integration/cli/tests/snapshots/snapshot__snapshot_fs_rename.snap @@ -0,0 +1,21 @@ +--- +source: tests/integration/cli/tests/snapshot.rs +expression: snapshot +--- +{ + "spec": { + "name": "snapshot::test_snapshot_fs_rename", + "use_packages": [], + "include_webcs": [], + "cli_args": [], + "enable_threads": true, + "enable_network": false + }, + "result": { + "Success": { + "stdout": "/test-dir/a:a\n/test-dir/b:a\n/test-dir/c:c\n/test-dir/d:c\n", + "stderr": "", + "exit_code": 0 + } + } +} diff --git a/tests/integration/cli/tests/wasm/fs-rename.wasm b/tests/integration/cli/tests/wasm/fs-rename.wasm new file mode 100644 index 00000000000..a4c99b58dfb Binary files /dev/null and b/tests/integration/cli/tests/wasm/fs-rename.wasm differ diff --git a/tests/rust-wasi-tests/Cargo.lock b/tests/rust-wasi-tests/Cargo.lock new file mode 100644 index 00000000000..59c7e8f295d --- /dev/null +++ b/tests/rust-wasi-tests/Cargo.lock @@ -0,0 +1,16 @@ +# This file is automatically @generated by Cargo. +# It is not intended for manual editing. +version = 3 + +[[package]] +name = "rust-wasi-tests" +version = "0.1.0" +dependencies = [ + "wasi", +] + +[[package]] +name = "wasi" +version = "0.11.0+wasi-snapshot-preview1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" diff --git a/tests/rust-wasi-tests/Cargo.toml b/tests/rust-wasi-tests/Cargo.toml new file mode 100644 index 00000000000..45731f7731f --- /dev/null +++ b/tests/rust-wasi-tests/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "rust-wasi-tests" +version = "0.1.0" +edition = "2021" + +[workspace] + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +wasi = "0.11.0" diff --git a/tests/rust-wasi-tests/src/bin/fs-rename.rs b/tests/rust-wasi-tests/src/bin/fs-rename.rs new file mode 100644 index 00000000000..840e2f87f33 --- /dev/null +++ b/tests/rust-wasi-tests/src/bin/fs-rename.rs @@ -0,0 +1,34 @@ +use std::fs::{self, File}; +use std::os::fd::AsRawFd; +use std::path::Path; + +fn print_contents(path: impl AsRef + Copy) { + let contents = fs::read_to_string(path).unwrap(); + println!( + "{}:{contents}", + path.as_ref().to_string_lossy().into_owned() + ); +} + +fn main() { + unsafe { + fs::create_dir("/test-dir").unwrap(); + + fs::write("/test-dir/a", "a").unwrap(); + print_contents("/test-dir/a"); + + let dir = File::open("/test-dir").unwrap(); + let dir_raw_fd = dir.as_raw_fd() as u32; + + wasi::path_rename(dir_raw_fd, "a", dir_raw_fd, "b").unwrap(); + + print_contents("/test-dir/b"); + + fs::write("/test-dir/c", "c").unwrap(); + print_contents("/test-dir/c"); + + fs::rename("/test-dir/c", "/test-dir/d").unwrap(); + + print_contents("/test-dir/d"); + } +} diff --git a/tests/rust-wasi-tests/src/lib.rs b/tests/rust-wasi-tests/src/lib.rs new file mode 100644 index 00000000000..8b137891791 --- /dev/null +++ b/tests/rust-wasi-tests/src/lib.rs @@ -0,0 +1 @@ +