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:
parent
e10d74a3d3
commit
99f4a710f1
9 changed files with 115 additions and 46 deletions
|
@ -72,6 +72,9 @@ if (import.meta.main) {
|
|||
const prelude = await Deno.readTextFile(path.resolve(outdir, basename));
|
||||
const options = JSON.parse(prelude);
|
||||
|
||||
await Deno.mkdir(`${testdir}/scratch`);
|
||||
|
||||
try {
|
||||
const process = await Deno.run({
|
||||
cwd: testdir,
|
||||
cmd: [
|
||||
|
@ -116,10 +119,21 @@ if (import.meta.main) {
|
|||
|
||||
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();
|
||||
assertEquals(status.code, options.exitCode ? +options.exitCode : 0);
|
||||
|
||||
process.close();
|
||||
} catch (err) {
|
||||
throw err;
|
||||
} finally {
|
||||
await Deno.remove(`${testdir}/scratch`, { recursive: true });
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
1
std/wasi/testdata/fixture/directory/file
vendored
Normal file
1
std/wasi/testdata/fixture/directory/file
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
directory/file
|
1
std/wasi/testdata/fixture/directory/symlink_to_file
vendored
Symbolic link
1
std/wasi/testdata/fixture/directory/symlink_to_file
vendored
Symbolic link
|
@ -0,0 +1 @@
|
|||
file
|
1
std/wasi/testdata/fixture/file
vendored
Normal file
1
std/wasi/testdata/fixture/file
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
file
|
1
std/wasi/testdata/fixture/symlink_to_directory
vendored
Symbolic link
1
std/wasi/testdata/fixture/symlink_to_directory
vendored
Symbolic link
|
@ -0,0 +1 @@
|
|||
directory
|
1
std/wasi/testdata/fixture/symlink_to_file
vendored
Symbolic link
1
std/wasi/testdata/fixture/symlink_to_file
vendored
Symbolic link
|
@ -0,0 +1 @@
|
|||
file
|
28
std/wasi/testdata/std_fs_metadata.rs
vendored
Normal file
28
std/wasi/testdata/std_fs_metadata.rs
vendored
Normal 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
17
std/wasi/testdata/std_fs_read.rs
vendored
Normal 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
5
std/wasi/testdata/std_fs_write.rs
vendored
Normal file
|
@ -0,0 +1,5 @@
|
|||
// { "preopens": { "/scratch": "scratch" }, "files": { "scratch/file": "file" } }
|
||||
|
||||
fn main() {
|
||||
assert!(std::fs::write("/scratch/file", b"file").is_ok())
|
||||
}
|
Loading…
Reference in a new issue