From 1303cd1b04984ae1fa1df80557f526dd6c49ef19 Mon Sep 17 00:00:00 2001 From: Foo Date: Sun, 30 Apr 2017 22:36:00 +0300 Subject: [PATCH] Move tests/run_*_tests.sh to tests/test_*/test.sh Warning: this also makes shell tests run. --- tests/run_daemon_tests.sh | 40 ------------------ tests/run_shell_tests.sh | 8 ---- tests/shlib/common.sh | 10 +++++ tests/test.sh | 13 +----- .../test.sh} | 8 +--- tests/{run_bar_tests.sh => test_bar/test.sh} | 8 +--- tests/test_daemon/test.sh | 41 +++++++++++++++++++ .../test.sh} | 4 +- .../{run_lint_tests.sh => test_lint/test.sh} | 2 +- .../test.sh} | 4 +- tests/test_shells/test.sh | 7 +--- tests/{run_vim_tests.sh => test_vim/test.sh} | 0 12 files changed, 60 insertions(+), 85 deletions(-) delete mode 100755 tests/run_daemon_tests.sh delete mode 100755 tests/run_shell_tests.sh rename tests/{run_awesome_tests.sh => test_awesome/test.sh} (97%) rename tests/{run_bar_tests.sh => test_bar/test.sh} (97%) create mode 100755 tests/test_daemon/test.sh rename tests/{run_vterm_tests.sh => test_in_vterm/test.sh} (68%) rename tests/{run_lint_tests.sh => test_lint/test.sh} (56%) rename tests/{run_python_tests.sh => test_python/test.sh} (61%) rename tests/{run_vim_tests.sh => test_vim/test.sh} (100%) diff --git a/tests/run_daemon_tests.sh b/tests/run_daemon_tests.sh deleted file mode 100755 index 45aaff9f..00000000 --- a/tests/run_daemon_tests.sh +++ /dev/null @@ -1,40 +0,0 @@ -#!/bin/sh -. tests/shlib/common.sh - -enter_suite daemon - -export ADDRESS="powerline-ipc-test-$$" -echo "Powerline address: $ADDRESS" -if $PYTHON scripts/powerline-daemon -s$ADDRESS ; then - sleep 1 - if ! ( \ - $PYTHON client/powerline.py --socket $ADDRESS -p/dev/null shell left | \ - grep 'file not found' - ) ; then - fail "devnull" F "-p/dev/null argument ignored or not treated properly" - fi - if ( \ - $PYTHON client/powerline.py --socket $ADDRESS \ - -p$PWD/powerline/config_files shell left | \ - grep 'file not found' - ) ; then - fail "nodevnull" F "-p/dev/null argument remembered while it should not" - fi - if ! ( \ - cd tests && \ - $PYTHON ../client/powerline.py --socket $ADDRESS \ - -p$PWD/../powerline/config_files shell left | \ - grep 'tests' - ) ; then - fail "segment" F "Output lacks string “tests”" - fi -else - fail "exitcode" E "Daemon exited with status $?" -fi -if $PYTHON scripts/powerline-daemon -s$ADDRESS -k ; then - : -else - fail "-k" F "powerline-daemon -k failed with exit code $?" -fi - -exit_suite diff --git a/tests/run_shell_tests.sh b/tests/run_shell_tests.sh deleted file mode 100755 index 29e6fac7..00000000 --- a/tests/run_shell_tests.sh +++ /dev/null @@ -1,8 +0,0 @@ -#!/bin/sh -exit 0 -FAILED=0 -if ! sh tests/test_shells/test.sh --fast ; then - echo "Failed shells" - FAILED=1 -fi -exit $FAILED diff --git a/tests/shlib/common.sh b/tests/shlib/common.sh index 7cba9b57..6fae3603 100644 --- a/tests/shlib/common.sh +++ b/tests/shlib/common.sh @@ -2,6 +2,10 @@ set +x : ${PYTHON:=python} +: ${USER:=`id -un`} +: ${HOME:=`getent passwd $USER | cut -d: -f6`} + +export USER HOME if test -z "$FAILED" ; then FAILED=0 @@ -69,3 +73,9 @@ rm_tmp_dir() { rm -r "$TMP_ROOT" fi } + +if ! which realpath ; then + realpath() { + $PYTHON -c 'import os, sys; print(os.path.realpath(sys.argv[1]))' "$1" + } +fi diff --git a/tests/test.sh b/tests/test.sh index 5a383f9d..5d86cbca 100755 --- a/tests/test.sh +++ b/tests/test.sh @@ -3,11 +3,6 @@ enter_suite root -: ${USER:=`id -un`} -: ${HOME:=`getent passwd $USER | cut -d: -f6`} - -export USER HOME - if test "$TRAVIS" = true ; then export PATH="$HOME/opt/fish/bin:${PATH}" export PATH="$PWD/tests/bot-ci/deps/rc:$PATH" @@ -25,15 +20,9 @@ if test "$TRAVIS" = true ; then fi fi -if ! which realpath ; then - realpath() { - $PYTHON -c 'import os, sys; print(os.path.realpath(sys.argv[1]))' "$1" - } -fi - export PYTHON="${PYTHON:=python}" export PYTHONPATH="${PYTHONPATH}${PYTHONPATH:+:}`realpath .`" -for script in tests/run_*_tests.sh ; do +for script in "$ROOT"/tests/test_*/test.sh ; do test_name="${script##*/run_}" if ! sh $script ; then fail "${test_name%_tests.sh}" F "Failed $script" diff --git a/tests/run_awesome_tests.sh b/tests/test_awesome/test.sh similarity index 97% rename from tests/run_awesome_tests.sh rename to tests/test_awesome/test.sh index e6dd29e0..8c883645 100755 --- a/tests/run_awesome_tests.sh +++ b/tests/test_awesome/test.sh @@ -3,12 +3,10 @@ enter_suite awesome -TEST_ROOT="$ROOT/tests/awesome" +TEST_ROOT="$(make_tmp_dir awesome)" TEST_PATH="$TEST_ROOT/path" TEST_STATIC_ROOT="$ROOT/tests/test_awesome" -test -d "$TEST_ROOT" && rm -r "$TEST_ROOT" -mkdir "$TEST_ROOT" cp -r "$TEST_STATIC_ROOT/path" "$TEST_ROOT" cp -r "$TEST_STATIC_ROOT/powerline" "$TEST_ROOT" @@ -186,8 +184,4 @@ then fail "lint" F "Checking test config failed" fi -if test $FAILED -eq 0 ; then - rm -r "$TEST_ROOT" -fi - exit_suite diff --git a/tests/run_bar_tests.sh b/tests/test_bar/test.sh similarity index 97% rename from tests/run_bar_tests.sh rename to tests/test_bar/test.sh index cad433b9..ef7b546f 100755 --- a/tests/run_bar_tests.sh +++ b/tests/test_bar/test.sh @@ -3,12 +3,10 @@ enter_suite bar -TEST_ROOT="$ROOT/tests/bar" +TEST_ROOT="$(make_tmp_dir bar)" TEST_PATH="$TEST_ROOT/path" TEST_STATIC_ROOT="$ROOT/tests/test_bar" -test -d "$TEST_ROOT" && rm -r "$TEST_ROOT" -mkdir "$TEST_ROOT" cp -r "$TEST_STATIC_ROOT/path" "$TEST_ROOT" cp -r "$TEST_STATIC_ROOT/powerline" "$TEST_ROOT" @@ -194,8 +192,4 @@ then fail "lint" F "Checking test config failed" fi -if test $FAILED -eq 0 ; then - rm -r "$TEST_ROOT" -fi - exit_suite diff --git a/tests/test_daemon/test.sh b/tests/test_daemon/test.sh new file mode 100755 index 00000000..6538e4fd --- /dev/null +++ b/tests/test_daemon/test.sh @@ -0,0 +1,41 @@ +#!/bin/sh +. tests/shlib/common.sh + +enter_suite daemon + +export ADDRESS="powerline-ipc-test-$$" +echo "Powerline address: $ADDRESS" +if "$PYTHON" "$ROOT/scripts/powerline-daemon" -s"$ADDRESS" ; then + sleep 1 + if ! ( \ + "$PYTHON" "$ROOT/client/powerline.py" \ + --socket "$ADDRESS" -p/dev/null shell left \ + | grep "file not found" + ) ; then + fail "devnull" F "-p/dev/null argument ignored or not treated properly" + fi + if ( \ + "$PYTHON" "$ROOT/client/powerline.py" --socket "$ADDRESS" \ + -p"$ROOT/powerline/config_files" shell left \ + | grep "file not found" + ) ; then + fail "nodevnull" F "-p/dev/null argument remembered while it should not" + fi + if ! ( \ + cd "$ROOT/tests/test_daemon" \ + && "$PYTHON" "$ROOT/client/powerline.py" --socket "$ADDRESS" \ + -p"$ROOT/powerline/config_files" shell left \ + | grep "test_daemon" + ) ; then + fail "segment" F "Output lacks string “tests”" + fi +else + fail "exitcode" E "Daemon exited with status $?" +fi +if "$PYTHON" "$ROOT/scripts/powerline-daemon" -s"$ADDRESS" -k ; then + : +else + fail "-k" F "powerline-daemon -k failed with exit code $?" +fi + +exit_suite diff --git a/tests/run_vterm_tests.sh b/tests/test_in_vterm/test.sh similarity index 68% rename from tests/run_vterm_tests.sh rename to tests/test_in_vterm/test.sh index 40aaebe8..bbd49582 100755 --- a/tests/run_vterm_tests.sh +++ b/tests/test_in_vterm/test.sh @@ -3,9 +3,9 @@ enter_suite vterm -for t in tests/test_in_vterm/test_*.sh ; do +for t in "$ROOT"/tests/test_in_vterm/test_*.sh ; do test_name="${t##*/test_}" - if ! sh "$t" ; then + if ! "$t" ; then fail "${test_name%.sh}" F "Failed running $t" fi done diff --git a/tests/run_lint_tests.sh b/tests/test_lint/test.sh similarity index 56% rename from tests/run_lint_tests.sh rename to tests/test_lint/test.sh index 3a02612f..f73ea981 100755 --- a/tests/run_lint_tests.sh +++ b/tests/test_lint/test.sh @@ -3,7 +3,7 @@ enter_suite lint -if ! ${PYTHON} scripts/powerline-lint -p powerline/config_files ; then +if ! "$PYTHON" "$ROOT/scripts/powerline-lint" -p "$ROOT/powerline/config_files" ; then fail "test" F "Running powerline-lint failed" fi diff --git a/tests/run_python_tests.sh b/tests/test_python/test.sh similarity index 61% rename from tests/run_python_tests.sh rename to tests/test_python/test.sh index 8f53b433..667d642d 100755 --- a/tests/run_python_tests.sh +++ b/tests/test_python/test.sh @@ -3,9 +3,9 @@ enter_suite python -for file in tests/test_python/test_*.py ; do +for file in "$ROOT"/tests/test_python/test_*.py ; do test_name="${file##*/test_}" - if ! ${PYTHON} $file --verbose --catch ; then + if ! "$PYTHON" "$file" --verbose --catch ; then fail "${test_name%.py}" F "Failed test(s) from $file" fi done diff --git a/tests/test_shells/test.sh b/tests/test_shells/test.sh index ec240a0e..590284b8 100755 --- a/tests/test_shells/test.sh +++ b/tests/test_shells/test.sh @@ -3,18 +3,13 @@ enter_suite shells -if test "x$1" = "x--fast" ; then +if test $# -eq 0 ; then FAST=1 - shift fi ONLY_SHELL="$1" ONLY_TEST_TYPE="$2" ONLY_TEST_CLIENT="$3" -if ! test -z "$ONLY_SHELL$ONLY_TEST_TYPE$ONLY_TEST_CLIENT" ; then - FAST= -fi - export PYTHON if test "x$ONLY_SHELL" = "x--help" ; then diff --git a/tests/run_vim_tests.sh b/tests/test_vim/test.sh similarity index 100% rename from tests/run_vim_tests.sh rename to tests/test_vim/test.sh