summaryrefslogtreecommitdiff
path: root/std/wasi/snapshot_preview1_test.ts
diff options
context:
space:
mode:
Diffstat (limited to 'std/wasi/snapshot_preview1_test.ts')
-rw-r--r--std/wasi/snapshot_preview1_test.ts66
1 files changed, 66 insertions, 0 deletions
diff --git a/std/wasi/snapshot_preview1_test.ts b/std/wasi/snapshot_preview1_test.ts
index 55982545f..1fe94a4cc 100644
--- a/std/wasi/snapshot_preview1_test.ts
+++ b/std/wasi/snapshot_preview1_test.ts
@@ -274,3 +274,69 @@ Deno.test("context_initialize", function () {
"WebAssembly.Instance has already started",
);
});
+
+Deno.test("std_io_stdin.wasm with stdin as file", function () {
+ const stdinPath = Deno.makeTempFileSync();
+ Deno.writeTextFileSync(stdinPath, "Hello, stdin!");
+
+ const stdinFile = Deno.openSync(stdinPath);
+
+ const context = new Context({
+ exitOnReturn: false,
+ stdin: stdinFile.rid,
+ });
+
+ const binary = Deno.readFileSync(path.join(testdir, "std_io_stdin.wasm"));
+ const module = new WebAssembly.Module(binary);
+ const instance = new WebAssembly.Instance(module, {
+ wasi_snapshot_preview1: context.exports,
+ });
+
+ context.start(instance);
+
+ stdinFile.close();
+});
+
+Deno.test("std_io_stdout.wasm with stdout as file", function () {
+ const stdoutPath = Deno.makeTempFileSync();
+ const stdoutFile = Deno.openSync(stdoutPath, { create: true, write: true });
+
+ const context = new Context({
+ exitOnReturn: false,
+ stdout: stdoutFile.rid,
+ });
+
+ const binary = Deno.readFileSync(path.join(testdir, "std_io_stdout.wasm"));
+ const module = new WebAssembly.Module(binary);
+ const instance = new WebAssembly.Instance(module, {
+ wasi_snapshot_preview1: context.exports,
+ });
+
+ context.start(instance);
+
+ stdoutFile.close();
+
+ assertEquals(Deno.readTextFileSync(stdoutPath), "Hello, stdout!");
+});
+
+Deno.test("std_io_stderr.wasm with stderr as file", function () {
+ const stderrPath = Deno.makeTempFileSync();
+ const stderrFile = Deno.openSync(stderrPath, { create: true, write: true });
+
+ const context = new Context({
+ exitOnReturn: false,
+ stderr: stderrFile.rid,
+ });
+
+ const binary = Deno.readFileSync(path.join(testdir, "std_io_stderr.wasm"));
+ const module = new WebAssembly.Module(binary);
+ const instance = new WebAssembly.Instance(module, {
+ wasi_snapshot_preview1: context.exports,
+ });
+
+ context.start(instance);
+
+ stderrFile.close();
+
+ assertEquals(Deno.readTextFileSync(stderrPath), "Hello, stderr!");
+});