From 53a7d1046efebbd4dde4e483dd259530a65047e6 Mon Sep 17 00:00:00 2001 From: Foo Date: Sun, 30 Apr 2017 15:30:15 +0300 Subject: [PATCH] Move messages.fail to a temporary directory --- tests/common.sh | 37 ++++++++++++++++--- tests/run_vim_tests.sh | 8 +++- tests/test_vim/tests/empty_encoding.old.vim | 2 +- tests/test_vim/tests/foreign_stl_override.vim | 2 +- tests/test_vim/tests/invalid_unicode.vim | 2 +- tests/test_vim/tests/plugin_file.vim | 2 +- tests/test_vim/tests/tabline.vim | 2 +- tests/test_vim/vim_utils.vim | 2 +- 8 files changed, 44 insertions(+), 13 deletions(-) diff --git a/tests/common.sh b/tests/common.sh index 1b323b7b..7cba9b57 100644 --- a/tests/common.sh +++ b/tests/common.sh @@ -7,14 +7,18 @@ if test -z "$FAILED" ; then FAILED=0 FAIL_SUMMARY="" + + TMP_ROOT="$ROOT/tests/tmp" + FAILURES_FILE="$ROOT/tests/failures" fi enter_suite() { - local suite_name="$1" + local suite_name="$1" ; shift export POWERLINE_CURRENT_SUITE="${POWERLINE_CURRENT_SUITE}/$suite_name" } exit_suite() { + rm_tmp_dir if test $FAILED -ne 0 ; then echo "Suite ${POWERLINE_CURRENT_SUITE} failed, summary:" echo "${FAIL_SUMMARY}" @@ -31,14 +35,37 @@ fail() { shift allow_failure=A fi - local test_name="$1" - local fail_char="$allow_failure$2" - local message="$3" + local test_name="$1" ; shift + local fail_char="$allow_failure$1" ; shift + local message="$1" ; shift local full_msg="$fail_char $POWERLINE_CURRENT_SUITE|$test_name :: $message" FAIL_SUMMARY="${FAIL_SUMMARY}${NL}${full_msg}" echo "Failed: $full_msg" - echo "$full_msg" >> "$ROOT/tests/failures" + echo "$full_msg" >> "$FAILURES_FILE" if test "x$allow_failure" = "x" ; then FAILED=1 fi } + +make_tmp_dir() { + local suffix="$1" ; shift + + local tmpdir="$TMP_ROOT/$suffix/" + + if test -d "$tmpdir" ; then + rm -r "$tmpdir" + fi + + mkdir -p "$tmpdir" + + printf '%s' "$tmpdir" +} + +rm_tmp_dir() { + if test -e "$FAILURES_FILE" ; then + return 0 + fi + if test -d "$TMP_ROOT" ; then + rm -r "$TMP_ROOT" + fi +} diff --git a/tests/run_vim_tests.sh b/tests/run_vim_tests.sh index 80e5400b..5f9d29a3 100755 --- a/tests/run_vim_tests.sh +++ b/tests/run_vim_tests.sh @@ -10,8 +10,8 @@ export POWERLINE_CONFIG_OVERRIDES='common.default_top_theme=ascii' export POWERLINE_THEME_OVERRIDES='default.segments.left=[]' test_script() { - local vim="$1" - local script="$2" + local vim="$1" ; shift + local script="$1" ; shift echo "Running script $script with $vim" if ! test -e "$vim" ; then return 0 @@ -28,8 +28,12 @@ test_script() { fi } +TMPDIR="$(make_tmp_dir vim)" + TEST_SCRIPT_ROOT="$ROOT/tests/test_vim/tests" +cd "$TMPDIR" + for script in "$TEST_SCRIPT_ROOT"/*.vim ; do if test "${script%.old.vim}" = "${script}" ; then test_script "$NEW_VIM" "$script" diff --git a/tests/test_vim/tests/empty_encoding.old.vim b/tests/test_vim/tests/empty_encoding.old.vim index 136d5100..124a10a3 100755 --- a/tests/test_vim/tests/empty_encoding.old.vim +++ b/tests/test_vim/tests/empty_encoding.old.vim @@ -14,7 +14,7 @@ endif let g:powerline_config_paths = [expand(':p:h:h:h:h') . '/powerline/config_files'] try - source powerline/bindings/vim/plugin/powerline.vim + source :p:h:h:h:h/powerline/bindings/vim/plugin/powerline.vim catch call writefile(['Unexpected exception:', v:exception], 'message.fail') cquit diff --git a/tests/test_vim/tests/foreign_stl_override.vim b/tests/test_vim/tests/foreign_stl_override.vim index 4f92d78d..2a5b8c01 100644 --- a/tests/test_vim/tests/foreign_stl_override.vim +++ b/tests/test_vim/tests/foreign_stl_override.vim @@ -4,7 +4,7 @@ let g:powerline_config_paths = [expand(':p:h:h:h:h') . '/powerline/config set laststatus=2 redir => g:messages try - source powerline/bindings/vim/plugin/powerline.vim + source :p:h:h:h:h/powerline/bindings/vim/plugin/powerline.vim redrawstatus! vsplit redrawstatus! diff --git a/tests/test_vim/tests/invalid_unicode.vim b/tests/test_vim/tests/invalid_unicode.vim index 1718ba57..ac91f3c5 100644 --- a/tests/test_vim/tests/invalid_unicode.vim +++ b/tests/test_vim/tests/invalid_unicode.vim @@ -5,7 +5,7 @@ set showtabline=2 edit `="\xFF"` redir => g:messages try - source powerline/bindings/vim/plugin/powerline.vim + source :p:h:h:h:h/powerline/bindings/vim/plugin/powerline.vim redrawstatus! catch call writefile(['Unexpected exception', v:exception], 'message.fail') diff --git a/tests/test_vim/tests/plugin_file.vim b/tests/test_vim/tests/plugin_file.vim index 0279683f..18489332 100755 --- a/tests/test_vim/tests/plugin_file.vim +++ b/tests/test_vim/tests/plugin_file.vim @@ -4,7 +4,7 @@ let g:powerline_config_paths = [expand(':p:h:h:h:h') . '/powerline/config tabedit abc tabedit def try - source powerline/bindings/vim/plugin/powerline.vim + source :p:h:h:h:h/powerline/bindings/vim/plugin/powerline.vim catch call writefile([v:exception], 'message.fail') cquit diff --git a/tests/test_vim/tests/tabline.vim b/tests/test_vim/tests/tabline.vim index c9f48c12..ff76dc02 100755 --- a/tests/test_vim/tests/tabline.vim +++ b/tests/test_vim/tests/tabline.vim @@ -1,7 +1,7 @@ #!/usr/bin/vim -S set encoding=utf-8 let g:powerline_config_paths = [expand(':p:h:h:h:h') . '/powerline/config_files'] -source powerline/bindings/vim/plugin/powerline.vim +source :p:h:h:h:h/powerline/bindings/vim/plugin/powerline.vim edit abc tabedit def tabedit ghi diff --git a/tests/test_vim/vim_utils.vim b/tests/test_vim/vim_utils.vim index 86ee7a30..6219ec48 100644 --- a/tests/test_vim/vim_utils.vim +++ b/tests/test_vim/vim_utils.vim @@ -2,7 +2,7 @@ let g:powerline_use_var_handler = 1 let g:pyfiles_root=expand(':p:h').'/pyfiles' let g:root=expand(':p:h:h:h') -let g:mf=g:root.'/message.fail' +let g:mf=fnamemodify('message.fail', ':p') command -nargs=1 LST :call writefile(, g:mf, 'a') | cquit command -nargs=1 ERR :LST []