@@ -49,7 +49,7 @@ def runnable(command):
4949dart2js_runnable = runnable ( dart2js + ' -h' )
5050coffee_runnable = runnable ( "coffee -v" ) and '--all-backends' in sys .argv
5151lua_runnable = runnable ( "lua -v" ) and '--all-backends' in sys .argv
52- luajit_runnable = runnable ( "luajit -v" ) and '--all-backends' in sys . argv
52+ luajit_runnable = runnable ( "luajit -v" )
5353
5454lua2js = os .path .abspath ( '../external/lua.js/lua2js' )
5555luajs_runnable = os .path .isfile ( lua2js ) and '--all-backends' in sys .argv
@@ -98,6 +98,9 @@ def run_command(command, returns_stdout_stderr=False):
9898 sys .exit ()
9999 if returns_stdout_stderr :
100100 return stdout , stderr
101+
102+ #########################
103+
101104 if stdout :
102105 if show_details :
103106 print (stdout )
@@ -172,7 +175,7 @@ def TestWarning(file, line, result, test):
172175 print(file + ":" + str(line) + " Warning fail " + test)
173176"""
174177
175- def patch_python (filename , dart = False , python = 'PYTHONJS' ):
178+ def patch_python (filename , dart = False , python = 'PYTHONJS' , backend = None ):
176179 """Rewrite the Python code"""
177180 code = patch_assert (filename )
178181
@@ -191,10 +194,17 @@ def patch_python(filename, dart=False, python='PYTHONJS'):
191194 # else:
192195 # out.append( line )
193196 # code = '\n'.join( out )
194- if dart :
195- return '\n ' .join ( [_patch_header , 'PYTHON="%s"' % python , code ] )
196- else :
197- return '\n ' .join ( [_patch_header , 'PYTHON="%s"' % python , code , 'main()' ] )
197+ a = [
198+ _patch_header ,
199+ 'PYTHON="%s"' % python ,
200+ 'BACKEND="%s"' % backend ,
201+ code
202+ ]
203+
204+ if not dart :
205+ a .append ( 'main()' )
206+
207+ return '\n ' .join ( a )
198208
199209def run_python_test_on (filename ):
200210 """Python2"""
@@ -213,27 +223,33 @@ def run_pypy_test_on(filename):
213223
214224
215225def translate_js (filename , javascript = False , dart = False , coffee = False , lua = False , luajs = False ):
226+ global tmpname
227+ tmpname = os .path .join (
228+ tempfile .gettempdir (),
229+ 'test-%s-js=%s-dart=%s-lua=%s' % (filename .split ('/' )[- 1 ], javascript , dart , lua )
230+ )
231+
216232 output_name = "%s.py" % tmpname
217233 if javascript :
218- content = 'pythonjs.configure(javascript=True)\n ' + patch_python (filename )
234+ content = 'pythonjs.configure(javascript=True)\n ' + patch_python (filename , backend = 'JAVASCRIPT' )
219235 elif dart :
220236 source = [
221237 'pythonjs.configure(dart=True)' ,
222238 open ('../pythonjs/runtime/dart_builtins.py' , 'rb' ).read ().decode ('utf-8' ),
223- patch_python (filename , dart = True )
239+ patch_python (filename , dart = True , backend = 'DART' )
224240 ]
225241 content = '\n ' .join ( source )
226242 elif coffee :
227243 source = [
228244 'pythonjs.configure(coffee=True)' ,
229- patch_python (filename )
245+ patch_python (filename , backend = 'COFFEE' )
230246 ]
231247 content = '\n ' .join ( source )
232248 elif lua or luajs :
233249 source = [
234250 'pythonjs.configure(lua=True)' ,
235251 read ('../pythonjs/runtime/lua_builtins.py' ),
236- patch_python (filename )
252+ patch_python (filename , backend = 'LUA' )
237253 ]
238254 content = '\n ' .join ( source )
239255
@@ -363,11 +379,11 @@ def run_js_rhino(content):
363379 return run_command ("rhino -O -1 %s.js" % tmpname )
364380
365381def run_pythonjs_test_on_node (dummy_filename ):
366- """PythonJS (normal mode )"""
382+ """PythonJS (normal)"""
367383 return run_if_no_error (run_js_node )
368384
369385def run_pythonjsjs_test_on_node (filename ):
370- """PythonJS (fast mode )"""
386+ """PythonJS (fast backend )"""
371387 return run_pythonjs_test_on_node (filename )
372388
373389def run_js_node (content ):
@@ -380,7 +396,7 @@ def run_js_node(content):
380396 return run_command ("node %s.js" % tmpname )
381397
382398def run_pythonjs_dart_test_on_node (dummy_filename ):
383- """PythonJS (dart2js )"""
399+ """PythonJS (Dart backend )"""
384400 return run_if_no_error (run_dart2js_node )
385401
386402def run_dart2js_node (content ):
@@ -410,7 +426,7 @@ def run_lua_lua(content):
410426
411427
412428def run_pythonjs_lua_test_on_luajit (dummy_filename ):
413- """PythonJS (Lua) on LuaJIT"""
429+ """PythonJS (LuaJIT backend) """
414430 return run_if_no_error (run_lua_luajit )
415431
416432def run_lua_luajit (content ):
0 commit comments