summaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
-rw-r--r--tests/cmdline/cmd_verbose.py3
-rw-r--r--tests/cmdline/cmd_verbose.py.exp21
-rw-r--r--tests/cmdline/repl_basic.py3
-rw-r--r--tests/cmdline/repl_basic.py.exp7
-rwxr-xr-xtests/run-tests46
5 files changed, 75 insertions, 5 deletions
diff --git a/tests/cmdline/cmd_verbose.py b/tests/cmdline/cmd_verbose.py
new file mode 100644
index 0000000000..b599a7aecb
--- /dev/null
+++ b/tests/cmdline/cmd_verbose.py
@@ -0,0 +1,3 @@
+# cmdline: -v -v
+# test verbose output
+print(1)
diff --git a/tests/cmdline/cmd_verbose.py.exp b/tests/cmdline/cmd_verbose.py.exp
new file mode 100644
index 0000000000..d7a8611805
--- /dev/null
+++ b/tests/cmdline/cmd_verbose.py.exp
@@ -0,0 +1,21 @@
+1
+File cmdline/cmd_verbose.py, code block '<module>' (descriptor: ######
+Raw bytecode (code_info_size=8, bytecode_size=13):
+ 08 82 23 83 45 43 00 00 02 00 00 1c 81 13 00 81
+ 64 01 32 11 5b
+arg names:
+(N_STATE 2)
+(N_EXC_STACK 0)
+(NUM_LOCAL 0)
+ bc=-3 line=1
+ bc=0 line=3
+00 LOAD_NAME print (cache=0)
+04 LOAD_CONST_SMALL_INT 1
+05 CALL_FUNCTION n=1 nkw=0
+07 POP_TOP
+08 LOAD_CONST_NONE
+09 RETURN_VALUE
+mem: total=######
+stack: ######
+GC: total: ######
+ No. of 1-blocks: ######
diff --git a/tests/cmdline/repl_basic.py b/tests/cmdline/repl_basic.py
new file mode 100644
index 0000000000..67d18cd577
--- /dev/null
+++ b/tests/cmdline/repl_basic.py
@@ -0,0 +1,3 @@
+# basic REPL tests
+print(1)
+OA
diff --git a/tests/cmdline/repl_basic.py.exp b/tests/cmdline/repl_basic.py.exp
new file mode 100644
index 0000000000..27732376a3
--- /dev/null
+++ b/tests/cmdline/repl_basic.py.exp
@@ -0,0 +1,7 @@
+Micro Python ######
+>>> # basic REPL tests
+>>> print(1)
+1
+>>> print(1)
+1
+>>>
diff --git a/tests/run-tests b/tests/run-tests
index e83f434210..a4044a65cc 100755
--- a/tests/run-tests
+++ b/tests/run-tests
@@ -28,10 +28,46 @@ def rm_f(fname):
def run_micropython(pyb, args, test_file):
if pyb is None:
# run on PC
- try:
- output_mupy = subprocess.check_output([MICROPYTHON, '-X', 'emit=' + args.emit, test_file])
- except subprocess.CalledProcessError:
- output_mupy = b'CRASH'
+ if test_file.startswith('cmdline/'):
+ # special handling for tests of the unix cmdline program
+
+ # check for any cmdline options needed for this test
+ args = [MICROPYTHON]
+ with open(test_file, 'rb') as f:
+ line = f.readline()
+ if line.startswith(b'# cmdline:'):
+ args += line[10:].strip().split()
+
+ # run the test, possibly with redirected input
+ try:
+ if test_file.startswith('cmdline/repl_'):
+ f = open(test_file, 'rb')
+ output_mupy = subprocess.check_output(args, stdin=f)
+ f.close()
+ else:
+ output_mupy = subprocess.check_output(args + [test_file])
+ except subprocess.CalledProcessError:
+ output_mupy = b'CRASH'
+
+ # erase parts of the output that are not stable across runs
+ with open(test_file + '.exp', 'rb') as f:
+ lines_exp = f.readlines()
+ lines_mupy = [line + b'\n' for line in output_mupy.split(b'\n')]
+ if output_mupy.endswith(b'\n'):
+ lines_mupy = lines_mupy[:-1] # remove erroneous last empty line
+ if len(lines_mupy) == len(lines_exp):
+ for i in range(len(lines_mupy)):
+ pos = lines_exp[i].find(b'######')
+ if pos != -1 and len(lines_mupy[i]) >= pos:
+ lines_mupy[i] = lines_mupy[i][:pos] + b'######\n'
+ output_mupy = b''.join(lines_mupy)
+
+ else:
+ # a standard test
+ try:
+ output_mupy = subprocess.check_output([MICROPYTHON, '-X', 'emit=' + args.emit, test_file])
+ except subprocess.CalledProcessError:
+ output_mupy = b'CRASH'
else:
# run on pyboard
import pyboard
@@ -186,7 +222,7 @@ def main():
if args.test_dirs is None:
if pyb is None:
# run PC tests
- test_dirs = ('basics', 'micropython', 'float', 'import', 'io', 'misc', 'unicode', 'extmod', 'unix')
+ test_dirs = ('basics', 'micropython', 'float', 'import', 'io', 'misc', 'unicode', 'extmod', 'unix', 'cmdline')
else:
# run pyboard tests
test_dirs = ('basics', 'micropython', 'float', 'misc', 'extmod', 'pyb', 'pybnative', 'inlineasm')