diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-11-01 16:51:04 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-11-01 16:51:04 -0400 |
| commit | 93217d7cce249854248ce68d455705253cf63a65 (patch) | |
| tree | aad94c9b71d94247c6c31c171a044895b3171701 /test/wasm.js | |
| parent | d827ec77a2a53f4b99455b0512c7b2fd237d353c (diff) | |
Clean up test directory structure
Diffstat (limited to 'test/wasm.js')
| -rwxr-xr-x | test/wasm.js | 27 |
1 files changed, 27 insertions, 0 deletions
diff --git a/test/wasm.js b/test/wasm.js new file mode 100755 index 00000000..b1afa586 --- /dev/null +++ b/test/wasm.js @@ -0,0 +1,27 @@ +#! /usr/bin/env node + +const execFile = require('child_process').execFile + , load=f=>require('fs').readFileSync(__dirname+'/'+f,'utf8') + , runWasm=w=>new WebAssembly.Instance(new WebAssembly.Module(Uint8Array.from(w))) + .exports.fn() + +const t=load('cases/simple.bqn').split('\n').filter(x=>x).map(x=>x.split(' % ')) + , test=t.map(e=> e[1]) + , expt=t.map(e=>+e[0]) + +var compiler = execFile( + __dirname+'/../wc.bqn', + test, + function (error, stdout, stderr) { + const rslt=stdout.split('\n').filter(a=>a.length) + .map(a=>runWasm(a.split(" ").map(n=>+n))) + , pass=expt.map((e,i)=>e===rslt[i]) + , fail=pass.map((p,i)=>p?-1:i).filter(i=>i>=0) + console.log( + fail.length + ? fail.map(i=>'"'+t[i][1]+'": expected '+expt[i]+' but received '+rslt[i]) + : "All passed!" + ) + process.exit(+(fail.length>0)) + } +); |
