diff options
Diffstat (limited to 'tests')
-rw-r--r-- | tests/runner.py | 45 |
1 files changed, 43 insertions, 2 deletions
diff --git a/tests/runner.py b/tests/runner.py index 88a79c73..beef1823 100644 --- a/tests/runner.py +++ b/tests/runner.py @@ -29,6 +29,7 @@ NAMESPACER = path_from_root('tools', 'namespacer.py') EMMAKEN = path_from_root('tools', 'emmaken.py') AUTODEBUGGER = path_from_root('tools', 'autodebugger.py') DFE = path_from_root('tools', 'dead_function_eliminator.py') +BINDINGS_GENERATOR = path_from_root('tools', 'bindings_generator.py') # Global cache for tests (we have multiple TestCase instances; this object lets them share data) @@ -1645,7 +1646,6 @@ if 'benchmark' not in sys.argv: expected = open(path_from_root('tests', 'time', 'output.txt'), 'r').read() self.do_test(src, expected) - def test_statics(self): # static initializers save i16 but load i8 for some reason global COMPILER_TEST_OPTS; COMPILER_TEST_OPTS = ['-g'] @@ -2565,7 +2565,7 @@ if 'benchmark' not in sys.argv: ### Integration tests def test_scriptaclass(self): - src = ''' + header = ''' struct ScriptMe { int value; ScriptMe(int val); @@ -2574,10 +2574,20 @@ if 'benchmark' not in sys.argv: // as a library) void mulVal(int mul); }; + ''' + header_filename = os.path.join(self.get_dir(), 'header.h') + open(header_filename, 'w').write(header) + + src = ''' + #include "header.h" + ScriptMe::ScriptMe(int val) : value(val) { } int ScriptMe::getVal() { return value; } void ScriptMe::mulVal(int mul) { value *= mul; } ''' + + # Way 1: use demangler and namespacer + script_src = ''' var sme = Module._.ScriptMe.__new__(83); // malloc(sizeof(ScriptMe)), ScriptMe::ScriptMe(sme, 83) / new ScriptMe(83) (at addr sme) Module._.ScriptMe.mulVal(sme, 2); // ScriptMe::mulVal(sme, 2) sme.mulVal(2) @@ -2596,6 +2606,37 @@ if 'benchmark' not in sys.argv: open(filename, 'w').write(src) self.do_test(src, '*166*\n*ok*', post_build=post) + # Way 2: use CppHeaderParser + + basename = os.path.join(self.get_dir(), 'bindingtest') + Popen(['python', BINDINGS_GENERATOR, basename, header_filename], stdout=PIPE, stderr=STDOUT).communicate()[0] + + src = ''' + #include "header.h" + + ScriptMe::ScriptMe(int val) : value(val) { } + int ScriptMe::getVal() { return value; } + void ScriptMe::mulVal(int mul) { value *= mul; } + + #include "bindingtest.c" + ''' + + script_src_2 = ''' + var sme = new ScriptMe(83); + sme.mulVal(2); + print('*' + sme.getVal() + '*'); + print('*ok*'); + ''' + + def post2(filename): + src = open(filename, 'r').read().replace( + '// {{MODULE_ADDITIONS}', + '''load('bindingtest.js')''' + '\n\n' + script_src_2 + '\n\n' + + '// {{MODULE_ADDITIONS}' + ) + open(filename, 'w').write(src) + self.do_test(src, '*166*\n*ok*', post_build=post2) + ### Tests for tools def test_safe_heap(self): |