tests/run-tests: Make "regex'ed .exp" facility available to device tests.

Required to pass bytes_compare3.py (opptional warnings) on devices.
run-tests-regex
Paul Sokolovsky 2016-07-26 21:29:48 +03:00
parent f2f761c0c3
commit 5c89237c9f
1 changed files with 63 additions and 58 deletions

View File

@ -26,12 +26,35 @@ def rm_f(fname):
if os.path.exists(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):
special_tests = ('micropython/meminfo.py', 'basics/bytes_compare3.py')
is_special = False
if pyb is None:
# run on PC
if test_file.startswith(('cmdline/', 'feature_check/')) or test_file in special_tests:
# special handling for tests of the unix cmdline program
is_special = True
# check for any cmdline options needed for this test
args = [MICROPYTHON]
@ -81,25 +104,29 @@ def run_micropython(pyb, args, test_file):
except subprocess.CalledProcessError:
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:
cs.append(c)
# accept carriage-return(s) before final newline
if cs[-1] == '\n':
cs[-1] = '\r*\n'
return bytes(''.join(cs), 'utf8')
# 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')
if is_special or test_file in special_tests:
# convert parts of the output that are not stable across runs
with open(test_file + '.exp', 'rb') as f:
lines_exp = []
@ -138,28 +165,6 @@ def run_micropython(pyb, args, test_file):
break
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
def run_tests(pyb, tests, args):