Skip to content

Commit

Permalink
Fix tests scripts to work correctly on Windows
Browse files Browse the repository at this point in the history
Tested using python2 from mingw32 package family in msys2.
  • Loading branch information
franko committed May 21, 2020
1 parent ca5fef2 commit 6a9fc6d
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 1 deletion.
9 changes: 8 additions & 1 deletion scripts/test-bytecode-hex.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
luajit_x = os.path.join(build_dir, "src/luajit-x")
diff_exec = "diff"

windows_os = (os.name == 'nt')

def lua_files(test_dir):
for dirpath, dirnames, filenames in os.walk(test_dir):
for filename in sorted(filenames):
Expand All @@ -26,7 +28,9 @@ def lua_files(test_dir):
def do_process(cmd, dst):
src = subprocess.Popen(cmd, stdout = subprocess.PIPE).stdout
for line in src:
dst.write(re.sub(r'\x0d', '', line))
if windows_os:
line = line.replace('\r\n', '\n')
dst.write(line)

def do_process_output(cmd):
sf = StringIO.StringIO()
Expand Down Expand Up @@ -67,6 +71,8 @@ def write_diff(a, b, a_name, b_name):
bf.close()

diff_output = subprocess.Popen([diff_exec, "-U", "4", fna, fnb], stdout=subprocess.PIPE).communicate()[0]
if windows_os:
diff_output = diff_output.replace('\r\n', '\n')
diff_file = open("tests/log/%s.%s.diff" % (a_name, b_name), "w")
diff_file.write(diff_output)
diff_file.close()
Expand Down Expand Up @@ -107,3 +113,4 @@ def compare_to_ref(name, fullname, output_test):
msg_ext = "%s / %s" % (msg, source) if source and source != "luajit" else msg

print("%s %-24s%s" % (led, name, msg_ext))
sys.stdout.flush()
6 changes: 6 additions & 0 deletions scripts/test-bytecode.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
luajit_x = os.path.join(build_dir, "src/luajit-x")
diff_exec = "diff"

windows_os = (os.name == 'nt')

def lua_files(test_dir):
for dirpath, dirnames, filenames in os.walk(test_dir):
for filename in sorted(filenames):
Expand Down Expand Up @@ -62,6 +64,7 @@ def parse(bcfile, outfile):
for line in bcfile:
m = re.match(r'-- BYTECODE -- ', line)
if m:
if windows_os: line = line.replace('\r\n', '\n')
outfile.write(line)
normalize(proto_lines(bcfile), outfile)

Expand Down Expand Up @@ -108,6 +111,8 @@ def write_diff(a, b, a_name, b_name):
bf.close()

diff_output = subprocess.Popen([diff_exec, "-U", "4", fna, fnb], stdout=subprocess.PIPE).communicate()[0]
if windows_os:
diff_output = diff_output.replace('\r\n', '\n')
diff_file = open("tests/log/%s.%s.diff" % (a_name, b_name), "w")
diff_file.write(diff_output)
diff_file.close()
Expand Down Expand Up @@ -148,3 +153,4 @@ def compare_to_ref(name, fullname, output_test):
msg_ext = "%s / %s" % (msg, source) if source and source != "luajit" else msg

print("%s %-24s%s" % (led, name, msg_ext))
sys.stdout.flush()
1 change: 1 addition & 0 deletions scripts/test-output.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,4 @@ def source_fullname_ref(fullname):
log.close()

print("%s %-24s %s" % (led, test_name, msg))
sys.stdout.flush()

0 comments on commit 6a9fc6d

Please sign in to comment.