Skip to content

Commit dd19929

Browse files
committed
Update tests for recent Binaryen changes
1 parent c8d2de8 commit dd19929

8 files changed

Lines changed: 138 additions & 234 deletions

File tree

tests/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
These test cases exists to catch the most obvious issues before pushing the binary back to GitHub
2+
and are not intended to be a full test suite, but feel free to extend / send a PR if necessary!

tests/fixtures/index.asm.js

Lines changed: 0 additions & 66 deletions
This file was deleted.

tests/fixtures/index.wasm

-79 Bytes
Binary file not shown.

tests/fixtures/index.wast

Lines changed: 0 additions & 12 deletions
This file was deleted.

tests/index.js

Lines changed: 2 additions & 156 deletions
Original file line numberDiff line numberDiff line change
@@ -1,156 +1,2 @@
1-
var fs = require("fs");
2-
var test = require("tape");
3-
4-
var isUpdate = process.argv[2] === "update";
5-
6-
// This test case exists to catch the most obvious issues before pushing the binary back to GitHub.
7-
// It's not intended to be a full test suite, but feel free to extend it / send a PR if necessary!
8-
9-
var binaryen;
10-
test("requiring binaryen", function(test) {
11-
test.doesNotThrow(function() {
12-
binaryen = require("..");
13-
});
14-
test.end();
15-
});
16-
17-
var mod;
18-
test("constructing a module", function(test) {
19-
test.doesNotThrow(function() {
20-
mod = new binaryen.Module();
21-
});
22-
test.end();
23-
});
24-
25-
var ftype;
26-
test("adding a function type", function(test) {
27-
test.doesNotThrow(function() {
28-
ftype = mod.addFunctionType("i", binaryen.i32, []);
29-
});
30-
test.end();
31-
});
32-
33-
var expr;
34-
test("creating an expression", function(test) {
35-
test.doesNotThrow(function() {
36-
expr = mod.i32.const(0);
37-
});
38-
test.end();
39-
});
40-
41-
var stmt;
42-
test("creating a statement", function(test) {
43-
test.doesNotThrow(function() {
44-
stmt = mod.return(expr);
45-
});
46-
test.end();
47-
});
48-
49-
test("adding a function", function(test) {
50-
test.doesNotThrow(function() {
51-
mod.addFunction("main", ftype, [], stmt);
52-
});
53-
test.end();
54-
});
55-
56-
test("adding a function import", function(test) {
57-
test.doesNotThrow(function() {
58-
mod.addFunctionImport("imported", "env", "provided", ftype);
59-
});
60-
test.end();
61-
});
62-
63-
test("adding a function export", function(test) {
64-
test.doesNotThrow(function() {
65-
mod.addFunctionExport("main", "main");
66-
});
67-
test.end();
68-
});
69-
70-
test("adding a memory import", function(test) {
71-
test.doesNotThrow(function() {
72-
mod.addMemoryImport("0", "env", "memory"); // doesn't work with a different internal name, yet
73-
});
74-
test.end();
75-
});
76-
77-
test("adding a memory export", function(test) {
78-
test.doesNotThrow(function() {
79-
mod.addMemoryExport("0", "memory");
80-
});
81-
test.end();
82-
});
83-
84-
var text;
85-
test("emitting text", function(test) {
86-
test.doesNotThrow(function() {
87-
text = mod.emitText();
88-
});
89-
test.ok(typeof text === "string" && text.length, "should return be a non-empty string");
90-
test.end();
91-
});
92-
93-
var binary;
94-
test("emitting binary", function(test) {
95-
test.doesNotThrow(function() {
96-
binary = mod.emitBinary();
97-
});
98-
test.ok(binary && binary.length, "should return a non-empty array-like object");
99-
test.end();
100-
});
101-
102-
test("validating the module", function(test) {
103-
var valid;
104-
test.doesNotThrow(function() {
105-
valid = mod.validate();
106-
});
107-
test.ok(valid, "the module should be valid");
108-
test.end();
109-
});
110-
111-
test("optimizing the module", function(test) {
112-
test.doesNotThrow(function() {
113-
mod.optimize();
114-
});
115-
test.end();
116-
});
117-
118-
var asmjs;
119-
test("emitting asmjs", function(test) {
120-
test.doesNotThrow(function() {
121-
mod.removeImport("0"); // wasm2js doesn't support non-function imports (here: memory)
122-
asmjs = mod.emitAsmjs();
123-
});
124-
test.ok(typeof asmjs === "string" && asmjs.length, "should return a non-empty string");
125-
test.end();
126-
});
127-
128-
function stripComments(text) {
129-
return text.replace(/ \(; [\w$_]+ ;\)/g, "");
130-
}
131-
132-
test("fixtures", function(test) {
133-
134-
if (isUpdate) {
135-
fs.writeFileSync(__dirname + "/fixtures/index.wast", text, "utf8");
136-
} else {
137-
var textComp = fs.readFileSync(__dirname + "/fixtures/index.wast", "utf8").replace(/\r?\n/g, "\n");
138-
test.strictEqual(stripComments(text), stripComments(textComp), "should match text output");
139-
}
140-
141-
if (isUpdate) {
142-
fs.writeFileSync(__dirname + "/fixtures/index.wasm", binary);
143-
} else {
144-
var binaryComp = fs.readFileSync(__dirname + "/fixtures/index.wasm");
145-
test.ok(Buffer.compare(binary, binaryComp) === 0, "should match binary output");
146-
}
147-
148-
if (isUpdate) {
149-
fs.writeFileSync(__dirname + "/fixtures/index.asm.js", asmjs, "utf8");
150-
} else {
151-
// var asmjsComp = fs.readFileSync(__dirname + "/fixtures/index.asm.js");
152-
// test.strictEqual(asmjs, asmjsComp, "should match asm.js output");
153-
}
154-
155-
test.end();
156-
});
1+
require("./test-wasm");
2+
require("./test-js");

