Skip to content

Commit

Permalink
Run Imp/Wasm tests on NodeJS
Browse files Browse the repository at this point in the history
  • Loading branch information
pkel authored and jeromesimeon committed Apr 28, 2022
1 parent cee41d9 commit 865228d
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ cleanall: Makefile.coq remove_all_derived
install-coqdev:
@$(MAKE) -f Makefile.coq install

install-local:
install-local:
@$(MAKE) install-ocaml
ifneq ($(JAVASCRIPT),)
@$(MAKE) install-javascript
Expand Down
35 changes: 22 additions & 13 deletions runtimes/assemblyscript/cli-runner.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,40 @@
'use strict';

const _ = require('lodash');
const fs = require('fs');
const engine = require('./lib/engine.js');

async function main(runtime, module, input, expected) {
console.log("invoke:");
console.log({runtime, module, input, expected});
let rt = fs.readFileSync(runtime);
let mod = fs.readFileSync(module);
let arg = JSON.parse(fs.readFileSync(input));
console.log("input:");
console.log(arg);
let exp = JSON.parse(fs.readFileSync(expected));
console.log("expected:");
console.log(JSON.stringify(exp, null, 2));
let res;
let err;
try {
res = await engine.invoke(rt, mod, "qcert_main", arg);
} catch(err) {
console.log("error:");
console.log(err);
res = {
"error": "Eval failed"
};
err = err;
res = { "error": "Eval failed" }
}
if (! _.isEqual(res, exp)) {
console.log("TEST FAILED");
console.log("arguments:");
console.log({runtime, module, input, expected});
console.log("input:");
console.log(arg);
console.log("expected output:");
console.log(JSON.stringify(exp, null, 2));
if (err) {
console.log("exception:");
console.log(err);
process.exit(2);
} else {
console.log("output:");
console.log(JSON.stringify(res, null, 2));
process.exit(1)
}
}
console.log("output:");
console.log(JSON.stringify(res, null, 2));
}

const rt = process.argv[2];
Expand Down
12 changes: 12 additions & 0 deletions runtimes/assemblyscript/package-lock.json

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

3 changes: 2 additions & 1 deletion runtimes/assemblyscript/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@
"asbuild": "npm run asbuild:untouched && npm run asbuild:optimized"
},
"author": "",
"license": "ISC",
"license": "Apache-2.0",
"dependencies": {
"@assemblyscript/loader": "0.0.0"
},
"devDependencies": {
"assemblyscript": "^0.12.5",
"assemblyscript-regex": "^1.6.3",
"lodash": "^4.17.15",
"chai": "^4.2.0",
"mocha": "^8.0.1"
}
Expand Down
7 changes: 4 additions & 3 deletions tests/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -495,7 +495,7 @@ imp_ejson-tests:
@$(MAKE) imp_ejson-wasm-spec-tests
ifneq ($(JAVASCRIPT),)
@$(MAKE) imp_ejson-js-tests
# @$(MAKE) imp_ejson-wasm-node-tests # TODO. Improve test and enable
@$(MAKE) imp_ejson-wasm-node-tests
endif

# imp_ejson -> wasm ; run on spec interpreter
Expand Down Expand Up @@ -538,10 +538,11 @@ imp_ejson-js-tests:
--eval-validate \
--query imp_ejson/wasm$(N).js || exit 1; )

IMPEJSONWASMNODENUM=0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
IMPEJSONWASMNODENUM=0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21

# imp_ejson -> wasm ; run on node
imp_ejson-wasm-node-tests:
cd ../runtimes/assemblyscript/ && npm install
$(foreach N,$(IMPEJSONWASMNODENUM), \
$(QCERTCOMP) imp_ejson/wasm$(N).imp_ejson \
-source imp_ejson -path imp_ejson -target imp_ejson \
Expand All @@ -553,7 +554,7 @@ imp_ejson-wasm-node-tests:
-source imp_ejson -target wasm \
-schema imp_ejson/wasm.schema && \
$(NODERUN) ../runtimes/assemblyscript/cli-runner.js \
../runtimes/assemblyscript/build/untouched.wasm \
../runtimes/assemblyscript/runtime.wasm \
imp_ejson/wasm$(N).wasm \
imp_ejson/wasm.input \
imp_ejson/wasm$(N)_imp_ejson.json || exit 1; )
Expand Down

0 comments on commit 865228d

Please sign in to comment.