Skip to content

Commit

Permalink
Squashed 'tests/wasi-wast/' changes from f575fff42..6035e0a8f
Browse files Browse the repository at this point in the history
6035e0a8f Merge pull request #1 from chenyukang/add-path-rename-tests
6c42d0308 add more info in output
178691a41 add path_rename testcase

git-subtree-dir: tests/wasi-wast
git-subtree-split: 6035e0a8f9f6fa668d7618ab03efae9d34da820c
  • Loading branch information
chenyukang committed Jun 23, 2021
1 parent 0948269 commit 640813c
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 3 deletions.
Binary file modified wasi/snapshot1/path_rename.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion wasi/snapshot1/path_rename.wast
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
(wasi_test "path_rename.wasm"
(temp_dirs "temp")
(assert_return (i64.const 0))
(assert_stdout "The original file does not still exist!\nFound item: path_renamed_file.txt\n柴犬\n")
(assert_stdout "The original file does not still exist!\nFound item: path_renamed_file.txt\n柴犬\nrun_with_sub_dir: The original file does not still exist!\nrun_with_different_sub_dirs: The original file does not still exist!\n")
)
94 changes: 93 additions & 1 deletion wasi/tests/path_rename.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use std::fs;
use std::io::{Read, Write};
use std::path::PathBuf;

fn main() {
fn run_with_toplevel_dir() {
#[cfg(not(target_os = "wasi"))]
let mut base = PathBuf::from("test_fs");
#[cfg(target_os = "wasi")]
Expand Down Expand Up @@ -73,3 +73,95 @@ fn main() {
println!("{}", test_str);
std::fs::remove_file(file_to_rename_to).unwrap();
}

fn run_with_sub_dir() {
#[cfg(not(target_os = "wasi"))]
let base = PathBuf::from("test_fs");
#[cfg(target_os = "wasi")]
let mut base = PathBuf::from("temp");

//make a sub-directory
fs::create_dir(base.join("sub"));

let file_to_create = base.join("sub/path_rename_file.txt");
let file_to_rename_to = base.join("sub/path_renamed_file.txt");

{
let mut f = std::fs::OpenOptions::new()
.create_new(true)
.write(true)
.open(&file_to_create)
.unwrap();

let string = "Hello world";
let bytes: Vec<u8> = string.bytes().collect();
f.write_all(&bytes[..]).unwrap();
}

std::fs::rename(&file_to_create, &file_to_rename_to).unwrap();
let mut file = fs::File::open(&file_to_rename_to).expect("Could not open file");
if file_to_create.exists() {
println!("run_with_sub_dir: The original file still exists!");
return;
} else {
println!("run_with_sub_dir: The original file does not still exist!");
}

if !file_to_rename_to.exists() {
println!("run_with_sub_dir: The moved file does not exist!");
return;
}
fs::remove_dir_all(base.join("sub"));
}

fn run_with_different_sub_dirs() {
#[cfg(not(target_os = "wasi"))]
let base = PathBuf::from("test_fs");
#[cfg(target_os = "wasi")]
let mut base = PathBuf::from("temp");

//make sub-directories
fs::create_dir(base.join("a"));
fs::create_dir(base.join("a/b"));
fs::create_dir(base.join("c"));
fs::create_dir(base.join("c/d"));
fs::create_dir(base.join("c/d/e"));

let file_to_create = base.join("a/b/path_rename_file.txt");
let file_to_rename_to = base.join("c/d/e/path_renamed_file.txt");

{
let mut f = std::fs::OpenOptions::new()
.create_new(true)
.write(true)
.open(&file_to_create)
.unwrap();

let string = "Hello world";
let bytes: Vec<u8> = string.bytes().collect();
f.write_all(&bytes[..]).unwrap();
}

std::fs::rename(&file_to_create, &file_to_rename_to).unwrap();
let mut file = fs::File::open(&file_to_rename_to).expect("Could not open file");
if file_to_create.exists() {
println!("run_with_different_sub_dirs: The original file still exists!");
return;
} else {
println!("run_with_different_sub_dirs: The original file does not still exist!");
}

if !file_to_rename_to.exists() {
println!("run_with_different_sub_dirs: The moved file does not exist!");
return;
}

fs::remove_dir_all(base.join("a"));
fs::remove_dir_all(base.join("c"));
}

fn main() {
run_with_toplevel_dir();
run_with_sub_dir();
run_with_different_sub_dirs();
}
Binary file modified wasi/unstable/path_rename.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion wasi/unstable/path_rename.wast
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@
(wasi_test "path_rename.wasm"
(temp_dirs "temp")
(assert_return (i64.const 0))
(assert_stdout "The original file does not still exist!\nFound item: path_renamed_file.txt\n柴犬\n")
(assert_stdout "The original file does not still exist!\nFound item: path_renamed_file.txt\n柴犬\nrun_with_sub_dir: The original file does not still exist!\nrun_with_different_sub_dirs: The original file does not still exist!\n")
)

0 comments on commit 640813c

Please sign in to comment.