diff options
author | Casper Beyer <caspervonb@pm.me> | 2021-01-05 19:16:46 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-01-05 12:16:46 +0100 |
commit | c823211a2cae13ff6fdb7d3d3fc585bb4e096232 (patch) | |
tree | 0c33314357cfaa8fe622a0ff85ccc1694e67ddf5 /std/wasi/snapshot_preview1_test.ts | |
parent | 37a9d6678ed4f634100d4b6ecb5abd7b0b45faad (diff) |
feat(std/wasi): allow stdio resources to be specified (#8999)
Diffstat (limited to 'std/wasi/snapshot_preview1_test.ts')
-rw-r--r-- | std/wasi/snapshot_preview1_test.ts | 66 |
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!"); +}); |