aboutsummaryrefslogtreecommitdiff
path: root/test/dz_wasm.js
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2020-09-08 21:14:26 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2020-09-08 21:14:26 -0400
commit2ff502e46f9d7e6929059479da2e160d0cbbf5de (patch)
tree4bc056b8ffbdbd3e4f24cec4c7a68d8345b1bb07 /test/dz_wasm.js
parent176c78f51809ba3648d7a4cdedc78553df5904ae (diff)
Organize tests scripts a little better and add README
Diffstat (limited to 'test/dz_wasm.js')
-rwxr-xr-xtest/dz_wasm.js27
1 files changed, 27 insertions, 0 deletions
diff --git a/test/dz_wasm.js b/test/dz_wasm.js
new file mode 100755
index 00000000..b8faa668
--- /dev/null
+++ b/test/dz_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.bqn').split('\n').filter(x=>x).map(x=>x.split(' % '))
+ , test=t.map(e=>'"'+e[1]+'"').join('\n')
+ , expt=t.map(e=>+e[0])
+
+var compiler = execFile(
+ __dirname+'/../wcshim.bqn',
+ [ '{•←WCompile𝕩}¨⟨'+test+'⟩' ],
+ function (error, stdout, stderr) {
+ const rslt=stdout.split('\n').filter(a=>a.length)
+ .map(a=>runWasm(a.split("‿").map(n=>+n)))
+ , pass=rslt.map((r,i)=>r===expt[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))
+ }
+);