Ignore stderr from printf and env

socat may close pipe before they succeed to write something which results in

    env: write error: Broken pipe

(according to my experience leading printf’s always succeeds to write before
socat closes pipe).
This commit is contained in:
ZyX 2015-02-21 13:56:25 +03:00
parent 838a7c3b15
commit 8524ee35e7
3 changed files with 110 additions and 94 deletions

View File

@ -46,7 +46,7 @@ fi
done
printf '%s\0' "$PWD"
$ENV -0
) | socat -lf/dev/null -t 10 - "$ADDRESS"
) 2>/dev/null | socat -lf/dev/null -t 10 - "$ADDRESS"
if test $? -ne 0 ; then
powerline-render "$@"

104
tests/test_shells/run_script.py Executable file
View File

@ -0,0 +1,104 @@
#!/usr/bin/env python
# vim:fileencoding=utf-8:noet
from __future__ import (unicode_literals, division, absolute_import, print_function)
import argparse
import os
import re
from time import sleep
from subprocess import check_call
import pexpect
def get_argparser(ArgumentParser=argparse.ArgumentParser):
parser = ArgumentParser(description='Run powerline shell test using pexpect')
parser.add_argument('--wait-for-echo', action='store_true', help='Wait until the input is echoed back.')
parser.add_argument('--type', metavar='TYPE', help='Test type (daemon, nodaemon, …).')
parser.add_argument('--client', metavar='CLIENT', help='Type of the client used (C, shell, zpython, …).')
parser.add_argument('--shell', metavar='SHELL', help='Shell name.')
parser.add_argument('command', required=True, nargs=argparse.REMAINDER, metavar='COMMAND',
help='Command to run and its argument.')
return parser
def main():
parser = get_argparser()
args = parser.parse_args()
shell = args.shell or args.command[0]
test_type = args.test_type or shell
test_client = args.test_client or test_type
log_file_base = '{0}.{1}.{2}'.format(shell, test_type, test_client)
full_log_file_name = os.path.join('tests', 'shell', '{0}.full.log'.format(log_file_base))
# postproc_log_file_name = os.path.join('tests', 'shell', '{0}.log'.format(log_file_base))
local_paths = [
os.path.abspath(os.path.join('tests', 'shell', 'path')),
os.path.abspath('scripts'),
]
if test_type == 'fish':
local_paths += ['/usr/bin', '/bin']
python_paths = os.environ.get('PYTHONPATH', '')
if python_paths:
python_paths = ':' + python_paths
python_paths = os.path.abspath('.') + python_paths
environ = {
'LANG': 'en_US.UTF-8',
'PATH': os.pathsep.join(local_paths),
'TERM': 'screen-256color',
'DIR1': os.environ['DIR1'],
'DIR2': os.environ['DIR2'],
'XDG_CONFIG_HOME': os.path.abspath(os.path.join('tests', 'shell', 'fish_home')),
'IPYTHONDIR': os.path.abspath(os.path.join('tests', 'shell', 'ipython_home')),
'PYTHONPATH': python_paths,
'POWERLINE_CONFIG_OVERRIDES': os.environ.get('POWERLINE_CONFIG_OVERRIDES', ''),
'POWERLINE_THEME_OVERRIDES': os.environ.get('POWERLINE_THEME_OVERRIDES', ''),
'POWERLINE_CONFIG_PATHS': os.path.abspath(os.path.join('powerline', 'config_files')),
'POWERLINE_COMMAND_ARGS': os.environ.get('POWERLINE_COMMAND_ARGS', ''),
'POWERLINE_COMMAND': os.environ.get('POWERLINE_COMMAND', ''),
'LD_LIBRARY_PATH': os.environ.get('LD_LIBRARY_PATH', ''),
}
if test_type == 'daemon':
environ['POWERLINE_SHELL_CONTINUATION'] = '1'
environ['POWERLINE_SHELL_SELECT'] = '1'
child = pexpect.spawn(
args.command[0],
args.command[1:],
logfile=open(full_log_file_name),
env=environ,
)
child.expect(re.compile('.*'))
sleep(0.5)
child.setwinsize(1, 300)
with open(os.path.join('tests', 'test_shells', 'input.{0}'.format(shell)), 'rb') as F:
if not args.wait_for_echo:
child.send(F.read())
else:
for line in F:
child.send(line)
sleep(1)
# TODO Implement something more smart
child.wait()
check_call([
os.path.join('tests', 'shell', 'path', 'python'),
os.path.join('tests', 'test_shells', 'postproc.py'),
test_type, test_client, shell
])
pidfile = os.path.join('tests', 'shell', '3rd', 'pid')
if os.path.exists(pidfile):
os.unlink(pidfile)
if __name__ == '__main__':
main()

View File