tests/test-common.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
module.exports = function(test, binaryen, mod) {
2+
3+
var ftype;
4+
test("adding a function type", function(test) {
5+
test.doesNotThrow(function() {
6+
ftype = mod.addFunctionType("i", binaryen.i32, []);
7+
});
8+
test.end();
9+
});
10+
11+
var expr;
12+
test("creating an expression", function(test) {
13+
test.doesNotThrow(function() {
14+
expr = mod.i32.const(0);
15+
});
16+
test.end();
17+
});
18+
19+
var stmt;
20+
test("creating a statement", function(test) {
21+
test.doesNotThrow(function() {
22+
stmt = mod.return(expr);
23+
});
24+
test.end();
25+
});
26+
27+
test("adding a function", function(test) {
28+
test.doesNotThrow(function() {
29+
mod.addFunction("main", ftype, [], stmt);
30+
});
31+
test.end();
32+
});
33+
34+
test("adding a function import", function(test) {
35+
test.doesNotThrow(function() {
36+
mod.addFunctionImport("imported", "env", "provided", ftype);
37+
});
38+
test.end();
39+
});
40+
41+
test("adding a function export", function(test) {
42+
test.doesNotThrow(function() {
43+
mod.addFunctionExport("main", "main");
44+
});
45+
test.end();
46+
});
47+
48+
} // exports

tests/test-js.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
var test = require("tape");
2+
var binaryen = require("..");
3+
4+
var mod = new binaryen.Module();
5+
6+
require("./test-common")(test, binaryen, mod);
7+
8+
// <js only>
9+
10+
test("emitting js", function(test) {
11+
var out;
12+
test.doesNotThrow(function() {
13+
out = mod.emitAsmjs();
14+
});
15+
test.ok(typeof out === "string" && out.length, "should return a non-empty string");
16+
test.end();
17+
});
18+
19+
// </js only>

tests/test-wasm.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
var test = require("tape");
2+
var binaryen = require("..");
3+
4+
var mod = new binaryen.Module();
5+
6+
require("./test-common")(test, binaryen, mod);
7+
8+
// <wasm only>
9+
10+
test("adding a memory import", function(test) {
11+
test.doesNotThrow(function() {
12+
mod.addMemoryImport("0", "env", "memory"); // doesn't work with a different internal name, yet
13+
});
14+
test.end();
15+
});
16+
17+
test("adding a memory export", function(test) {
18+
test.doesNotThrow(function() {
19+
mod.addMemoryExport("0", "memory");
20+
});
21+
test.end();
22+
});
23+
24+
// </wasm only>
25+
26+
var text;
27+
test("emitting text", function(test) {
28+
test.doesNotThrow(function() {
29+
text = mod.emitText();
30+
});
31+
test.ok(typeof text === "string" && text.length, "should return be a non-empty string");
32+
test.end();
33+
});
34+
35+
var binary;
36+
test("emitting binary", function(test) {
37+
test.doesNotThrow(function() {
38+
binary = mod.emitBinary();
39+
});
40+
test.ok(binary && binary.length, "should return a non-empty array-like object");
41+
test.end();
42+
});
43+
44+
test("validating the module", function(test) {
45+
var valid;
46+
test.doesNotThrow(function() {
47+
valid = mod.validate();
48+
});
49+
test.ok(valid, "the module should be valid");
50+
test.end();
51+
});
52+
53+
test("optimizing the module", function(test) {
54+
test.doesNotThrow(function() {
55+
mod.optimize();
56+
});
57+
test.end();
58+
});
59+
60+
test("validating the module again", function(test) {
61+
var valid;
62+
test.doesNotThrow(function() {
63+
valid = mod.validate();
64+
});
65+
test.ok(valid, "the module should be valid");
66+
test.end();
67+
});

0 commit comments

Comments
 (0)