Compare commits
1 Commits
jebbatime
...
run-tests-
Author | SHA1 | Date |
---|---|---|
![]() |
5c89237c9f |
|
@ -26,12 +26,35 @@ def rm_f(fname):
|
||||||
if os.path.exists(fname):
|
if os.path.exists(fname):
|
||||||
os.remove(fname)
|
os.remove(fname)
|
||||||
|
|
||||||
|
|
||||||
|
# unescape wanted regex chars and escape unwanted ones
|
||||||
|
def convert_regex_escapes(line):
|
||||||
|
cs = []
|
||||||
|
escape = False
|
||||||
|
for c in str(line, 'utf8'):
|
||||||
|
if escape:
|
||||||
|
escape = False
|
||||||
|
cs.append(c)
|
||||||
|
elif c == '\\':
|
||||||
|
escape = True
|
||||||
|
elif c in ('(', ')', '[', ']', '{', '}', '.', '*', '+', '^', '$'):
|
||||||
|
cs.append('\\' + c)
|
||||||
|
else:
|
||||||
|
cs.append(c)
|
||||||
|
# accept carriage-return(s) before final newline
|
||||||
|
if cs[-1] == '\n':
|
||||||
|
cs[-1] = '\r*\n'
|
||||||
|
return bytes(''.join(cs), 'utf8')
|
||||||
|
|
||||||
|
|
||||||
def run_micropython(pyb, args, test_file):
|
def run_micropython(pyb, args, test_file):
|
||||||
special_tests = ('micropython/meminfo.py', 'basics/bytes_compare3.py')
|
special_tests = ('micropython/meminfo.py', 'basics/bytes_compare3.py')
|
||||||
|
is_special = False
|
||||||
if pyb is None:
|
if pyb is None:
|
||||||
# run on PC
|
# run on PC
|
||||||
if test_file.startswith(('cmdline/', 'feature_check/')) or test_file in special_tests:
|
if test_file.startswith(('cmdline/', 'feature_check/')) or test_file in special_tests:
|
||||||
# special handling for tests of the unix cmdline program
|
# special handling for tests of the unix cmdline program
|
||||||
|
is_special = True
|
||||||
|
|
||||||
# check for any cmdline options needed for this test
|
# check for any cmdline options needed for this test
|
||||||
args = [MICROPYTHON]
|
args = [MICROPYTHON]
|
||||||
|
@ -81,25 +104,29 @@ def run_micropython(pyb, args, test_file):
|
||||||
except subprocess.CalledProcessError:
|
except subprocess.CalledProcessError:
|
||||||
return b'CRASH'
|
return b'CRASH'
|
||||||
|
|
||||||
# unescape wanted regex chars and escape unwanted ones
|
|
||||||
def convert_regex_escapes(line):
|
|
||||||
cs = []
|
|
||||||
escape = False
|
|
||||||
for c in str(line, 'utf8'):
|
|
||||||
if escape:
|
|
||||||
escape = False
|
|
||||||
cs.append(c)
|
|
||||||
elif c == '\\':
|
|
||||||
escape = True
|
|
||||||
elif c in ('(', ')', '[', ']', '{', '}', '.', '*', '+', '^', '$'):
|
|
||||||
cs.append('\\' + c)
|
|
||||||
else:
|
else:
|
||||||
cs.append(c)
|
# a standard test
|
||||||
# accept carriage-return(s) before final newline
|
try:
|
||||||
if cs[-1] == '\n':
|
cmdlist = [MICROPYTHON, '-X', 'emit=' + args.emit]
|
||||||
cs[-1] = '\r*\n'
|
if args.heapsize is not None:
|
||||||
return bytes(''.join(cs), 'utf8')
|
cmdlist.extend(['-X', 'heapsize=' + args.heapsize])
|
||||||
|
cmdlist.append(test_file)
|
||||||
|
output_mupy = subprocess.check_output(cmdlist)
|
||||||
|
except subprocess.CalledProcessError:
|
||||||
|
output_mupy = b'CRASH'
|
||||||
|
else:
|
||||||
|
# run on pyboard
|
||||||
|
import pyboard
|
||||||
|
pyb.enter_raw_repl()
|
||||||
|
try:
|
||||||
|
output_mupy = pyb.execfile(test_file)
|
||||||
|
except pyboard.PyboardError:
|
||||||
|
output_mupy = b'CRASH'
|
||||||
|
|
||||||
|
# canonical form for all ports/platforms is to use \n for end-of-line
|
||||||
|
output_mupy = output_mupy.replace(b'\r\n', b'\n')
|
||||||
|
|
||||||
|
if is_special or test_file in special_tests:
|
||||||
# convert parts of the output that are not stable across runs
|
# convert parts of the output that are not stable across runs
|
||||||
with open(test_file + '.exp', 'rb') as f:
|
with open(test_file + '.exp', 'rb') as f:
|
||||||
lines_exp = []
|
lines_exp = []
|
||||||
|
@ -138,28 +165,6 @@ def run_micropython(pyb, args, test_file):
|
||||||
break
|
break
|
||||||
output_mupy = b''.join(lines_mupy)
|
output_mupy = b''.join(lines_mupy)
|
||||||
|
|
||||||
else:
|
|
||||||
# a standard test
|
|
||||||
try:
|
|
||||||
cmdlist = [MICROPYTHON, '-X', 'emit=' + args.emit]
|
|
||||||
if args.heapsize is not None:
|
|
||||||
cmdlist.extend(['-X', 'heapsize=' + args.heapsize])
|
|
||||||
cmdlist.append(test_file)
|
|
||||||
output_mupy = subprocess.check_output(cmdlist)
|
|
||||||
except subprocess.CalledProcessError:
|
|
||||||
output_mupy = b'CRASH'
|
|
||||||
else:
|
|
||||||
# run on pyboard
|
|
||||||
import pyboard
|
|
||||||
pyb.enter_raw_repl()
|
|
||||||
try:
|
|
||||||
output_mupy = pyb.execfile(test_file)
|
|
||||||
except pyboard.PyboardError:
|
|
||||||
output_mupy = b'CRASH'
|
|
||||||
|
|
||||||
# canonical form for all ports/platforms is to use \n for end-of-line
|
|
||||||
output_mupy = output_mupy.replace(b'\r\n', b'\n')
|
|
||||||
|
|
||||||
return output_mupy
|
return output_mupy
|
||||||
|
|
||||||
def run_tests(pyb, tests, args):
|
def run_tests(pyb, tests, args):
|
||||||
|
|
Loading…
Reference in New Issue