diff --git a/tests/run_shell_tests.sh b/tests/run_shell_tests.sh index 08655312..4fce28f5 100755 --- a/tests/run_shell_tests.sh +++ b/tests/run_shell_tests.sh @@ -2,8 +2,6 @@ FAILED=0 if ! sh tests/test_shells/test.sh --fast ; then echo "Failed shells" - if ${PYTHON} -c 'import platform, sys; sys.exit(1 * (platform.python_implementation() == "PyPy"))' ; then - FAILED=1 - fi + FAILED=1 fi exit $FAILED diff --git a/tests/test_shells/postproc.py b/tests/test_shells/postproc.py index 71e79f9e..3ef35972 100755 --- a/tests/test_shells/postproc.py +++ b/tests/test_shells/postproc.py @@ -6,6 +6,8 @@ import os import socket import sys import codecs +import platform +import re test_type = sys.argv[1] @@ -15,6 +17,8 @@ fname = os.path.join('tests', 'shell', '.'.join((shell, test_type, test_client, new_fname = os.path.join('tests', 'shell', '.'.join((shell, test_type, test_client, 'log'))) pid_fname = os.path.join('tests', 'shell', '3rd', 'pid') +is_pypy = platform.python_implementation() == 'PyPy' + try: with open(pid_fname, 'r') as P: @@ -24,6 +28,8 @@ except IOError: hostname = socket.gethostname() user = os.environ['USER'] +IPYPY_DEANSI_RE = re.compile(r'\033(?:\[(?:\?\d+[lh]|[^a-zA-Z]+[a-ln-zA-Z])|[=>])') + with codecs.open(fname, 'r', encoding='utf-8') as R: with codecs.open(new_fname, 'w', encoding='utf-8') as W: found_cd = False @@ -68,4 +74,25 @@ with codecs.open(fname, 'r', encoding='utf-8') as R: # after the next line if line.startswith('[1] + Terminated'): continue + elif shell == 'ipython' and is_pypy: + try: + end_idx = line.rindex('\033[0m') + try: + idx = line[:end_idx].rindex('\033[1;1H') + except ValueError: + idx = line[:end_idx].rindex('\033[?25h') + line = line[idx + len('\033[1;1H'):] + except ValueError: + pass + try: + data_end_idx = line.rindex('\033[1;1H') + line = line[:data_end_idx] + '\n' + except ValueError: + pass + if line == '\033[1;1H\n': + continue + was_empty = line == '\n' + line = IPYPY_DEANSI_RE.subn('', line)[0] + if line == '\n' and not was_empty: + line = '' W.write(line) diff --git a/tests/test_shells/test.sh b/tests/test_shells/test.sh index 8d68a06d..275fa9c5 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -102,7 +102,13 @@ run_test() { while ! screen -S "$SESNAME" -p 0 -X width 300 1 ; do sleep 0.1s done - if test "x${SH}" = "xdash" ; then + if ( \ + test "x${SH}" = "xdash" || + ( \ + test "x${SH}" = "xipython" \ + && ${PYTHON} -c 'import platform, sys; sys.exit(1 - (platform.python_implementation() == "PyPy"))' \ + ) \ + ) ; then # If I do not use this hack for dash then output will look like # # command1 @@ -121,7 +127,7 @@ run_test() { while screen -S "$SESNAME" -X blankerprg "" > /dev/null ; do sleep 0.1s done - ./tests/test_shells/postproc.py ${TEST_TYPE} ${TEST_CLIENT} ${SH} + ${PYTHON} ./tests/test_shells/postproc.py ${TEST_TYPE} ${TEST_CLIENT} ${SH} rm -f tests/shell/3rd/pid if ! check_screen_log ${TEST_TYPE} ${TEST_CLIENT} ${SH} ; then echo '____________________________________________________________'