aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers/wasm_test.js
diff options
context:
space:
mode:
Diffstat (limited to 'tests/drivers/wasm_test.js')
-rw-r--r--tests/drivers/wasm_test.js28
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/drivers/wasm_test.js b/tests/drivers/wasm_test.js
new file mode 100644
index 0000000..ddab3be
--- /dev/null
+++ b/tests/drivers/wasm_test.js
@@ -0,0 +1,28 @@
+// runs programs on the webassembly build (src/web/zc.wasm) and compares with the expected output.
+// usage: node tests/drivers/wasm_test.js [path/to/zc.wasm]
+const fs = require('fs');
+const ZC = require('../../src/web/zc.js');
+(async () => {
+ const zc = await ZC.load(fs.readFileSync(process.argv[2] || __dirname + '/../../src/web/zc.wasm'));
+ const cases = [
+ ['examples/hello.zc', 'hello, world!'],
+ ['examples/fact.zc', '1101110101111100000000\n3628800\n'],
+ ['examples/selfpatch.zc', 'ABC'],
+ ['examples/lists.zc', '[0 1 4 9 16 25]\nlive: 7\nafter the block: 0\n'],
+ ['examples/wiring.zc', '16 1234 25 4/9'],
+ ['examples/struct_closure_opt.zc', '299\n'],
+ ['examples/opt_test.zc', '1303\n'],
+ ['tests/programs/basics.zc', '285 610 42 512\nhey 65 -3 -2 1024 -8\n12456\n757\n9 100-101\n5\nok\n'],
+ ];
+ let ok = 0, bad = 0;
+ for (const [file, want] of cases) {
+ const r = await zc.run(fs.readFileSync(__dirname + '/../../' + file, 'utf8'));
+ if (r.output.replace(/\n+$/, '') === want.replace(/\n+$/, '')) { ok++; console.log('ok wasm ' + file); }
+ else { bad++; console.log('FAIL wasm ' + file + ': got ' + JSON.stringify(r.output) + ' ' + r.messages); }
+ }
+ // an error is reported the way the interpreter reports it
+ const r = await zc.run('fn main() { return undefined_name; }');
+ if (/undefined_name/.test(r.output)) { ok++; console.log('ok wasm compiler errors'); } else { bad++; console.log('FAIL wasm compiler errors: ' + JSON.stringify(r.output)); }
+ console.log(ok + ' wasm checks passed, ' + bad + ' failed');
+ process.exit(bad ? 1 : 0);
+})();