Skip to content

Commit

Permalink
test(wasi): add std file read and write tests (denoland/deno#6671)
Browse files Browse the repository at this point in the history
  • Loading branch information
caspervonb committed Jan 31, 2021
1 parent 014ae05 commit 90cc2cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
16 changes: 16 additions & 0 deletions wasi/testdata/std_fs_file_read.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// { "preopens": { "/fixture": "fixture" } }

use std::io::Read;

fn main() {
let mut file = std::fs::File::open("/fixture/file").unwrap();
let mut buffer = [0; 2];

assert_eq!(file.read(&mut buffer).unwrap(), 2);
assert_eq!(&buffer, b"fi");

assert_eq!(file.read(&mut buffer).unwrap(), 2);
assert_eq!(&buffer, b"le");

assert_eq!(file.read(&mut buffer).unwrap(), 1);
}
9 changes: 9 additions & 0 deletions wasi/testdata/std_fs_file_write.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// { "preopens": { "/scratch": "scratch" }, "files": { "scratch/file": "file" } }

use std::io::Write;

fn main() {
let mut file = std::fs::File::create("/scratch/file").unwrap();
assert_eq!(file.write(b"fi").unwrap(), 2);
assert_eq!(file.write(b"le").unwrap(), 2);
}

0 comments on commit 90cc2cf

Please sign in to comment.