powerline/tests/test_shells/test.sh

151 lines
3.4 KiB
Bash
Raw Normal View History

2014-07-19 23:49:30 +02:00
#!/bin/bash
2014-01-11 10:16:25 +01:00
FAILED=0
ONLY_SHELL="$1"
check_screen_log() {
SH="$1"
if test -e tests/test_shells/${SH}.ok ; then
diff -u tests/test_shells/${SH}.ok tests/shell/${SH}.log
2014-01-22 05:33:43 +01:00
return $?
else
cat tests/shell/${SH}.log
2014-01-22 05:33:43 +01:00
return 1
fi
}
2014-01-12 21:53:38 +01:00
run_test() {
SH="$1"
SESNAME="powerline-shell-test-${SH}-$$"
2014-07-19 23:49:30 +02:00
ARGS=( "$@" )
test "x$ONLY_SHELL" = "x" || test "x$ONLY_SHELL" = "x$SH" || return 0
2014-07-19 23:49:30 +02:00
if ! which "${SH}" ; then
if test "x${SH}" = "xbb" ; then
if ! which busybox ; then
return 0
fi
shift
ARGS=( busybox ash "$@" )
else
return 0
fi
fi
2014-01-23 15:33:33 +01:00
export SH
screen -L -c tests/test_shells/screenrc -d -m -S "$SESNAME" \
2014-07-19 23:49:30 +02:00
env LANG=en_US.UTF-8 BINDFILE="$BINDFILE" "${ARGS[@]}"
screen -S "$SESNAME" -X readreg a tests/test_shells/input.$SH
# Wait for screen to initialize
2014-07-19 23:49:30 +02:00
sleep 1
2014-01-12 21:53:38 +01:00
screen -S "$SESNAME" -p 0 -X width 300 1
2014-07-19 23:49:30 +02:00
if test "x${SH}" = "xdash" ; then
# If I do not use this hack for dash then output will look like
#
# command1
# command2
# …
# prompt1> prompt2> …
2014-07-19 23:49:30 +02:00
while read -r line ; do
screen -S "$SESNAME" -p 0 -X stuff "$line"$'\n'
sleep 1
done < tests/test_shells/input.$SH
else
screen -S "$SESNAME" -p 0 -X paste a
fi
# Wait for screen to exit (sending command to non-existing screen session
# fails; when launched instance exits corresponding session is deleted)
2014-01-12 21:53:38 +01:00
while screen -S "$SESNAME" -X blankerprg "" > /dev/null ; do
sleep 0.1s
2014-01-12 21:53:38 +01:00
done
./tests/test_shells/postproc.py ${SH}
if ! check_screen_log ${SH} ; then
echo '____________________________________________________________'
# Repeat the diff to make it better viewable in travis output
echo "Diff (cat -v):"
echo '============================================================'
check_screen_log ${SH} | cat -v
echo '____________________________________________________________'
echo "Failed ${SH}. Full output:"
echo '============================================================'
cat tests/shell/${SH}.full.log
echo '____________________________________________________________'
echo "Full output (cat -v):"
echo '============================================================'
cat -v tests/shell/${SH}.full.log
echo '____________________________________________________________'
2014-07-19 23:49:30 +02:00
case ${SH} in
*ksh)
${SH} -c 'echo ${KSH_VERSION}'
;;
dash)
# ?
;;
bb)
bb --help
;;
*)
${SH} --version
;;
esac
if which dpkg >/dev/null ; then
dpkg -s ${SH}
fi
2014-01-12 21:53:38 +01:00
return 1
fi
return 0
2014-01-11 10:36:02 +01:00
}
test -d tests/shell && rm -r tests/shell
2014-01-11 10:16:25 +01:00
mkdir tests/shell
git init tests/shell/3rd
git --git-dir=tests/shell/3rd/.git checkout -b BRANCH
2014-01-26 18:59:33 +01:00
export DIR1=""
export DIR2=""
mkdir tests/shell/3rd/"$DIR1"
mkdir tests/shell/3rd/"$DIR2"
mkdir tests/shell/3rd/'\[\]'
mkdir tests/shell/3rd/'%%'
mkdir tests/shell/3rd/'#[bold]'
mkdir tests/shell/3rd/'(echo)'
mkdir tests/shell/3rd/'$(echo)'
mkdir tests/shell/3rd/'`echo`'
2014-01-12 21:53:38 +01:00
if ! run_test bash --norc --noprofile -i ; then
2014-01-11 10:16:25 +01:00
FAILED=1
fi
2014-01-13 16:47:58 +01:00
if ! run_test zsh -f -i ; then
FAILED=1
fi
2014-01-22 05:33:43 +01:00
mkdir tests/shell/fish_home
export XDG_CONFIG_HOME="$PWD/tests/shell/fish_home"
2014-01-22 05:33:43 +01:00
if ! run_test fish -i ; then
FAILED=1
fi
2014-01-13 16:47:58 +01:00
2014-01-26 20:52:06 +01:00
if ! run_test tcsh -f -i ; then
FAILED=1
fi
2014-07-19 23:49:30 +02:00
if ! run_test bb -i ; then
FAILED=1
fi
unset ENV
if ! run_test mksh -i ; then
FAILED=1
fi
if ! run_test dash -i ; then
# dash tests are not stable, see #931
# FAILED=1
true
2014-07-19 23:49:30 +02:00
fi
test "x$ONLY_SHELL" = "x" && rm -r tests/shell
2014-01-11 10:16:25 +01:00
exit $FAILED