1
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2024-12-03 17:08:35 -05:00

test(std/wasi): add read, write and metadata tests (#6494)

This commit is contained in:
Casper Beyer 2020-06-27 03:36:46 +08:00 committed by GitHub
parent e10d74a3d3
commit 99f4a710f1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
9 changed files with 115 additions and 46 deletions

View file

@ -72,6 +72,9 @@ if (import.meta.main) {
const prelude = await Deno.readTextFile(path.resolve(outdir, basename)); const prelude = await Deno.readTextFile(path.resolve(outdir, basename));
const options = JSON.parse(prelude); const options = JSON.parse(prelude);
await Deno.mkdir(`${testdir}/scratch`);
try {
const process = await Deno.run({ const process = await Deno.run({
cwd: testdir, cwd: testdir,
cmd: [ cmd: [
@ -116,10 +119,21 @@ if (import.meta.main) {
process.stderr.close(); process.stderr.close();
if (options.files) {
for (const [key, value] of Object.entries(options.files)) {
assertEquals(value, await Deno.readTextFile(`${testdir}/${key}`));
}
}
const status = await process.status(); const status = await process.status();
assertEquals(status.code, options.exitCode ? +options.exitCode : 0); assertEquals(status.code, options.exitCode ? +options.exitCode : 0);
process.close(); process.close();
} catch (err) {
throw err;
} finally {
await Deno.remove(`${testdir}/scratch`, { recursive: true });
}
}); });
} }
} }

View file

@ -0,0 +1 @@
directory/file

View file

@ -0,0 +1 @@
file

1
std/wasi/testdata/fixture/file vendored Normal file
View file

@ -0,0 +1 @@
file

View file

@ -0,0 +1 @@
directory

View file

@ -0,0 +1 @@
file

28
std/wasi/testdata/std_fs_metadata.rs vendored Normal file
View file

@ -0,0 +1,28 @@
// { "preopens": { "/fixture": "fixture" } }
fn main() {
let metadata = std::fs::metadata("/fixture/directory").unwrap();
assert!(metadata.is_dir());
assert!(metadata.len() > 0);
let metadata = std::fs::metadata("/fixture/symlink_to_directory").unwrap();
assert!(metadata.is_dir());
assert!(metadata.len() > 0);
let metadata = std::fs::metadata("/fixture/file").unwrap();
assert!(metadata.is_file());
assert!(metadata.len() > 0);
let metadata = std::fs::metadata("/fixture/symlink_to_file").unwrap();
assert!(metadata.is_file());
assert!(metadata.len() > 0);
let metadata = std::fs::metadata("/fixture/directory/file").unwrap();
assert!(metadata.is_file());
assert!(metadata.len() > 0);
let metadata =
std::fs::metadata("/fixture/directory/symlink_to_file").unwrap();
assert!(metadata.is_file());
assert!(metadata.len() > 0);
}

17
std/wasi/testdata/std_fs_read.rs vendored Normal file
View file

@ -0,0 +1,17 @@
// { "preopens": { "/fixture": "fixture" } }
fn main() {
assert_eq!(std::fs::read("/fixture/file").unwrap(), b"file\n");
assert_eq!(
std::fs::read("/fixture/symlink_to_file").unwrap(),
b"file\n"
);
assert_eq!(
std::fs::read("/fixture/directory/file").unwrap(),
b"directory/file\n"
);
assert_eq!(
std::fs::read("/fixture/directory/symlink_to_file").unwrap(),
b"directory/file\n"
);
}

5
std/wasi/testdata/std_fs_write.rs vendored Normal file
View file

@ -0,0 +1,5 @@
// { "preopens": { "/scratch": "scratch" }, "files": { "scratch/file": "file" } }
fn main() {
assert!(std::fs::write("/scratch/file", b"file").is_ok())
}