Skip to content

Commit

Permalink
Modify script to accept "alias" test files for luajit
Browse files Browse the repository at this point in the history
Useful when the language implements non-Lua syntax constructs. The "alias"
file can be provided as an equivalent test file that use Lua syntax.
  • Loading branch information
franko committed Feb 25, 2016
1 parent 6f9247e commit fd9ed8b
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 4 deletions.
6 changes: 5 additions & 1 deletion scripts/test-bytecode-hex.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,12 @@ def do_process_output(cmd):
sf.close()
return s

def source_fullname_ref(fullname):
fullname_alias = re.sub(r'\.lua$', '.alias.lua', fullname)
return fullname_alias if os.path.isfile(fullname_alias) else fullname

def expected_bytecode(name, fullname):
subprocess.check_call([luajit_exec, "-bg", fullname, ".out.raw"])
subprocess.check_call([luajit_exec, "-bg", source_fullname_ref(fullname), ".out.raw"])
s = do_process_output([luajit_x, "-bx", ".out.raw"])
yield s, "luajit"
expect_dir = os.path.join("tests", "expect_hex")
Expand Down
7 changes: 6 additions & 1 deletion scripts/test-bytecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,13 @@ def do_process_output(cmd):
sf.close()
return s

def source_fullname_ref(fullname):
fullname_alias = re.sub(r'\.lua$', '.alias.lua', fullname)
return fullname_alias if os.path.isfile(fullname_alias) else fullname

def expected_bytecode(name, fullname):
s = do_process_output([luajit_exec, "-bl", fullname])
s = do_process_output([luajit_exec, "-bl", source_fullname_ref(fullname)])
s = re.sub(r'\.alias\.lua([^a-z])', r'.lua\1', s)
yield s, "luajit"
expect_dir = os.path.join("tests", "expect")
for expect_filename in glob(os.path.join(expect_dir, "*.txt")):
Expand Down
6 changes: 5 additions & 1 deletion scripts/test-luacode-output.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@
print "Please make sure that luajit executable is in the current PATH."
sys.exit(1)

def source_fullname_ref(fullname):
fullname_alias = re.sub(r'\.lua$', '.alias.lua', fullname)
return fullname_alias if os.path.isfile(fullname_alias) else fullname

for dirpath, dirnames, filenames in os.walk(test_dir):
for filename in sorted(filenames):
m = re.match(r'([^.]+)\.lua$', filename)
Expand All @@ -33,7 +37,7 @@
out_tst = subprocess.check_output([luajit_exec, "run.lua", "-c", fullname])
except subprocess.CalledProcessError:
run_error = True
out_ref = subprocess.check_output([luajit_exec, fullname])
out_ref = subprocess.check_output([luajit_exec, source_fullname_ref(fullname)])
led, msg = None, None
if run_error:
led, msg = "*", "fail to run"
Expand Down
6 changes: 5 additions & 1 deletion scripts/test-output.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@
print "Please make sure that luajit executable is in the current PATH."
sys.exit(1)

def source_fullname_ref(fullname):
fullname_alias = re.sub(r'\.lua$', '.alias.lua', fullname)
return fullname_alias if os.path.isfile(fullname_alias) else fullname

for dirpath, dirnames, filenames in os.walk(test_dir):
for filename in sorted(filenames):
m = re.match(r'([^.]+)\.lua$', filename)
Expand All @@ -34,7 +38,7 @@
out_tst = subprocess.check_output([luajit_x, fullname])
except subprocess.CalledProcessError:
run_error = True
out_ref = subprocess.check_output([luajit_exec, fullname])
out_ref = subprocess.check_output([luajit_exec, source_fullname_ref(fullname)])
led, msg = None, None
if run_error:
led, msg = "*", "fail to run"
Expand Down

0 comments on commit fd9ed8b

Please sign in to comment.