0
0
Fork 0
mirror of https://github.com/denoland/deno.git synced 2025-03-03 17:34:47 -05:00

test(std/wasi): seperate test runner into a module (#7191)

This commit is contained in:
Casper Beyer 2020-08-27 17:21:57 +08:00 committed by GitHub
parent 59428e3d8a
commit 992248e731
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 98 additions and 100 deletions

View file

@ -3,7 +3,6 @@
import { assert, assertEquals } from "../testing/asserts.ts";
import { copy } from "../fs/mod.ts";
import * as path from "../path/mod.ts";
import Context from "./snapshot_preview1.ts";
const ignore = [
"wasi_clock_time_get_realtime.wasm",
@ -18,26 +17,6 @@ if (Deno.build.os == "windows") {
ignore.push("std_fs_read_dir_relative.wasm");
}
if (import.meta.main) {
const options = JSON.parse(Deno.args[0]);
const pathname = Deno.args[1];
const binary = await Deno.readFile(pathname);
const module = await WebAssembly.compile(binary);
const context = new Context({
env: options.env,
args: [pathname].concat(options.args),
preopens: options.preopens,
});
const instance = new WebAssembly.Instance(module, {
wasi_snapshot_preview1: context.exports,
});
context.memory = instance.exports.memory;
instance.exports._start();
} else {
const rootdir = path.dirname(path.fromFileUrl(import.meta.url));
const testdir = path.join(rootdir, "testdata");
@ -71,7 +50,7 @@ if (import.meta.main) {
"--quiet",
"--unstable",
"--allow-all",
import.meta.url,
path.resolve(rootdir, "snapshot_preview1_test_runner.ts"),
prelude,
path.resolve(testdir, entry.name),
],
@ -119,4 +98,3 @@ if (import.meta.main) {
},
});
}
}

View file

@ -0,0 +1,20 @@
import Context from "./snapshot_preview1.ts";
const options = JSON.parse(Deno.args[0]);
const pathname = Deno.args[1];
const binary = await Deno.readFile(pathname);
const module = await WebAssembly.compile(binary);
const context = new Context({
env: options.env,
args: [pathname].concat(options.args),
preopens: options.preopens,
});
const instance = new WebAssembly.Instance(module, {
wasi_snapshot_preview1: context.exports,
});
context.memory = instance.exports.memory;
instance.exports._start();