Skip to content

Commit 487cee5

Browse files
vloppinkripken
authored andcommitted
Fix check.py on windows platform (#1605)
Fix some file reading & endline issues on windows platform.
1 parent 4730172 commit 487cee5

File tree

3 files changed

+8
-7
lines changed

3 files changed

+8
-7
lines changed

check.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ def run_wasm_opt_tests():
105105
actual = ''
106106
for module, asserts in split_wast(t):
107107
assert len(asserts) == 0
108-
with open('split.wast', 'w') as o:
108+
with open('split.wast', "wb" if binary else 'w') as o:
109109
o.write(module)
110110
cmd = WASM_OPT + opts + ['split.wast', '--print']
111111
curr = run_command(cmd)
@@ -139,12 +139,12 @@ def check():
139139
wasm = os.path.basename(t).replace('.wast', '')
140140
cmd = WASM_OPT + [os.path.join(options.binaryen_test, 'print', t), '--print']
141141
print ' ', ' '.join(cmd)
142-
actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
142+
actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).communicate()
143143
expected_file = os.path.join(options.binaryen_test, 'print', wasm + '.txt')
144144
fail_if_not_identical_to_file(actual, expected_file)
145145
cmd = WASM_OPT + [os.path.join(options.binaryen_test, 'print', t), '--print-minified']
146146
print ' ', ' '.join(cmd)
147-
actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE).communicate()
147+
actual, err = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True).communicate()
148148
fail_if_not_identical(actual.strip(), open(os.path.join(options.binaryen_test, 'print', wasm + '.minified.txt')).read().strip())
149149

150150
print '\n[ checking wasm-opt testcases... ]\n'

scripts/test/shared.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ def fail_if_not_contained(actual, expected):
312312

313313

314314
def fail_if_not_identical_to_file(actual, expected_file):
315-
with open(expected_file, 'rb') as f:
315+
with open(expected_file, 'rb' if expected_file.endswith(".wasm") else 'r') as f:
316316
fail_if_not_identical(actual, f.read(), fromfile=expected_file)
317317

318318

scripts/test/support.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,16 +87,17 @@ def untar(tarfile, outdir):
8787
shutil.rmtree(tmpdir)
8888

8989

90-
def split_wast(wast):
90+
def split_wast(wastFile):
9191
# .wast files can contain multiple modules, and assertions for each one.
9292
# this splits out a wast into [(module, assertions), ..]
9393
# we ignore module invalidity tests here.
94-
wast = open(wast).read()
94+
wast = open(wastFile, 'rb').read()
9595

9696
# if it's a binary, leave it as is
9797
if wast[0] == '\0':
9898
return [[wast, '']]
9999

100+
wast = open(wastFile, 'r').read()
100101
ret = []
101102

102103
def to_end(j):
@@ -152,7 +153,7 @@ def run_command(cmd, expected_status=0, stderr=None,
152153
"Can't redirect stderr if using expected_err"
153154
stderr = subprocess.PIPE
154155
print 'executing: ', ' '.join(cmd)
155-
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=stderr)
156+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=stderr, universal_newlines=True)
156157
out, err = proc.communicate()
157158
code = proc.returncode
158159
if code != expected_status:

0 commit comments

Comments
 (0)