mirror of
https://github.com/denoland/deno.git
synced 2024-11-25 15:29:32 -05:00
test(std/wasi): add wasi-testsuite as a submodule (#7042)
This commit is contained in:
parent
54d336ab20
commit
f7174267e3
30 changed files with 87 additions and 390 deletions
3
.gitmodules
vendored
3
.gitmodules
vendored
|
@ -1,3 +1,6 @@
|
||||||
[submodule "deno_third_party"]
|
[submodule "deno_third_party"]
|
||||||
path = third_party
|
path = third_party
|
||||||
url = https://github.com/denoland/deno_third_party.git
|
url = https://github.com/denoland/deno_third_party.git
|
||||||
|
[submodule "std/wasi/testdata"]
|
||||||
|
path = std/wasi/testdata
|
||||||
|
url = git@github.com:khronosproject/wasi-test-suite.git
|
||||||
|
|
|
@ -1,17 +1,32 @@
|
||||||
/* eslint-disable */
|
/* eslint-disable */
|
||||||
|
|
||||||
import { assert, assertEquals } from "../testing/asserts.ts";
|
import { assert, assertEquals } from "../testing/asserts.ts";
|
||||||
|
import { copy } from "../fs/mod.ts";
|
||||||
import * as path from "../path/mod.ts";
|
import * as path from "../path/mod.ts";
|
||||||
import Context from "./snapshot_preview1.ts";
|
import Context from "./snapshot_preview1.ts";
|
||||||
|
|
||||||
|
const ignore = [
|
||||||
|
"wasi_clock_time_get_realtime.wasm",
|
||||||
|
];
|
||||||
|
|
||||||
|
// TODO(caspervonb) investigate why these tests are failing on windows and fix
|
||||||
|
// them.
|
||||||
|
if (Deno.build.os == "windows") {
|
||||||
|
ignore.push("std_fs_metadata_absolute.wasm");
|
||||||
|
ignore.push("std_fs_metadata_relative.wasm");
|
||||||
|
ignore.push("std_fs_read_dir_absolute.wasm");
|
||||||
|
ignore.push("std_fs_read_dir_relative.wasm");
|
||||||
|
}
|
||||||
|
|
||||||
if (import.meta.main) {
|
if (import.meta.main) {
|
||||||
const options = JSON.parse(Deno.args[0]);
|
const options = JSON.parse(Deno.args[0]);
|
||||||
const binary = await Deno.readFile(Deno.args[1]);
|
const pathname = Deno.args[1];
|
||||||
|
const binary = await Deno.readFile(pathname);
|
||||||
const module = await WebAssembly.compile(binary);
|
const module = await WebAssembly.compile(binary);
|
||||||
|
|
||||||
const context = new Context({
|
const context = new Context({
|
||||||
env: options.env,
|
env: options.env,
|
||||||
args: options.args,
|
args: [pathname].concat(options.args),
|
||||||
preopens: options.preopens,
|
preopens: options.preopens,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -25,58 +40,31 @@ if (import.meta.main) {
|
||||||
} else {
|
} else {
|
||||||
const rootdir = path.dirname(path.fromFileUrl(import.meta.url));
|
const rootdir = path.dirname(path.fromFileUrl(import.meta.url));
|
||||||
const testdir = path.join(rootdir, "testdata");
|
const testdir = path.join(rootdir, "testdata");
|
||||||
const outdir = path.join(testdir, "snapshot_preview1");
|
|
||||||
|
|
||||||
for await (const entry of Deno.readDir(testdir)) {
|
for await (const entry of Deno.readDir(testdir)) {
|
||||||
if (!entry.name.endsWith(".rs")) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
const process = Deno.run({
|
|
||||||
cmd: [
|
|
||||||
"rustc",
|
|
||||||
"--target",
|
|
||||||
"wasm32-wasi",
|
|
||||||
"--out-dir",
|
|
||||||
outdir,
|
|
||||||
path.join(testdir, entry.name),
|
|
||||||
],
|
|
||||||
stdout: "inherit",
|
|
||||||
stderr: "inherit",
|
|
||||||
});
|
|
||||||
|
|
||||||
const status = await process.status();
|
|
||||||
assert(status.success);
|
|
||||||
|
|
||||||
process.close();
|
|
||||||
|
|
||||||
// TODO(caspervonb) allow the prelude to span multiple lines
|
|
||||||
const source = await Deno.readTextFile(path.join(testdir, entry.name));
|
|
||||||
const prelude = source.match(/^\/\/\s*\{.*/);
|
|
||||||
if (prelude) {
|
|
||||||
const basename = entry.name.replace(/.rs$/, ".json");
|
|
||||||
await Deno.writeTextFile(
|
|
||||||
path.join(outdir, basename),
|
|
||||||
prelude[0].slice(2),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for await (const entry of Deno.readDir(outdir)) {
|
|
||||||
if (!entry.name.endsWith(".wasm")) {
|
if (!entry.name.endsWith(".wasm")) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Deno.test(entry.name, async function () {
|
Deno.test({
|
||||||
|
name: entry.name,
|
||||||
|
ignore: ignore.includes(entry.name),
|
||||||
|
fn: async function () {
|
||||||
const basename = entry.name.replace(/\.wasm$/, ".json");
|
const basename = entry.name.replace(/\.wasm$/, ".json");
|
||||||
const prelude = await Deno.readTextFile(path.resolve(outdir, basename));
|
const prelude = await Deno.readTextFile(
|
||||||
|
path.resolve(testdir, basename),
|
||||||
|
);
|
||||||
const options = JSON.parse(prelude);
|
const options = JSON.parse(prelude);
|
||||||
|
|
||||||
await Deno.mkdir(`${testdir}/scratch`);
|
const workdir = await Deno.makeTempDir();
|
||||||
|
await copy(
|
||||||
|
path.join(testdir, "fixtures"),
|
||||||
|
path.join(workdir, "fixtures"),
|
||||||
|
);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const process = await Deno.run({
|
const process = await Deno.run({
|
||||||
cwd: testdir,
|
cwd: workdir,
|
||||||
cmd: [
|
cmd: [
|
||||||
`${Deno.execPath()}`,
|
`${Deno.execPath()}`,
|
||||||
"run",
|
"run",
|
||||||
|
@ -85,7 +73,7 @@ if (import.meta.main) {
|
||||||
"--allow-all",
|
"--allow-all",
|
||||||
import.meta.url,
|
import.meta.url,
|
||||||
prelude,
|
prelude,
|
||||||
path.resolve(outdir, entry.name),
|
path.resolve(testdir, entry.name),
|
||||||
],
|
],
|
||||||
stdin: "piped",
|
stdin: "piped",
|
||||||
stdout: "piped",
|
stdout: "piped",
|
||||||
|
@ -119,12 +107,6 @@ 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);
|
||||||
|
|
||||||
|
@ -132,8 +114,9 @@ if (import.meta.main) {
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
throw err;
|
throw err;
|
||||||
} finally {
|
} finally {
|
||||||
await Deno.remove(`${testdir}/scratch`, { recursive: true });
|
await Deno.remove(workdir, { recursive: true });
|
||||||
}
|
}
|
||||||
|
},
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1
std/wasi/testdata
Submodule
1
std/wasi/testdata
Submodule
|
@ -0,0 +1 @@
|
||||||
|
Subproject commit 419874edc0dd334df55760ba626ecc94a1df7cc9
|
1
std/wasi/testdata/fixture/directory/file
vendored
1
std/wasi/testdata/fixture/directory/file
vendored
|
@ -1 +0,0 @@
|
||||||
directory/file
|
|
|
@ -1 +0,0 @@
|
||||||
file
|
|
1
std/wasi/testdata/fixture/file
vendored
1
std/wasi/testdata/fixture/file
vendored
|
@ -1 +0,0 @@
|
||||||
file
|
|
|
@ -1 +0,0 @@
|
||||||
directory
|
|
1
std/wasi/testdata/fixture/symlink_to_file
vendored
1
std/wasi/testdata/fixture/symlink_to_file
vendored
|
@ -1 +0,0 @@
|
||||||
file
|
|
9
std/wasi/testdata/std_env_args.rs
vendored
9
std/wasi/testdata/std_env_args.rs
vendored
|
@ -1,9 +0,0 @@
|
||||||
// { "args": ["one", "two", "three" ]}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let mut args = std::env::args();
|
|
||||||
assert_eq!(args.len(), 3);
|
|
||||||
assert_eq!(args.next().unwrap(), "one");
|
|
||||||
assert_eq!(args.next().unwrap(), "two");
|
|
||||||
assert_eq!(args.next().unwrap(), "three");
|
|
||||||
}
|
|
6
std/wasi/testdata/std_env_vars.rs
vendored
6
std/wasi/testdata/std_env_vars.rs
vendored
|
@ -1,6 +0,0 @@
|
||||||
// { "env": { "one": "1", "two": "2", "three": "3" } }
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let vars = std::env::vars();
|
|
||||||
assert_eq!(vars.count(), 3);
|
|
||||||
}
|
|
6
std/wasi/testdata/std_fs_create_dir.rs
vendored
6
std/wasi/testdata/std_fs_create_dir.rs
vendored
|
@ -1,6 +0,0 @@
|
||||||
// { "preopens": { "/scratch": "scratch" } }
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
assert!(std::fs::create_dir("/scratch/directory").is_ok());
|
|
||||||
assert!(std::fs::metadata("/scratch/directory").unwrap().is_dir());
|
|
||||||
}
|
|
6
std/wasi/testdata/std_fs_file_create.rs
vendored
6
std/wasi/testdata/std_fs_file_create.rs
vendored
|
@ -1,6 +0,0 @@
|
||||||
// { "preopens": { "/scratch": "scratch" } }
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
assert!(std::fs::File::create("/scratch/file").is_ok());
|
|
||||||
assert!(std::fs::metadata("/scratch/file").unwrap().is_file());
|
|
||||||
}
|
|
23
std/wasi/testdata/std_fs_file_metadata.rs
vendored
23
std/wasi/testdata/std_fs_file_metadata.rs
vendored
|
@ -1,23 +0,0 @@
|
||||||
// { "preopens": { "/fixture": "fixture" } }
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let file = std::fs::File::open("/fixture/file").unwrap();
|
|
||||||
let metadata = file.metadata().unwrap();
|
|
||||||
assert!(metadata.is_file());
|
|
||||||
assert!(metadata.len() == 5);
|
|
||||||
|
|
||||||
let file = std::fs::File::open("/fixture/symlink_to_file").unwrap();
|
|
||||||
let metadata = file.metadata().unwrap();
|
|
||||||
assert!(metadata.is_file());
|
|
||||||
assert!(metadata.len() == 5);
|
|
||||||
|
|
||||||
let file = std::fs::File::open("/fixture/directory/file").unwrap();
|
|
||||||
let metadata = file.metadata().unwrap();
|
|
||||||
assert!(metadata.is_file());
|
|
||||||
assert!(metadata.len() == 15);
|
|
||||||
|
|
||||||
let file = std::fs::File::open("/fixture/directory/symlink_to_file").unwrap();
|
|
||||||
let metadata = file.metadata().unwrap();
|
|
||||||
assert!(metadata.is_file());
|
|
||||||
assert!(metadata.len() == 15);
|
|
||||||
}
|
|
16
std/wasi/testdata/std_fs_file_read.rs
vendored
16
std/wasi/testdata/std_fs_file_read.rs
vendored
|
@ -1,16 +0,0 @@
|
||||||
// { "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);
|
|
||||||
}
|
|
33
std/wasi/testdata/std_fs_file_seek.rs
vendored
33
std/wasi/testdata/std_fs_file_seek.rs
vendored
|
@ -1,33 +0,0 @@
|
||||||
// { "preopens": { "/fixture": "fixture" } }
|
|
||||||
|
|
||||||
use std::io::Seek;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let mut file = std::fs::File::open("/fixture/file").unwrap();
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::Current(0)).unwrap(), 0);
|
|
||||||
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::Start(1)).unwrap(), 1);
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::Start(2)).unwrap(), 2);
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::Start(3)).unwrap(), 3);
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::Start(4)).unwrap(), 4);
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::Start(5)).unwrap(), 5);
|
|
||||||
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::Current(-1)).unwrap(), 4);
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::Current(-1)).unwrap(), 3);
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::Current(-1)).unwrap(), 2);
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::Current(-1)).unwrap(), 1);
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::Current(-1)).unwrap(), 0);
|
|
||||||
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::Current(1)).unwrap(), 1);
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::Current(1)).unwrap(), 2);
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::Current(1)).unwrap(), 3);
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::Current(1)).unwrap(), 4);
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::Current(1)).unwrap(), 5);
|
|
||||||
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::End(0)).unwrap(), 5);
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::End(-1)).unwrap(), 4);
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::End(-2)).unwrap(), 3);
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::End(-3)).unwrap(), 2);
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::End(-4)).unwrap(), 1);
|
|
||||||
assert_eq!(file.seek(std::io::SeekFrom::End(-5)).unwrap(), 0);
|
|
||||||
}
|
|
17
std/wasi/testdata/std_fs_file_set_len.rs
vendored
17
std/wasi/testdata/std_fs_file_set_len.rs
vendored
|
@ -1,17 +0,0 @@
|
||||||
// { "preopens": { "/scratch": "scratch" } }
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let file = std::fs::File::create("/scratch/file").unwrap();
|
|
||||||
|
|
||||||
assert!(file.set_len(0).is_ok());
|
|
||||||
assert_eq!(file.metadata().unwrap().len(), 0);
|
|
||||||
|
|
||||||
assert!(file.set_len(5).is_ok());
|
|
||||||
assert_eq!(file.metadata().unwrap().len(), 5);
|
|
||||||
|
|
||||||
assert!(file.set_len(25).is_ok());
|
|
||||||
assert_eq!(file.metadata().unwrap().len(), 25);
|
|
||||||
|
|
||||||
assert!(file.set_len(0).is_ok());
|
|
||||||
assert_eq!(file.metadata().unwrap().len(), 0);
|
|
||||||
}
|
|
15
std/wasi/testdata/std_fs_file_sync_all.rs
vendored
15
std/wasi/testdata/std_fs_file_sync_all.rs
vendored
|
@ -1,15 +0,0 @@
|
||||||
// { "preopens": { "/scratch": "scratch" } }
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let file = std::fs::File::create("/scratch/file").unwrap();
|
|
||||||
|
|
||||||
assert!(file.set_len(5).is_ok());
|
|
||||||
assert!(file.sync_all().is_ok());
|
|
||||||
let metadata = std::fs::metadata("/scratch/file").unwrap();
|
|
||||||
assert_eq!(metadata.len(), 5);
|
|
||||||
|
|
||||||
assert!(file.set_len(25).is_ok());
|
|
||||||
assert!(file.sync_all().is_ok());
|
|
||||||
let metadata = std::fs::metadata("/scratch/file").unwrap();
|
|
||||||
assert_eq!(metadata.len(), 25);
|
|
||||||
}
|
|
15
std/wasi/testdata/std_fs_file_sync_data.rs
vendored
15
std/wasi/testdata/std_fs_file_sync_data.rs
vendored
|
@ -1,15 +0,0 @@
|
||||||
// { "preopens": { "/scratch": "scratch" } }
|
|
||||||
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let mut file = std::fs::File::create("/scratch/file").unwrap();
|
|
||||||
|
|
||||||
assert!(file.write(b"Hello").is_ok());
|
|
||||||
assert!(file.sync_data().is_ok());
|
|
||||||
assert_eq!(std::fs::read("/scratch/file").unwrap(), b"Hello");
|
|
||||||
|
|
||||||
assert!(file.write(b", world!").is_ok());
|
|
||||||
assert!(file.sync_data().is_ok());
|
|
||||||
assert_eq!(std::fs::read("/scratch/file").unwrap(), b"Hello, world!");
|
|
||||||
}
|
|
9
std/wasi/testdata/std_fs_file_write.rs
vendored
9
std/wasi/testdata/std_fs_file_write.rs
vendored
|
@ -1,9 +0,0 @@
|
||||||
// { "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);
|
|
||||||
}
|
|
11
std/wasi/testdata/std_fs_hard_link.rs
vendored
11
std/wasi/testdata/std_fs_hard_link.rs
vendored
|
@ -1,11 +0,0 @@
|
||||||
// { "preopens": { "/fixture": "fixture", "/scratch": "scratch" } }
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
assert!(
|
|
||||||
std::fs::hard_link("/fixture/file", "/scratch/hardlink_to_file").is_ok()
|
|
||||||
);
|
|
||||||
assert_eq!(
|
|
||||||
std::fs::read("/fixture/file").unwrap(),
|
|
||||||
std::fs::read("/scratch/hardlink_to_file").unwrap()
|
|
||||||
);
|
|
||||||
}
|
|
26
std/wasi/testdata/std_fs_metadata.rs
vendored
26
std/wasi/testdata/std_fs_metadata.rs
vendored
|
@ -1,26 +0,0 @@
|
||||||
// { "preopens": { "/fixture": "fixture" } }
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let metadata = std::fs::metadata("/fixture/directory").unwrap();
|
|
||||||
assert!(metadata.is_dir());
|
|
||||||
|
|
||||||
let metadata = std::fs::metadata("/fixture/symlink_to_directory").unwrap();
|
|
||||||
assert!(metadata.is_dir());
|
|
||||||
|
|
||||||
let metadata = std::fs::metadata("/fixture/file").unwrap();
|
|
||||||
assert!(metadata.is_file());
|
|
||||||
assert_eq!(metadata.len(), 5);
|
|
||||||
|
|
||||||
let metadata = std::fs::metadata("/fixture/symlink_to_file").unwrap();
|
|
||||||
assert!(metadata.is_file());
|
|
||||||
assert_eq!(metadata.len(), 5);
|
|
||||||
|
|
||||||
let metadata = std::fs::metadata("/fixture/directory/file").unwrap();
|
|
||||||
assert!(metadata.is_file());
|
|
||||||
assert_eq!(metadata.len(), 15);
|
|
||||||
|
|
||||||
let metadata =
|
|
||||||
std::fs::metadata("/fixture/directory/symlink_to_file").unwrap();
|
|
||||||
assert!(metadata.is_file());
|
|
||||||
assert_eq!(metadata.len(), 15);
|
|
||||||
}
|
|
17
std/wasi/testdata/std_fs_read.rs
vendored
17
std/wasi/testdata/std_fs_read.rs
vendored
|
@ -1,17 +0,0 @@
|
||||||
// { "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"
|
|
||||||
);
|
|
||||||
}
|
|
9
std/wasi/testdata/std_fs_read_dir.rs
vendored
9
std/wasi/testdata/std_fs_read_dir.rs
vendored
|
@ -1,9 +0,0 @@
|
||||||
// { "preopens": { "/fixture": "fixture" } }
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let entries = std::fs::read_dir("/fixture").unwrap();
|
|
||||||
assert_eq!(entries.count(), 4);
|
|
||||||
|
|
||||||
let entries = std::fs::read_dir("/fixture/directory").unwrap();
|
|
||||||
assert_eq!(entries.count(), 2);
|
|
||||||
}
|
|
11
std/wasi/testdata/std_fs_rename.rs
vendored
11
std/wasi/testdata/std_fs_rename.rs
vendored
|
@ -1,11 +0,0 @@
|
||||||
// { "preopens": { "/scratch": "scratch" } }
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let old_path = "/scratch/old_file";
|
|
||||||
let new_path = "/scratch/new_file";
|
|
||||||
|
|
||||||
assert!(std::fs::write(old_path, b"Hello, world!").is_ok());
|
|
||||||
assert!(std::fs::rename(old_path, new_path).is_ok());
|
|
||||||
assert!(std::fs::read(old_path).is_err());
|
|
||||||
assert_eq!(std::fs::read(new_path).unwrap(), b"Hello, world!");
|
|
||||||
}
|
|
23
std/wasi/testdata/std_fs_symlink_metadata.rs
vendored
23
std/wasi/testdata/std_fs_symlink_metadata.rs
vendored
|
@ -1,23 +0,0 @@
|
||||||
// { "preopens": { "/fixture": "fixture" } }
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let metadata = std::fs::symlink_metadata("/fixture/directory").unwrap();
|
|
||||||
assert!(metadata.file_type().is_dir());
|
|
||||||
|
|
||||||
let metadata =
|
|
||||||
std::fs::symlink_metadata("/fixture/symlink_to_directory").unwrap();
|
|
||||||
assert!(metadata.file_type().is_symlink());
|
|
||||||
|
|
||||||
let metadata = std::fs::symlink_metadata("/fixture/file").unwrap();
|
|
||||||
assert!(metadata.file_type().is_file());
|
|
||||||
|
|
||||||
let metadata = std::fs::symlink_metadata("/fixture/symlink_to_file").unwrap();
|
|
||||||
assert!(metadata.file_type().is_symlink());
|
|
||||||
|
|
||||||
let metadata = std::fs::symlink_metadata("/fixture/directory/file").unwrap();
|
|
||||||
assert!(metadata.file_type().is_file());
|
|
||||||
|
|
||||||
let metadata =
|
|
||||||
std::fs::symlink_metadata("/fixture/directory/symlink_to_file").unwrap();
|
|
||||||
assert!(metadata.file_type().is_symlink());
|
|
||||||
}
|
|
5
std/wasi/testdata/std_fs_write.rs
vendored
5
std/wasi/testdata/std_fs_write.rs
vendored
|
@ -1,5 +0,0 @@
|
||||||
// { "preopens": { "/scratch": "scratch" }, "files": { "scratch/file": "file" } }
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
assert!(std::fs::write("/scratch/file", b"file").is_ok())
|
|
||||||
}
|
|
7
std/wasi/testdata/std_io_stderr.rs
vendored
7
std/wasi/testdata/std_io_stderr.rs
vendored
|
@ -1,7 +0,0 @@
|
||||||
// { "stderr": "Hello, stderr!" }
|
|
||||||
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
assert!(std::io::stderr().write_all(b"Hello, stderr!").is_ok())
|
|
||||||
}
|
|
9
std/wasi/testdata/std_io_stdin.rs
vendored
9
std/wasi/testdata/std_io_stdin.rs
vendored
|
@ -1,9 +0,0 @@
|
||||||
// { "stdin": "Hello, stdin!" }
|
|
||||||
|
|
||||||
use std::io::Read;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
let mut buffer = String::new();
|
|
||||||
assert!(std::io::stdin().read_to_string(&mut buffer).is_ok());
|
|
||||||
assert_eq!(buffer, "Hello, stdin!")
|
|
||||||
}
|
|
7
std/wasi/testdata/std_io_stdout.rs
vendored
7
std/wasi/testdata/std_io_stdout.rs
vendored
|
@ -1,7 +0,0 @@
|
||||||
// { "stdout": "Hello, stdout!" }
|
|
||||||
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
assert!(std::io::stdout().write_all(b"Hello, stdout!").is_ok())
|
|
||||||
}
|
|
5
std/wasi/testdata/std_process_exit.rs
vendored
5
std/wasi/testdata/std_process_exit.rs
vendored
|
@ -1,5 +0,0 @@
|
||||||
// { "exitCode": "120" }
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
std::process::exit(120);
|
|
||||||
}
|
|
Loading…
Reference in a new issue