Skip to content

Commit

Permalink
Merge pull request #7379 from xtuc/refactor-use-wast-in-tests
Browse files Browse the repository at this point in the history
switch to tests to wast
  • Loading branch information
sokra committed May 25, 2018
2 parents c513cac + 00eafa6 commit 4cd0cf5
Show file tree
Hide file tree
Showing 32 changed files with 115 additions and 11 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -72,6 +72,7 @@
"url-loader": "^0.6.2",
"val-loader": "^1.0.2",
"vm-browserify": "~0.0.0",
"wast-loader": "^1.5.5",
"webpack-dev-middleware": "^1.9.0",
"worker-loader": "^1.1.1",
"xxhashjs": "^0.2.1"
Expand Down
5 changes: 5 additions & 0 deletions test/TestCases.template.js
Expand Up @@ -143,6 +143,11 @@ const describeCases = config => {
{
test: /\.pug/,
loader: "pug-loader"
},
{
test: /\.wat$/i,
loader: "wast-loader",
type: "webassembly/experimental"
}
]
},
Expand Down
2 changes: 1 addition & 1 deletion test/cases/wasm/import-wasm-wasm/index.js
@@ -1,5 +1,5 @@
it("should allow to run a WebAssembly module with imports", function() {
return import("./wasm.wasm").then(function(wasm) {
return import("./wasm.wat").then(function(wasm) {
const result = wasm.addNumber(20);
expect(result).toEqual(42);
});
Expand Down
Binary file removed test/cases/wasm/import-wasm-wasm/wasm.wasm
Binary file not shown.
9 changes: 9 additions & 0 deletions test/cases/wasm/import-wasm-wasm/wasm.wat
@@ -0,0 +1,9 @@
(module
(type $t0 (func (result i32)))
(type $t1 (func (param i32) (result i32)))
(import "./wasm2.wat" "getNumber" (func $./wasm2.wasm.getNumber (type $t0)))
(func $addNumber (export "addNumber") (type $t1) (param $p0 i32) (result i32)
(i32.add
(get_local $p0)
(call $./wasm2.wasm.getNumber))))

Binary file removed test/cases/wasm/import-wasm-wasm/wasm2.wasm
Binary file not shown.
5 changes: 5 additions & 0 deletions test/cases/wasm/import-wasm-wasm/wasm2.wat
@@ -0,0 +1,5 @@
(module
(type $t0 (func (result i32)))
(func $getNumber (export "getNumber") (type $t0) (result i32)
(i32.const 22)))

2 changes: 1 addition & 1 deletion test/cases/wasm/imports-circular/module.js
@@ -1,4 +1,4 @@
import { addNumber } from "./wasm.wasm";
import { addNumber } from "./wasm.wat";

export var result = addNumber(22);

Expand Down
Binary file removed test/cases/wasm/imports-circular/wasm.wasm
Binary file not shown.
9 changes: 9 additions & 0 deletions test/cases/wasm/imports-circular/wasm.wat
@@ -0,0 +1,9 @@
(module
(type $t0 (func (result i32)))
(type $t1 (func (param i32) (result i32)))
(import "./module" "getNumber" (func $./module.getNumber (type $t0)))
(func $addNumber (export "addNumber") (type $t1) (param $p0 i32) (result i32)
(i32.add
(get_local $p0)
(call $./module.getNumber))))

2 changes: 1 addition & 1 deletion test/cases/wasm/imports/index.js
@@ -1,5 +1,5 @@
it("should allow to run a WebAssembly module with imports", function() {
return import("./wasm.wasm?1").then(function(wasm) {
return import("./wasm.wat?1").then(function(wasm) {
const result = wasm.addNumber(3);
expect(result).toEqual(11);
});
Expand Down
Binary file removed test/cases/wasm/imports/wasm.wasm
Binary file not shown.
9 changes: 9 additions & 0 deletions test/cases/wasm/imports/wasm.wat
@@ -0,0 +1,9 @@
(module
(type $t0 (func (result i32)))
(type $t1 (func (param i32) (result i32)))
(import "./module" "getNumber" (func $./module.getNumber (type $t0)))
(func $addNumber (export "addNumber") (type $t1) (param $p0 i32) (result i32)
(i32.add
(get_local $p0)
(call $./module.getNumber))))

Binary file removed test/cases/wasm/memory/mem-access.wasm
Binary file not shown.
11 changes: 11 additions & 0 deletions test/cases/wasm/memory/mem-access.wat
@@ -0,0 +1,11 @@
(module
(type $t0 (func (result i32)))
(type $t1 (func (param i32)))
(import "./memory.wat" "memory" (memory $./memory.wasm.memory 1))
(func $get (export "get") (type $t0) (result i32)
(i32.load
(i32.const 0)))
(func $set (export "set") (type $t1) (param $p i32)
(i32.store
(i32.const 0)
(get_local $p))))
Binary file removed test/cases/wasm/memory/memory.wasm
Binary file not shown.
4 changes: 4 additions & 0 deletions test/cases/wasm/memory/memory.wat
@@ -0,0 +1,4 @@
(module
(memory $memory (export "memory") 1)
(data (i32.const 12) "\00\00\00\00"))

4 changes: 2 additions & 2 deletions test/cases/wasm/memory/run.js
@@ -1,5 +1,5 @@
import * as a1 from "./mem-access.wasm?1";
import * as a2 from "./mem-access.wasm?2";
import * as a1 from "./mem-access.wat?1";
import * as a2 from "./mem-access.wat?2";

a1.set(42);
export const x1 = a1.get();
Expand Down
2 changes: 1 addition & 1 deletion test/cases/wasm/order/a.js
@@ -1,6 +1,6 @@
import { trackA, results } from "./tracker";
import "./b.js";
import "./wasm.wasm";
import "./wasm.wat";

trackA();

Expand Down
Binary file removed test/cases/wasm/order/wasm.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion test/cases/wasm/simple/index.js
Expand Up @@ -6,7 +6,7 @@ it("should allow to run a WebAssembly module (indirect)", function() {
});

it("should allow to run a WebAssembly module (direct)", function() {
return import("./wasm.wasm?2").then(function(wasm) {
return import("./wasm.wat?2").then(function(wasm) {
const result = wasm.add(wasm.getNumber(), 2);
expect(result).toEqual(42);
});
Expand Down
2 changes: 1 addition & 1 deletion test/cases/wasm/simple/module.js
@@ -1,4 +1,4 @@
import { add, getNumber } from "./wasm.wasm?1";
import { add, getNumber } from "./wasm.wat?1";

export function run() {
return add(getNumber(), 2);
Expand Down
Binary file removed test/cases/wasm/simple/wasm.wasm
Binary file not shown.
10 changes: 10 additions & 0 deletions test/cases/wasm/simple/wasm.wat
@@ -0,0 +1,10 @@
(module
(type $t0 (func (param i32 i32) (result i32)))
(type $t1 (func (result i32)))
(func $add (export "add") (type $t0) (param $p0 i32) (param $p1 i32) (result i32)
(i32.add
(get_local $p0)
(get_local $p1)))
(func $getNumber (export "getNumber") (type $t1) (result i32)
(i32.const 40)))

6 changes: 3 additions & 3 deletions test/cases/wasm/table/index.js
Expand Up @@ -2,15 +2,15 @@
const UNKNOWN_FUNCTION_TABLE = /invalid index into function table|invalid function/;

it("should support tables", function() {
return import("./wasm-table.wasm").then(function(wasm) {
return import("./wasm-table.wat").then(function(wasm) {
expect(wasm.callByIndex(0)).toEqual(42);
expect(wasm.callByIndex(1)).toEqual(13);
expect(() => wasm.callByIndex(2)).toThrow(UNKNOWN_FUNCTION_TABLE);
});
});

it("should support exported tables", function() {
return import("./wasm-table-export.wasm").then(function(wasm) {
return import("./wasm-table-export.wat").then(function(wasm) {
expect(wasm.table).toBeInstanceOf(WebAssembly.Table);
expect(wasm.table.length).toBe(2);
const e0 = wasm.table.get(0);
Expand All @@ -23,7 +23,7 @@ it("should support exported tables", function() {
});

it("should support imported tables", function() {
return import("./wasm-table-imported.wasm").then(function(wasm) {
return import("./wasm-table-imported.wat").then(function(wasm) {
expect(wasm.callByIndex(0)).toEqual(42);
expect(wasm.callByIndex(1)).toEqual(13);
expect(() => wasm.callByIndex(2)).toThrow(UNKNOWN_FUNCTION_TABLE);
Expand Down
Binary file removed test/cases/wasm/table/wasm-table-export.wasm
Binary file not shown.
9 changes: 9 additions & 0 deletions test/cases/wasm/table/wasm-table-export.wat
@@ -0,0 +1,9 @@
(module
(type $t0 (func (result i32)))
(func $f1 (type $t0) (result i32)
(i32.const 42))
(func $f2 (type $t0) (result i32)
(i32.const 13))
(table $table (export "table") 2 anyfunc)
(elem (i32.const 0) $f1 $f2))

Binary file removed test/cases/wasm/table/wasm-table-imported.wasm
Binary file not shown.
8 changes: 8 additions & 0 deletions test/cases/wasm/table/wasm-table-imported.wat
@@ -0,0 +1,8 @@
(module
(type $t0 (func (result i32)))
(type $t1 (func (param i32) (result i32)))
(import "./wasm-table-export.wat" "table" (table $./wasm-table-export.wasm.table 2 anyfunc))
(func $callByIndex (export "callByIndex") (type $t1) (param $i i32) (result i32)
(call_indirect (type $t0)
(get_local $i))))

Binary file removed test/cases/wasm/table/wasm-table.wasm
Binary file not shown.
14 changes: 14 additions & 0 deletions test/cases/wasm/table/wasm-table.wat
@@ -0,0 +1,14 @@
(module
(type $t0 (func (result i32)))
(type $t1 (func (result i32)))
(type $t2 (func (param i32) (result i32)))
(func $f0 (type $t0) (result i32)
(i32.const 42))
(func $f1 (type $t0) (result i32)
(i32.const 13))
(func $callByIndex (export "callByIndex") (type $t2) (param $p0 i32) (result i32)
(call_indirect (type $t1)
(get_local $p0)))
(table $T0 2 anyfunc)
(elem (i32.const 0) $f0 $f1))

10 changes: 10 additions & 0 deletions yarn.lock
Expand Up @@ -6174,12 +6174,22 @@ w3c-hr-time@^1.0.1:
dependencies:
browser-process-hrtime "^0.1.2"

wabt@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/wabt/-/wabt-1.0.0.tgz#f33a5c4a6405370ec80ba97e782d092f1d599ff4"

walker@~1.0.5:
version "1.0.7"
resolved "https://registry.yarnpkg.com/walker/-/walker-1.0.7.tgz#2f7f9b8fd10d677262b18a884e28d19618e028fb"
dependencies:
makeerror "1.0.x"

wast-loader@^1.5.5:
version "1.5.5"
resolved "https://registry.yarnpkg.com/wast-loader/-/wast-loader-1.5.5.tgz#a1d6cdc468b6963a6e479de683dc74755f09b81a"
dependencies:
wabt "^1.0.0"

watch@~0.18.0:
version "0.18.0"
resolved "https://registry.yarnpkg.com/watch/-/watch-0.18.0.tgz#28095476c6df7c90c963138990c0a5423eb4b986"
Expand Down

0 comments on commit 4cd0cf5

Please sign in to comment.