From 5425c0647640f92b8472d02a84bdd8e70511300a Mon Sep 17 00:00:00 2001 From: ZyX Date: Sun, 20 Jul 2014 01:49:30 +0400 Subject: [PATCH] Add tests for new functionality --- tests/install.sh | 2 +- tests/test.sh | 2 +- tests/test_shells/bb.ok | 17 ++++++++++ tests/test_shells/dash.ok | 17 ++++++++++ tests/test_shells/input.bb | 23 ++++++++++++++ tests/test_shells/input.dash | 23 ++++++++++++++ tests/test_shells/input.mksh | 23 ++++++++++++++ tests/test_shells/mksh.ok | 19 ++++++++++++ tests/test_shells/test.sh | 60 ++++++++++++++++++++++++++++++++---- 9 files changed, 178 insertions(+), 8 deletions(-) create mode 100644 tests/test_shells/bb.ok create mode 100644 tests/test_shells/dash.ok create mode 100644 tests/test_shells/input.bb create mode 100644 tests/test_shells/input.dash create mode 100644 tests/test_shells/input.mksh create mode 100644 tests/test_shells/mksh.ok diff --git a/tests/install.sh b/tests/install.sh index 05d2e3d2..1f1a3729 100755 --- a/tests/install.sh +++ b/tests/install.sh @@ -12,7 +12,7 @@ if python -c 'import sys; sys.exit(1 * (sys.version_info[0] != 2))' ; then pip install unittest2 argparse fi fi -sudo apt-get install -qq screen zsh tcsh +sudo apt-get install -qq screen zsh tcsh mksh busybox # Travis has too outdated fish. It cannot be used for tests. # sudo apt-get install fish true diff --git a/tests/test.sh b/tests/test.sh index 5ea9d0ea..f25d63a6 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -20,7 +20,7 @@ for script in tests/*.vim ; do FAILED=1 fi done -if ! sh tests/test_shells/test.sh ; then +if ! bash tests/test_shells/test.sh ; then echo "Failed shells" if ${PYTHON} -c 'import platform, sys; sys.exit(1 * (platform.python_implementation() == "PyPy"))' ; then FAILED=1 diff --git a/tests/test_shells/bb.ok b/tests/test_shells/bb.ok new file mode 100644 index 00000000..8a439c05 --- /dev/null +++ b/tests/test_shells/bb.ok @@ -0,0 +1,17 @@ +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done' & +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s +[1]+ Terminated bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  cd "$DIR1" +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  `echo`  false diff --git a/tests/test_shells/dash.ok b/tests/test_shells/dash.ok new file mode 100644 index 00000000..2a42cd64 --- /dev/null +++ b/tests/test_shells/dash.ok @@ -0,0 +1,17 @@ +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done' & +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1s +[1] + Terminated bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" +cd "$DIR1" +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1    HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  `echo`  false diff --git a/tests/test_shells/input.bb b/tests/test_shells/input.bb new file mode 100644 index 00000000..d9ae1342 --- /dev/null +++ b/tests/test_shells/input.bb @@ -0,0 +1,23 @@ +POWERLINE_COMMAND="$PWD/scripts/powerline -p $PWD/powerline/config_files" +POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" +POWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" +export VIRTUAL_ENV= +. powerline/bindings/shell/powerline.sh ; cd tests/shell/3rd +cd .git +cd .. +VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +VIRTUAL_ENV= +bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done' & +false +kill `cat pid` ; sleep 1s +cd "$DIR1" +cd ../"$DIR2" +cd ../'\[\]' +cd ../'%%' +cd ../'#[bold]' +cd ../'(echo)' +cd ../'$(echo)' +cd ../'`echo`' +false +true is the last line +exit diff --git a/tests/test_shells/input.dash b/tests/test_shells/input.dash new file mode 100644 index 00000000..d9ae1342 --- /dev/null +++ b/tests/test_shells/input.dash @@ -0,0 +1,23 @@ +POWERLINE_COMMAND="$PWD/scripts/powerline -p $PWD/powerline/config_files" +POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" +POWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" +export VIRTUAL_ENV= +. powerline/bindings/shell/powerline.sh ; cd tests/shell/3rd +cd .git +cd .. +VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +VIRTUAL_ENV= +bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done' & +false +kill `cat pid` ; sleep 1s +cd "$DIR1" +cd ../"$DIR2" +cd ../'\[\]' +cd ../'%%' +cd ../'#[bold]' +cd ../'(echo)' +cd ../'$(echo)' +cd ../'`echo`' +false +true is the last line +exit diff --git a/tests/test_shells/input.mksh b/tests/test_shells/input.mksh new file mode 100644 index 00000000..a4a5928a --- /dev/null +++ b/tests/test_shells/input.mksh @@ -0,0 +1,23 @@ +POWERLINE_COMMAND="$PWD/scripts/powerline -p $PWD/powerline/config_files" +POWERLINE_COMMAND="$POWERLINE_COMMAND -t default_leftonly.segment_data.hostname.args.only_if_ssh=false" +POWERLINE_COMMAND="$POWERLINE_COMMAND -c ext.shell.theme=default_leftonly" +export VIRTUAL_ENV= +. powerline/bindings/shell/powerline.sh ; cd tests/shell/3rd +cd .git +cd .. +VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +VIRTUAL_ENV= +bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done' & +false +kill `cat pid` ; sleep 1 +cd "$DIR1" +cd ../"$DIR2" +cd ../'\[\]' +cd ../'%%' +cd ../'#[bold]' +cd ../'(echo)' +cd ../'$(echo)' +cd ../'`echo`' +false +true is the last line +exit diff --git a/tests/test_shells/mksh.ok b/tests/test_shells/mksh.ok new file mode 100644 index 00000000..f03a4c29 --- /dev/null +++ b/tests/test_shells/mksh.ok @@ -0,0 +1,19 @@ + +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd .git +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  .git  cd .. +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV="$HOME/.virtenvs/some-virtual-environment" +  HOSTNAME  USER  ⓔ  some-virtual-environment   BRANCH  ⋯  tests  shell  3rd  VIRTUAL_ENV= +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  bash -c 'echo $$>pid ; while true ; do sleep 0.1s ; done' & +[1] PID +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  false +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  1  1  kill `cat pid` ; sleep 1 +[1] + Terminated bash -c "echo \$\$>pid ; while true ; do sleep 0.1s ; done" +  HOSTNAME  USER   BRANCH  ⋯  tests  shell  3rd  cd "$DIR1" +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^[[32m  cd ../"$DIR2" +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  ^H  cd ../'\[\]' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  \[\]  cd ../'%%' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  %%  cd ../'#[bold]' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  #[bold]  cd ../'(echo)' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  (echo)  cd ../'$(echo)' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  $(echo)  cd ../'`echo`' +  HOSTNAME  USER   BRANCH  ⋯  shell  3rd  `echo`  false diff --git a/tests/test_shells/test.sh b/tests/test_shells/test.sh index 9e9c370b..69a34fc9 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -1,4 +1,4 @@ -#!/bin/sh +#!/bin/bash FAILED=0 ONLY_SHELL="$1" @@ -16,20 +16,38 @@ check_screen_log() { run_test() { SH="$1" SESNAME="powerline-shell-test-${SH}-$$" + ARGS=( "$@" ) test "x$ONLY_SHELL" = "x" || test "x$ONLY_SHELL" = "x$SH" || return 0 - which "${SH}" || return 0 + 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 export SH screen -L -c tests/test_shells/screenrc -d -m -S "$SESNAME" \ - env LANG=en_US.UTF-8 BINDFILE="$BINDFILE" "$@" + 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 - sleep 1s + sleep 1 screen -S "$SESNAME" -p 0 -X width 300 1 - screen -S "$SESNAME" -p 0 -X paste a + if test "x${SH}" = "xdash" ; then + 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) while screen -S "$SESNAME" -X blankerprg "" > /dev/null ; do @@ -51,7 +69,23 @@ run_test() { echo '============================================================' cat -v tests/shell/${SH}.full.log echo '____________________________________________________________' - ${SH} --version + 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 return 1 fi return 0 @@ -90,5 +124,19 @@ if ! run_test tcsh -f -i ; then FAILED=1 fi +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 + FAILED=1 +fi + test "x$ONLY_SHELL" = "x" && rm -r tests/shell exit $FAILED