Skip to content

Add more tests for asconfig #1412

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions tests/asconfig/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
!entry-points/**/*/node_modules/
8 changes: 4 additions & 4 deletions tests/asconfig/complicated/assembly/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
assert(ASC_OPTIMIZE_LEVEL == 3);
assert(ASC_SHRINK_LEVEL == 1);
assert(ASC_FEATURE_SIMD);
assert(ASC_OPTIMIZE_LEVEL == 3, "expected optimize level == 3");
assert(ASC_SHRINK_LEVEL == 1, "expected shrink level == 1");
assert(ASC_FEATURE_SIMD, "expected SIMD enabled");
let size = memory.size();
trace("size", 1, size);
assert(size == 30);
assert(size == 30, "expected 30 got " + size.toString());
3 changes: 3 additions & 0 deletions tests/asconfig/entry-points/node-resolution/asconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "entry-points/asconfig.json"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assert(answerToLife == 42);

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions tests/asconfig/entry-points/node-resolution/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"private": true,
"scripts": {
"test": "node ../../index.js"
}
}
4 changes: 3 additions & 1 deletion tests/asconfig/entry-points/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"private": true,
"scripts": {
"test": "node ../index.js && cd nested && npm run test"
"test": "node ../index.js && npm run test:nested && npm run test:node",
"test:nested": "cd nested && npm run test",
"test:node": "cd node-resolution && npm run test"
}
}
4 changes: 3 additions & 1 deletion tests/asconfig/extends/asconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
}
},
"options": {
"enable": ["simd"]
"enable": ["simd"],
"runtime": "half",
"noEmit": false
},
"extends": "./extends.json"
}
8 changes: 8 additions & 0 deletions tests/asconfig/extends/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"options": {
"runtime": "half",
"noEmit": false,
"noAssert": true,
"enable": ["simd"]
}
}
4 changes: 3 additions & 1 deletion tests/asconfig/extends/extends.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
}
},
"options": {
"disable": ["simd"]
"disable": ["simd"],
"noEmit": true,
"noAssert": true
}
}
2 changes: 1 addition & 1 deletion tests/asconfig/extends/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": true,
"scripts": {
"test": "node ../index.js"
"test": "node ../index.js --showConfig && node ../index.js"
}
}
44 changes: 44 additions & 0 deletions tests/asconfig/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
const asc = require("../../cli/asc");
const loader = require("../../lib/loader");
const args = process.argv.slice(2);
const path = require('path');
const fs = require("fs");

/** @type {string} */
let stderr;
/** @type {Uint8Array} */
let binary;
asc.main(["assembly/index.ts", "--outFile", "output.wasm", "--explicitStart", ...args], {
Expand All @@ -11,13 +15,52 @@ asc.main(["assembly/index.ts", "--outFile", "output.wasm", "--explicitStart", ..
} else if (name !== "output.wasm.map") {
throw Error("Unexpected output file: " + name);
}
},
stderr: {
write(s) {
stderr = s;
}
}

}, (err) => {
if (err) {
console.error(err);
console.error(stderr);
process.exit(1);
}

const jsonPath = path.join(process.cwd(), "expected.json");
if (fs.existsSync(jsonPath) && stderr) {
const actualRes = JSON.parse(stderr);
const actual = actualRes.options;
const expected = require(jsonPath).options;
let errored = false;
for (let name of Object.getOwnPropertyNames(expected)) {
if (actual[name] !== expected[name]) {
// If object check just first level
if (typeof actual[name] === 'object' && typeof expected[name] === 'object') {
let error = false;
for (let field of Object.getOwnPropertyNames(actual[name])) {
if (actual[name][field] !== expected[name][field]) {
error = true;
break;
}
}
if (!error) {
continue;
}
}
console.error(name + ": " + actual[name] + " expected " + expected[name]);
errored = true;
}
}
if (errored) {
process.exit(1);
}
process.exit(0);
}


if (!binary) {
console.error("No binary was generated for the asconfig test in " + process.cwd());
process.exit(1);
Expand All @@ -29,6 +72,7 @@ asc.main(["assembly/index.ts", "--outFile", "output.wasm", "--explicitStart", ..
theModule.exports._start();
} catch (err) {
console.error("The wasm module _start() function failed in " + process.cwd());
console.error(err);
process.exit(1);
}
return 0;
Expand Down
5 changes: 3 additions & 2 deletions tests/asconfig/package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
{
"private": true,
"scripts": {
"test": "npm run test:use-consts && npm run test:target && npm run test:entry-points && npm run test:complicated",
"test": "npm run test:use-consts && npm run test:target && npm run test:entry-points && npm run test:complicated && npm run test:extends",
"test:use-consts": "cd use-consts && npm run test",
"test:entry-points": "cd entry-points && npm run test",
"test:respect-inheritence": "cd respect-inheritence && npm run test",
"test:target": "cd target && npm run test",
"test:cyclical": "cd cyclical && npm run test",
"test:complicated": "cd complicated && npm run test"
"test:complicated": "cd complicated && npm run test",
"test:extends": "cd extends && npm run test"
}
}
12 changes: 8 additions & 4 deletions tests/asconfig/target/asconfig.json
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
{
"targets": {
"release": {
"noAssert": true,
"runtime": "none"
},
"debug": {
"optimizeLevel": 3,
"shrinkLevel": 1,
"enable": ["simd"]
},
"dev": {
"enable": ["simd"],
"debug": true
}
},
"options": {}
"options": {
"runtime": "stub"
}
}
6 changes: 3 additions & 3 deletions tests/asconfig/target/assembly/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
assert(ASC_OPTIMIZE_LEVEL == 3);
assert(ASC_SHRINK_LEVEL == 1);
assert(ASC_FEATURE_SIMD);
assert(ASC_OPTIMIZE_LEVEL == 3, "expected optimize level == 3");
assert(ASC_SHRINK_LEVEL == 1, "expected shrink level == 1");
assert(ASC_FEATURE_SIMD, "expected SIMD enabled");
6 changes: 6 additions & 0 deletions tests/asconfig/target/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"options": {
"runtime": "none",
"noAssert": true
}
}
2 changes: 1 addition & 1 deletion tests/asconfig/target/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"private": true,
"scripts": {
"test": "node ../index.js"
"test": "node ../index.js --target debug && node ../index.js --showConfig"
}
}