Skip to content

Commit c8a150c

Browse files
author
Willem Wyndham
authored
Add more tests for asconfig (#1412)
1 parent df40407 commit c8a150c

File tree

19 files changed

+106
-18
lines changed

19 files changed

+106
-18
lines changed

tests/asconfig/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
!entry-points/**/*/node_modules/
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
assert(ASC_OPTIMIZE_LEVEL == 3);
2-
assert(ASC_SHRINK_LEVEL == 1);
3-
assert(ASC_FEATURE_SIMD);
1+
assert(ASC_OPTIMIZE_LEVEL == 3, "expected optimize level == 3");
2+
assert(ASC_SHRINK_LEVEL == 1, "expected shrink level == 1");
3+
assert(ASC_FEATURE_SIMD, "expected SIMD enabled");
44
let size = memory.size();
55
trace("size", 1, size);
6-
assert(size == 30);
6+
assert(size == 30, "expected 30 got " + size.toString());
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"extends": "entry-points/asconfig.json"
3+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
assert(answerToLife == 42);

tests/asconfig/entry-points/node-resolution/node_modules/entry-points/asconfig.json

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/asconfig/entry-points/node-resolution/node_modules/entry-points/assembly/globals.ts

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/asconfig/entry-points/node-resolution/node_modules/entry-points/assembly/index.ts

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"private": true,
3+
"scripts": {
4+
"test": "node ../../index.js"
5+
}
6+
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"private": true,
33
"scripts": {
4-
"test": "node ../index.js && cd nested && npm run test"
4+
"test": "node ../index.js && npm run test:nested && npm run test:node",
5+
"test:nested": "cd nested && npm run test",
6+
"test:node": "cd node-resolution && npm run test"
57
}
68
}

tests/asconfig/extends/asconfig.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
}
66
},
77
"options": {
8-
"enable": ["simd"]
8+
"enable": ["simd"],
9+
"runtime": "half",
10+
"noEmit": false
911
},
1012
"extends": "./extends.json"
1113
}

tests/asconfig/extends/expected.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"options": {
3+
"runtime": "half",
4+
"noEmit": false,
5+
"noAssert": true,
6+
"enable": ["simd"]
7+
}
8+
}

tests/asconfig/extends/extends.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
}
77
},
88
"options": {
9-
"disable": ["simd"]
9+
"disable": ["simd"],
10+
"noEmit": true,
11+
"noAssert": true
1012
}
1113
}

tests/asconfig/extends/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"private": true,
33
"scripts": {
4-
"test": "node ../index.js"
4+
"test": "node ../index.js --showConfig && node ../index.js"
55
}
66
}

tests/asconfig/index.js

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
11
const asc = require("../../cli/asc");
22
const loader = require("../../lib/loader");
33
const args = process.argv.slice(2);
4+
const path = require('path');
5+
const fs = require("fs");
46

7+
/** @type {string} */
8+
let stderr;
59
/** @type {Uint8Array} */
610
let binary;
711
asc.main(["assembly/index.ts", "--outFile", "output.wasm", "--explicitStart", ...args], {
@@ -11,13 +15,52 @@ asc.main(["assembly/index.ts", "--outFile", "output.wasm", "--explicitStart", ..
1115
} else if (name !== "output.wasm.map") {
1216
throw Error("Unexpected output file: " + name);
1317
}
18+
},
19+
stderr: {
20+
write(s) {
21+
stderr = s;
22+
}
1423
}
24+
1525
}, (err) => {
1626
if (err) {
1727
console.error(err);
28+
console.error(stderr);
1829
process.exit(1);
1930
}
2031

32+
const jsonPath = path.join(process.cwd(), "expected.json");
33+
if (fs.existsSync(jsonPath) && stderr) {
34+
const actualRes = JSON.parse(stderr);
35+
const actual = actualRes.options;
36+
const expected = require(jsonPath).options;
37+
let errored = false;
38+
for (let name of Object.getOwnPropertyNames(expected)) {
39+
if (actual[name] !== expected[name]) {
40+
// If object check just first level
41+
if (typeof actual[name] === 'object' && typeof expected[name] === 'object') {
42+
let error = false;
43+
for (let field of Object.getOwnPropertyNames(actual[name])) {
44+
if (actual[name][field] !== expected[name][field]) {
45+
error = true;
46+
break;
47+
}
48+
}
49+
if (!error) {
50+
continue;
51+
}
52+
}
53+
console.error(name + ": " + actual[name] + " expected " + expected[name]);
54+
errored = true;
55+
}
56+
}
57+
if (errored) {
58+
process.exit(1);
59+
}
60+
process.exit(0);
61+
}
62+
63+
2164
if (!binary) {
2265
console.error("No binary was generated for the asconfig test in " + process.cwd());
2366
process.exit(1);
@@ -29,6 +72,7 @@ asc.main(["assembly/index.ts", "--outFile", "output.wasm", "--explicitStart", ..
2972
theModule.exports._start();
3073
} catch (err) {
3174
console.error("The wasm module _start() function failed in " + process.cwd());
75+
console.error(err);
3276
process.exit(1);
3377
}
3478
return 0;

tests/asconfig/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
{
22
"private": true,
33
"scripts": {
4-
"test": "npm run test:use-consts && npm run test:target && npm run test:entry-points && npm run test:complicated",
4+
"test": "npm run test:use-consts && npm run test:target && npm run test:entry-points && npm run test:complicated && npm run test:extends",
55
"test:use-consts": "cd use-consts && npm run test",
66
"test:entry-points": "cd entry-points && npm run test",
77
"test:respect-inheritence": "cd respect-inheritence && npm run test",
88
"test:target": "cd target && npm run test",
99
"test:cyclical": "cd cyclical && npm run test",
10-
"test:complicated": "cd complicated && npm run test"
10+
"test:complicated": "cd complicated && npm run test",
11+
"test:extends": "cd extends && npm run test"
1112
}
1213
}

tests/asconfig/target/asconfig.json

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,17 @@
11
{
22
"targets": {
33
"release": {
4+
"noAssert": true,
5+
"runtime": "none"
6+
},
7+
"debug": {
48
"optimizeLevel": 3,
59
"shrinkLevel": 1,
6-
"enable": ["simd"]
7-
},
8-
"dev": {
10+
"enable": ["simd"],
911
"debug": true
1012
}
1113
},
12-
"options": {}
14+
"options": {
15+
"runtime": "stub"
16+
}
1317
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
assert(ASC_OPTIMIZE_LEVEL == 3);
2-
assert(ASC_SHRINK_LEVEL == 1);
3-
assert(ASC_FEATURE_SIMD);
1+
assert(ASC_OPTIMIZE_LEVEL == 3, "expected optimize level == 3");
2+
assert(ASC_SHRINK_LEVEL == 1, "expected shrink level == 1");
3+
assert(ASC_FEATURE_SIMD, "expected SIMD enabled");

tests/asconfig/target/expected.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"options": {
3+
"runtime": "none",
4+
"noAssert": true
5+
}
6+
}

tests/asconfig/target/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"private": true,
33
"scripts": {
4-
"test": "node ../index.js"
4+
"test": "node ../index.js --target debug && node ../index.js --showConfig"
55
}
66
}

0 commit comments

Comments
 (0)