summaryrefslogtreecommitdiff
path: root/scripts/test
diff options
context:
space:
mode:
authorDaniel Wirtz <dcode@dcode.io>2020-01-15 01:00:08 +0100
committerAlon Zakai <azakai@google.com>2020-01-14 16:00:08 -0800
commit5ca79a71b2a2379083093d4d9136b2ae4095dfe8 (patch)
tree80263fb09290b896362a36d3ae062ee6cb64fb8c /scripts/test
parenta43b533b0778a1daf47178a3d3d9e559f3d390ed (diff)
downloadbinaryen-5ca79a71b2a2379083093d4d9136b2ae4095dfe8.tar.gz
binaryen-5ca79a71b2a2379083093d4d9136b2ae4095dfe8.tar.bz2
binaryen-5ca79a71b2a2379083093d4d9136b2ae4095dfe8.zip
Align binaryen.js with the npm package (#2551)
Binaryen.js now uses binaryen (was Binaryen) as its global name to align with the npm package. Also fixes issues with emitting and testing both the JS and Wasm builds.
Diffstat (limited to 'scripts/test')
-rwxr-xr-xscripts/test/binaryenjs.py37
-rw-r--r--scripts/test/shared.py3
-rw-r--r--scripts/test/support.py16
3 files changed, 38 insertions, 18 deletions
diff --git a/scripts/test/binaryenjs.py b/scripts/test/binaryenjs.py
index 4f97ce889..43d039542 100755
--- a/scripts/test/binaryenjs.py
+++ b/scripts/test/binaryenjs.py
@@ -16,23 +16,24 @@
import os
import subprocess
+import sys
from . import shared
from . import support
-def test_binaryen_js():
+def do_test_binaryen_js_with(which):
if not (shared.MOZJS or shared.NODEJS):
print('no vm to run binaryen.js tests')
return
node_has_wasm = shared.NODEJS and support.node_has_webassembly(shared.NODEJS)
- if not os.path.exists(shared.BINARYEN_JS):
- print('no binaryen.js build to test')
+ if not os.path.exists(which):
+ print('no ' + which + ' build to test')
return
- print('\n[ checking binaryen.js testcases... ]\n')
+ print('\n[ checking binaryen.js testcases (' + which + ')... ]\n')
for s in sorted(os.listdir(os.path.join(shared.options.binaryen_test, 'binaryen.js'))):
if not s.endswith('.js'):
@@ -41,15 +42,13 @@ def test_binaryen_js():
f = open('a.js', 'w')
# avoid stdout/stderr ordering issues in some js shells - use just stdout
f.write('''
- console.warn = function(x) { console.log(x) };
+ console.warn = console.error = console.log;
''')
- binaryen_js = open(shared.BINARYEN_JS).read()
+ binaryen_js = open(which).read()
f.write(binaryen_js)
- if shared.NODEJS:
- f.write(support.node_test_glue())
test_path = os.path.join(shared.options.binaryen_test, 'binaryen.js', s)
test_src = open(test_path).read()
- f.write(test_src)
+ f.write(support.js_test_wrap().replace('%TEST%', test_src))
f.close()
def test(engine):
@@ -73,5 +72,23 @@ def test_binaryen_js():
print('Skipping ' + test_path + ' because WebAssembly might not be supported')
-if __name__ == "__main__":
+def test_binaryen_js():
+ do_test_binaryen_js_with(shared.BINARYEN_JS)
+
+
+def test_binaryen_wasm():
+ do_test_binaryen_js_with(shared.BINARYEN_WASM)
+
+
+def test_binaryen_js_and_wasm():
test_binaryen_js()
+ test_binaryen_wasm()
+
+
+if __name__ == "__main__":
+ if sys.argv[1] == "js":
+ test_binaryen_js()
+ elif sys.argv[1] == "wasm":
+ test_binaryen_wasm()
+ else:
+ test_binaryen_js_and_wasm()
diff --git a/scripts/test/shared.py b/scripts/test/shared.py
index 7bf944097..f15424885 100644
--- a/scripts/test/shared.py
+++ b/scripts/test/shared.py
@@ -184,7 +184,8 @@ WASM_REDUCE = [os.path.join(options.binaryen_bin, 'wasm-reduce')]
WASM_METADCE = [os.path.join(options.binaryen_bin, 'wasm-metadce')]
WASM_EMSCRIPTEN_FINALIZE = [os.path.join(options.binaryen_bin,
'wasm-emscripten-finalize')]
-BINARYEN_JS = os.path.join(options.binaryen_bin, 'binaryen.js')
+BINARYEN_JS = os.path.join(options.binaryen_bin, 'binaryen_js.js')
+BINARYEN_WASM = os.path.join(options.binaryen_bin, 'binaryen_wasm.js')
def wrap_with_valgrind(cmd):
diff --git a/scripts/test/support.py b/scripts/test/support.py
index 8f48a7af9..6eee79910 100644
--- a/scripts/test/support.py
+++ b/scripts/test/support.py
@@ -189,10 +189,12 @@ def node_has_webassembly(cmd):
return run_command(cmd) == 'object'
-def node_test_glue():
- # running concatenated files (a.js) in node interferes with module loading
- # because the concatenated file expects a 'var Binaryen' but binaryen.js
- # assigned to module.exports. this is correct behavior but tests then need
- # a workaround:
- return ('if (typeof module === "object" && typeof exports === "object")\n'
- ' Binaryen = module.exports;\n')
+def js_test_wrap():
+ # common wrapper code for JS tests, waiting for binaryen.js to become ready
+ # and providing common utility used by all tests:
+ return '''
+ binaryen.ready.then(function() {
+ function assert(x) { if (!x) throw Error('Test assertion failed'); }
+ %TEST%
+ });
+ '''