@ -47,47 +47,6 @@ check_screen_log() {
fi
}
run() {
TEST_TYPE="$1"
shift
TEST_CLIENT="$1"
shift
SH="$1"
shift
local local_path="$PWD/tests/shell/path:$PWD/scripts"
if test "x$SH" = "xfish" ; then
local_path="${local_path}:/usr/bin:/bin"
fi
if test $TEST_TYPE = daemon ; then
local additional_prompts=1
else
local additional_prompts=
fi
env -i \
LANG=en_US.UTF-8 \
PATH="$local_path" \
TERM="screen-256color" \
COLUMNS="${COLUMNS}" \
LINES="${LINES}" \
TEST_TYPE="${TEST_TYPE}" \
TEST_CLIENT="${TEST_CLIENT}" \
SH="${SH}" \
DIR1="${DIR1}" \
POWERLINE_NO_ZSH_ZPYTHON="$(test $TEST_TYPE = zpython || echo 1)" \
DIR2="${DIR2}" \
XDG_CONFIG_HOME="$PWD/tests/shell/fish_home" \
IPYTHONDIR="$PWD/tests/shell/ipython_home" \
PYTHONPATH="${PWD}${PYTHONPATH:+:}$PYTHONPATH" \
POWERLINE_CONFIG_OVERRIDES="${POWERLINE_CONFIG_OVERRIDES}" \
POWERLINE_THEME_OVERRIDES="${POWERLINE_THEME_OVERRIDES}" \
POWERLINE_SHELL_CONTINUATION=$additional_prompts \
POWERLINE_SHELL_SELECT=$additional_prompts \
POWERLINE_CONFIG_PATHS="$PWD/powerline/config_files" \
POWERLINE_COMMAND_ARGS="${POWERLINE_COMMAND_ARGS}" \
POWERLINE_COMMAND="${POWERLINE_COMMAND}" \
"$@"
}
# HACK: get newline for use in strings given that "\n" and $'' do not work.
NL="$(printf '\nE')"
NL="${NL%E}"
@ -116,38 +75,8 @@ do_run_test() {
TEST_CLIENT="$1"
shift
SH="$1"
SESNAME="powerline-shell-test-${SH}-$$"
# Note: when running screen with setuid libc unsets LD_LIBRARY_PATH, so it
# cannot be added to the `env -i` call above.
run "${TEST_TYPE}" "${TEST_CLIENT}" "${SH}" \
screen -L -c tests/test_shells/screenrc -d -m -S "$SESNAME" \
env LD_LIBRARY_PATH="${LD_LIBRARY_PATH}" \
"$@"
local attempts=100
while ! screen -S "$SESNAME" -X readreg a tests/test_shells/input.$SH ; do
sleep 0.1s
attempts=$(( attempts - 1 ))
if test $attempts -eq 0 ; then
echo "Waiting for too long: assuming test failed"
echo "Failed ${SH}: failed to put input.$SH contents to the screen register."
print_full_output ${TEST_TYPE} ${TEST_CLIENT} ${SH}
return 1
fi
done
# Wait for screen to initialize
sleep 1
local attempts=100
while ! screen -S "$SESNAME" -p 0 -X width 300 1 >/dev/null ; do
sleep 0.1s
attempts=$(( attempts - 1 ))
if test $attempts -eq 0 ; then
echo "Waiting for too long: assuming test failed"
echo -n "Failed ${SH}. "
print_full_output ${TEST_TYPE} ${TEST_CLIENT} ${SH}
return 1
fi
done
local wait_for_echo_arg=
if ( \
test "x${SH}" = "xdash" \
|| ( \
@ -166,28 +95,11 @@ do_run_test() {
) \
) \
) ; then
# If I do not use this hack for dash then output will look like
#
# command1
# command2
# …
# prompt1> prompt2> …
while read -r line ; do
if test "$(screen -S "$SESNAME" -p 0 -X stuff "$line$NL")" = "No screen session found." ; then
break
fi
sleep 1
done < tests/test_shells/input.$SH
else
screen -S "$SESNAME" -p 0 -X paste a
wait_for_echo_arg="--wait-for-echo"
fi
# Wait for screen to exit (sending command to non-existing screen session
# fails; when launched instance exits corresponding session is deleted)
while screen -S "$SESNAME" -X blankerprg "" > /dev/null ; do
sleep 0.1s
done
${PYTHON} ./tests/test_shells/postproc.py ${TEST_TYPE} ${TEST_CLIENT} ${SH}
rm -f tests/shell/3rd/pid
"${PYTHON}" tests/test_shells/run_script.py \
$wait_for_echo_arg --type=${TEST_TYPE} --client=${TEST_CLIENT} --shell=${SH} \
"$@"
if ! check_screen_log ${TEST_TYPE} ${TEST_CLIENT} ${SH} ; then
echo '____________________________________________________________'
if test "x$POWERLINE_TEST_NO_CAT_V" != "x1" ; then