Skip to content

Commit

Permalink
Merge pull request #4127 from wasmerio/fix/3945-path-rename-test
Browse files Browse the repository at this point in the history
Add regression test for path_rename
  • Loading branch information
theduke authored Aug 7, 2023
2 parents 69d4a78 + 77a1b2f commit 8cf3e13
Show file tree
Hide file tree
Showing 8 changed files with 101 additions and 6 deletions.
15 changes: 9 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand All @@ -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 = [
Expand Down Expand Up @@ -66,9 +70,7 @@ members = [
"tests/lib/wast",
"tests/wasi-wast",
]
exclude = [
"lib/wasi-web",
]
exclude = ["lib/wasi-web"]
resolver = "2"

[workspace.package]
Expand All @@ -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"
Expand Down
9 changes: 9 additions & 0 deletions tests/integration/cli/tests/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Original file line number Diff line number Diff line change
@@ -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
}
}
}
Binary file added tests/integration/cli/tests/wasm/fs-rename.wasm
Binary file not shown.
16 changes: 16 additions & 0 deletions tests/rust-wasi-tests/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions tests/rust-wasi-tests/Cargo.toml
Original file line number Diff line number Diff line change
@@ -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"
34 changes: 34 additions & 0 deletions tests/rust-wasi-tests/src/bin/fs-rename.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
use std::fs::{self, File};
use std::os::fd::AsRawFd;
use std::path::Path;

fn print_contents(path: impl AsRef<Path> + 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");
}
}
1 change: 1 addition & 0 deletions tests/rust-wasi-tests/src/lib.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

0 comments on commit 8cf3e13

Please sign in to comment.