diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 12:38:06 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-27 12:38:06 +0000 |
commit | 695ad2c6d0b157d2969c9b946d9e3765113a61e7 (patch) | |
tree | eaab7e7e2523ad710afe779d532156258e40d5cc /tests/test_in_vterm | |
parent | Initial commit. (diff) | |
download | powerline-695ad2c6d0b157d2969c9b946d9e3765113a61e7.tar.xz powerline-695ad2c6d0b157d2969c9b946d9e3765113a61e7.zip |
Adding upstream version 2.8.1.upstream/2.8.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/test_in_vterm')
-rw-r--r-- | tests/test_in_vterm/shell/inits/dash | 16 | ||||
-rwxr-xr-x | tests/test_in_vterm/test.sh | 14 | ||||
-rwxr-xr-x | tests/test_in_vterm/test_shells.py | 162 | ||||
-rwxr-xr-x | tests/test_in_vterm/test_shells.sh | 119 | ||||
-rwxr-xr-x | tests/test_in_vterm/test_tmux.py | 251 | ||||
-rwxr-xr-x | tests/test_in_vterm/test_tmux.sh | 44 | ||||
-rwxr-xr-x | tests/test_in_vterm/test_vim.py | 73 | ||||
-rwxr-xr-x | tests/test_in_vterm/test_vim.sh | 39 |
8 files changed, 718 insertions, 0 deletions
diff --git a/tests/test_in_vterm/shell/inits/dash b/tests/test_in_vterm/shell/inits/dash new file mode 100644 index 0000000..7b146ff --- /dev/null +++ b/tests/test_in_vterm/shell/inits/dash @@ -0,0 +1,16 @@ +# vim: ft=sh + +set_theme_option() { + export POWERLINE_THEME_OVERRIDES="${POWERLINE_THEME_OVERRIDES};$1=$2" +} +set_theme() { + export POWERLINE_CONFIG_OVERRIDES="ext.shell.theme=$1" +} +set_virtual_env() { + export VIRTUAL_ENV="$HOME/.virtenvs/$1" +} +set_theme_option default_leftonly.segment_data.hostname.args.only_if_ssh false +set_theme default_leftonly +. "$ROOT/powerline/bindings/shell/powerline.sh" +export VIRTUAL_ENV= +cd "$TEST_ROOT/3rd" diff --git a/tests/test_in_vterm/test.sh b/tests/test_in_vterm/test.sh new file mode 100755 index 0000000..ad8d72a --- /dev/null +++ b/tests/test_in_vterm/test.sh @@ -0,0 +1,14 @@ +#!/bin/sh +. tests/shlib/common.sh + +enter_suite vterm + +# (Disabled) +#for t in "$ROOT"/tests/test_in_vterm/test_*.sh ; do +# test_name="${t##*/test_}" +# if ! "$t" ; then +# fail "${test_name%.sh}" F "Failed running $t" +# fi +#done + +exit_suite diff --git a/tests/test_in_vterm/test_shells.py b/tests/test_in_vterm/test_shells.py new file mode 100755 index 0000000..faf7976 --- /dev/null +++ b/tests/test_in_vterm/test_shells.py @@ -0,0 +1,162 @@ +#!/usr/bin/env python +# vim:fileencoding=utf-8:noet +from __future__ import (unicode_literals, division, absolute_import, print_function) + +import os +import sys + +from time import sleep +from subprocess import check_call +from glob import glob1 +from traceback import print_exc + +from argparse import ArgumentParser + +from powerline.lib.dict import updated + +from tests.modules.lib.terminal import (ExpectProcess, MutableDimensions, + do_terminal_tests, get_env) +from tests.modules import PowerlineTestSuite + + +TEST_ROOT = os.path.abspath(os.environ['TEST_ROOT']) + + +def get_parser(): + parser = ArgumentParser() + parser.add_argument('--type', action='store') + parser.add_argument('--client', action='store') + parser.add_argument('--binding', action='store') + parser.add_argument('args', action='append') + return parser + + +BINDING_OPTIONS = { + 'dash': { + 'cmd': 'dash', + 'args': ['-i'], + 'init': [ + '. "$ROOT/tests/test_in_vterm/shell/inits/dash"', + ], + }, +} + + +def main(argv): + script_args = get_parser().parse_args(argv) + + vterm_path = os.path.join(TEST_ROOT, 'path') + + env = get_env(vterm_path, TEST_ROOT) + env['ROOT'] = os.path.abspath('.') + env['TEST_ROOT'] = TEST_ROOT + env['TEST_TYPE'] = script_args.type + env['TEST_CLIENT'] = script_args.client + env['LANG'] = 'en_US.UTF_8' + env['_POWERLINE_RUNNING_SHELL_TESTS'] = ( + 'ee5bcdc6-b749-11e7-9456-50465d597777') + + dim = MutableDimensions(rows=50, cols=200) + + binding_opts = BINDING_OPTIONS[script_args.binding] + + cmd = os.path.join(vterm_path, binding_opts['cmd']) + args = binding_opts['args'] + + def gen_init(binding): + def init(p): + for line in binding_opts['init']: + p.send(line + '\n') + sleep(1) + + return init + + def gen_feed(line): + def feed(p): + p.send(line + '\n') + sleep(0.1) + + return feed + + base_attrs = { + ((255, 204,0), (204, 51, 0), 0, 0, 0): 'H', + ((204, 51, 0), (0, 102, 153), 0, 0, 0): 'sHU', + ((255, 255, 255), (0, 102, 153), 1, 0, 0): 'U', + ((0, 102, 153), (44, 44, 44), 0, 0, 0): 'sUB', + ((199, 199, 199), (44, 44, 44), 0, 0, 0): 'B', + ((44, 44, 44), (88, 88, 88), 0, 0, 0): 'sBD', + ((199, 199, 199), (88, 88, 88), 0, 0, 0): 'D', + ((144, 144, 144), (88, 88, 88), 0, 0, 0): 'sD', + ((221, 221, 221), (88, 88, 88), 1, 0, 0): 'C', + ((88, 88, 88), (0, 0, 0), 0, 0, 0): 'sDN', + ((240, 240, 240), (0, 0, 0), 0, 0, 0): 'N', + ((0, 102, 153), (51, 153, 204), 0, 0, 0): 'sUE', + ((255, 255, 255), (51, 153, 204), 0, 0, 0): 'E', + ((51, 153, 204), (44, 44, 44), 0, 0, 0): 'sEB', + } + + tests = ( + { + 'expected_result': ( + '{H: hostname }{sHU: }' + '{U:user }{sUB: }' + '{B: BRANCH }{sBD: }' + '{D:… }{sD: }{D:tmp }{sD: }{D:vshells }{sD: }{C:3rd }{sDN: }' + '{N:}', + base_attrs, + ), + 'prep_cb': gen_init(script_args.binding), + }, + { + 'expected_result': ( + '{H: hostname }{sHU: }' + '{U:user }{sUB: }' + '{B: BRANCH }{sBD: }' + '{D:… }{sD: }{D:vshells }{sD: }{D:3rd }{sD: }{C:.git }{sDN: }' + '{N:}', + base_attrs + ), + 'prep_cb': gen_feed('cd .git'), + }, + { + 'expected_result': ( + '{H: hostname }{sHU: }' + '{U:user }{sUB: }' + '{B: BRANCH }{sBD: }' + '{D:… }{sD: }{D:tmp }{sD: }{D:vshells }{sD: }{C:3rd }{sDN: }' + '{N:}', + base_attrs, + ), + 'prep_cb': gen_feed('cd ..'), + }, + { + 'expected_result': ( + '{H: hostname }{sHU: }' + '{U:user }{sUE: }' + '{E:(e) some-venv }{sEB: }' + '{B: BRANCH }{sBD: }' + '{D:… }{sD: }{D:tmp }{sD: }{D:vshells }{sD: }{C:3rd }{sDN: }' + '{N:}', + base_attrs, + ), + 'prep_cb': gen_feed('set_virtual_env some-venv'), + }, + ) + + with PowerlineTestSuite('shell') as suite: + return do_terminal_tests( + tests=tests, + cmd=cmd, + dim=dim, + args=args, + env=env, + cwd=TEST_ROOT, + suite=suite, + ) + + +if __name__ == '__main__': + if main(sys.argv[1:]): + raise SystemExit(0) + else: + raise SystemExit(1) diff --git a/tests/test_in_vterm/test_shells.sh b/tests/test_in_vterm/test_shells.sh new file mode 100755 index 0000000..f27442a --- /dev/null +++ b/tests/test_in_vterm/test_shells.sh @@ -0,0 +1,119 @@ +#!/bin/bash +. tests/shlib/common.sh +. tests/shlib/vterm.sh + +enter_suite vshells + +vterm_setup + +HAS_SOCAT= +HAS_C_CLIENT= + +git init "$TEST_ROOT/3rd" +git --git-dir="$TEST_ROOT/3rd/.git" checkout -b BRANCH +export DIR1="[32m" +export DIR2="" +mkdir "$TEST_ROOT/3rd/$DIR1" +mkdir "$TEST_ROOT/3rd/$DIR2" +mkdir "$TEST_ROOT"/3rd/'\[\]' +mkdir "$TEST_ROOT"/3rd/'%%' +mkdir "$TEST_ROOT"/3rd/'#[bold]' +mkdir "$TEST_ROOT"/3rd/'(echo)' +mkdir "$TEST_ROOT"/3rd/'$(echo)' +mkdir "$TEST_ROOT"/3rd/'`echo`' +mkdir "$TEST_ROOT"/3rd/'«Unicode!»' +mkdir "$TEST_ROOT/fish_home" +mkdir "$TEST_ROOT/fish_home/fish" +mkdir "$TEST_ROOT/fish_home/fish/generated_completions" +cp -r "$ROOT/tests/test_shells/ipython_home" "$TEST_ROOT" + +ln -s "$(command -v env)" "$TEST_ROOT/path" +ln -s "$(command -v git)" "$TEST_ROOT/path" +ln -s "$(command -v sleep)" "$TEST_ROOT/path" +ln -s "$(command -v cat)" "$TEST_ROOT/path" +ln -s "$(command -v false)" "$TEST_ROOT/path" +ln -s "$(command -v true)" "$TEST_ROOT/path" +ln -s "$(command -v kill)" "$TEST_ROOT/path" +ln -s "$(command -v echo)" "$TEST_ROOT/path" +ln -s "$(command -v which)" "$TEST_ROOT/path" +ln -s "$(command -v dirname)" "$TEST_ROOT/path" +ln -s "$(command -v wc)" "$TEST_ROOT/path" +ln -s "$(command -v stty)" "$TEST_ROOT/path" +ln -s "$(command -v cut)" "$TEST_ROOT/path" +ln -s "$(command -v bc)" "$TEST_ROOT/path" +ln -s "$(command -v expr)" "$TEST_ROOT/path" +ln -s "$(command -v mktemp)" "$TEST_ROOT/path" +ln -s "$(command -v grep)" "$TEST_ROOT/path" +ln -s "$(command -v sed)" "$TEST_ROOT/path" +ln -s "$(command -v rm)" "$TEST_ROOT/path" +ln -s "$(command -v tr)" "$TEST_ROOT/path" +ln -s "$(command -v uname)" "$TEST_ROOT/path" +ln -s "$(command -v test)" "$TEST_ROOT/path" +ln -s "$(command -v pwd)" "$TEST_ROOT/path" +ln -s "$(command -v hostname)" "$TEST_ROOT/path" +ln -s "$ROOT/tests/test_shells/bgscript.sh" "$TEST_ROOT/path" +ln -s "$ROOT/tests/test_shells/waitpid.sh" "$TEST_ROOT/path" + +ln -s "$ROOT/scripts/powerline-config" "$TEST_ROOT/path" +ln -s "$ROOT/scripts/powerline-render" "$TEST_ROOT/path" +ln -s "$ROOT/client/powerline.py" "$TEST_ROOT/path" + +if test -e "$ROOT/scripts/powerline" ; then + ln -s "$ROOT/scripts/powerline" "$TEST_ROOT/path" +elif test -e client/powerline ; then + ln -s "$ROOT/client/powerline" "$TEST_ROOT/path" +elif command -v powerline ; then + ln -s "$(command -v powerline)" "$TEST_ROOT/path" +else + echo "Executable powerline was not found" + exit 1 +fi + +if test "$( + file --mime-type --brief --dereference "$TEST_ROOT/path/powerline" \ + | cut -d/ -f1)" = "application" ; then + HAS_C_CLIENT=1 +fi + +if command -v socat ; then + HAS_SOCAT=1 + ln -s "$(command -v socat)" "$TEST_ROOT/path" + ln -s "$ROOT/client/powerline.sh" "$TEST_ROOT/path" +fi + +# Test type: daemon, renderer, … +# Test client: python, shell, c, none +# Test binding: *sh, ipython, pdb, … +test_shell() { + local test_type="$1" ; shift + local test_client="$1" ; shift + local test_binding="$1" ; shift + + if test "$test_client" = shell && test -z "$HAS_SOCAT" ; then + echo "Skipping test, socat not available" + return + fi + if test "$test_client" = c && test -z "$HAS_C_CLIENT" ; then + echo "Skipping test, C client not available" + return + fi + if command -v "$test_binding" ; then + ln -s "$(command -v "$test_binding")" "$TEST_ROOT/path" + fi + + if ! "${PYTHON}" "$ROOT/tests/test_in_vterm/test_shells.py" \ + --type=$test_type \ + --client=$test_client \ + --binding=$test_binding \ + -- "$@" + then + local test_name="$test_type-$test_client-$test_binding" + fail "$test_name" F "Failed vterm shell test" + fi +} + +test_shell renderer python dash -i || true + +vterm_shutdown + +exit_suite diff --git a/tests/test_in_vterm/test_tmux.py b/tests/test_in_vterm/test_tmux.py new file mode 100755 index 0000000..c1e126b --- /dev/null +++ b/tests/test_in_vterm/test_tmux.py @@ -0,0 +1,251 @@ +#!/usr/bin/env python +# vim:fileencoding=utf-8:noet +from __future__ import (unicode_literals, division, absolute_import, print_function) + +import os +import sys +import json + +from time import sleep +from subprocess import check_call +from glob import glob1 +from traceback import print_exc + +from powerline.lib.dict import updated +from powerline.bindings.tmux import get_tmux_version +from powerline import get_fallback_logger + +from tests.modules.lib.terminal import (ExpectProcess, MutableDimensions, + do_terminal_tests, get_env) +from tests.modules import PowerlineTestSuite + + +TEST_ROOT = os.path.abspath(os.environ['TEST_ROOT']) + + +def tmux_logs_iter(test_dir): + for tail in glob1(test_dir, '*.log'): + yield os.path.join(test_dir, tail) + + +def print_tmux_logs(): + for f in tmux_logs_iter(TEST_ROOT): + print('_' * 80) + print(os.path.basename(f) + ':') + print('=' * 80) + with open(f, 'r') as fp: + for line in fp: + sys.stdout.write(line) + os.unlink(f) + + +def get_expected_result(tmux_version, + expected_result_old, + expected_result_1_7=None, + expected_result_1_8=None, + expected_result_2_0=None): + if tmux_version >= (2, 0) and expected_result_2_0: + return expected_result_2_0 + elif tmux_version >= (1, 8) and expected_result_1_8: + return expected_result_1_8 + elif tmux_version >= (1, 7) and expected_result_1_7: + return expected_result_1_7 + else: + return expected_result_old + + +def tmux_fin_cb(p, cmd, env): + try: + check_call([ + cmd, '-S', env['POWERLINE_TMUX_SOCKET_PATH'], 'kill-server' + ], env=env, cwd=TEST_ROOT) + except Exception: + print_exc() + for f in tmux_logs_iter(TEST_ROOT): + os.unlink(f) + + +def main(attempts=3): + vterm_path = os.path.join(TEST_ROOT, 'path') + + tmux_exe = os.path.join(vterm_path, 'tmux') + + socket_path = os.path.abspath('tmux-socket-{0}'.format(attempts)) + if os.path.exists(socket_path): + os.unlink(socket_path) + + env = get_env(vterm_path, TEST_ROOT, { + 'POWERLINE_THEME_OVERRIDES': ';'.join(( + key + '=' + json.dumps(val) + for key, val in ( + ('default.segments.right', [{ + 'type': 'string', + 'name': 's1', + 'highlight_groups': ['cwd'], + 'priority':50, + }]), + ('default.segments.left', [{ + 'type': 'string', + 'name': 's2', + 'highlight_groups': ['background'], + 'priority':20, + }]), + ('default.segment_data.s1.contents', 'S1 string here'), + ('default.segment_data.s2.contents', 'S2 string here'), + ) + )), + 'POWERLINE_TMUX_SOCKET_PATH': socket_path, + }) + + conf_path = os.path.abspath('powerline/bindings/tmux/powerline.conf') + conf_line = 'source "' + ( + conf_path.replace('\\', '\\\\').replace('"', '\\"')) + '"\n' + conf_file = os.path.realpath(os.path.join(TEST_ROOT, 'tmux.conf')) + with open(conf_file, 'w') as cf_fd: + cf_fd.write(conf_line) + + tmux_version = get_tmux_version(get_fallback_logger()) + + dim = MutableDimensions(rows=50, cols=200) + + def prepare_test_1(p): + sleep(5) + + def prepare_test_2(p): + dim.cols = 40 + p.resize(dim) + sleep(5) + + base_attrs = { + ((0, 0, 0), (243, 243, 243), 1, 0, 0): 'lead', + ((243, 243, 243), (11, 11, 11), 0, 0, 0): 'leadsep', + ((255, 255, 255), (11, 11, 11), 0, 0, 0): 'bg', + ((199, 199, 199), (88, 88, 88), 0, 0, 0): 'cwd', + ((88, 88, 88), (11, 11, 11), 0, 0, 0): 'cwdhsep', + ((0, 0, 0), (0, 224, 0), 0, 0, 0): 'defstl', + } + tests = ( + { + 'expected_result': get_expected_result( + tmux_version, + expected_result_old=( + '{lead: 0 }{leadsep: }{bg: S2 string here }' + '{4: 0 }{cwdhsep:| }{6:bash }' + '{bg: }{4: 1- }{cwdhsep:| }{6:bash }' + '{bg: }{7: }{8:2* | }{9:bash }{10: }' + '{bg:' + (' ' * 124) + '}' + '{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, { + ((133, 133, 133), (11, 11, 11), 0, 0, 0): 4, + ((188, 188, 188), (11, 11, 11), 0, 0, 0): 6, + ((11, 11, 11), (0, 102, 153), 0, 0, 0): 7, + ((102, 204, 255), (0, 102, 153), 0, 0, 0): 8, + ((255, 255, 255), (0, 102, 153), 1, 0, 0): 9, + ((0, 102, 153), (11, 11, 11), 0, 0, 0): 10, + })), + expected_result_1_8=( + '{lead: 0 }{leadsep: }{bg: S2 string here }' + '{4: 0 }{cwdhsep:| }{6:bash }' + '{bg: }{4: 1- }{cwdhsep:| }{7:bash }' + '{bg: }{8: }{9:2* | }{10:bash }{7: }' + '{bg:' + (' ' * 124) + '}' + '{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, { + ((133, 133, 133), (11, 11, 11), 0, 0, 0): 4, + ((188, 188, 188), (11, 11, 11), 0, 0, 0): 6, + ((0, 102, 153), (11, 11, 11), 0, 0, 0): 7, + ((11, 11, 11), (0, 102, 153), 0, 0, 0): 8, + ((102, 204, 255), (0, 102, 153), 0, 0, 0): 9, + ((255, 255, 255), (0, 102, 153), 1, 0, 0): 10, + })), + expected_result_2_0=( + '{lead: 0 }{leadsep: }{bg: S2 string here }' + '{4: 0 }{cwdhsep:| }{6:bash }' + '{bg: }{4: 1- }{cwdhsep:| }{7:bash }' + '{bg: }{8: }{9:2* | }{10:bash }{7: }' + '{bg:' + (' ' * 125) + '}' + '{cwdhsep: }{cwd: S1 string here }', updated(base_attrs, { + ((133, 133, 133), (11, 11, 11), 0, 0, 0): 4, + ((188, 188, 188), (11, 11, 11), 0, 0, 0): 6, + ((0, 102, 153), (11, 11, 11), 0, 0, 0): 7, + ((11, 11, 11), (0, 102, 153), 0, 0, 0): 8, + ((102, 204, 255), (0, 102, 153), 0, 0, 0): 9, + ((255, 255, 255), (0, 102, 153), 1, 0, 0): 10, + })), + ), + 'prep_cb': prepare_test_1, + 'row': dim.rows - 1, + }, { + 'expected_result': get_expected_result( + tmux_version, + expected_result_old=('{bg:' + (' ' * 40) + '}', base_attrs), + expected_result_1_7=( + '{lead: 0 }' + '{leadsep: }{bg: <}{4:h }{bg: }{5: }' + '{6:2* | }{7:bash }{8: }{bg: }{cwdhsep: }' + '{cwd: S1 string here }', updated(base_attrs, { + ((188, 188, 188), (11, 11, 11), 0, 0, 0): 4, + ((11, 11, 11), (0, 102, 153), 0, 0, 0): 5, + ((102, 204, 255), (0, 102, 153), 0, 0, 0): 6, + ((255, 255, 255), (0, 102, 153), 1, 0, 0): 7, + ((0, 102, 153), (11, 11, 11), 0, 0, 0): 8, + })), + expected_result_1_8=( + '{lead: 0 }' + '{leadsep: }{bg: <}{4:h }{bg: }{5: }' + '{6:2* | }{7:bash }{4: }{bg: }{cwdhsep: }' + '{cwd: S1 string here }', updated(base_attrs, { + ((0, 102, 153), (11, 11, 11), 0, 0, 0): 4, + ((11, 11, 11), (0, 102, 153), 0, 0, 0): 5, + ((102, 204, 255), (0, 102, 153), 0, 0, 0): 6, + ((255, 255, 255), (0, 102, 153), 1, 0, 0): 7, + })), + expected_result_2_0=( + '{lead: 0 }' + '{leadsep: }{bg:<}{4:ash }{bg: }{5: }' + '{6:2* | }{7:bash }{4: }{cwdhsep: }' + '{cwd: S1 string here }', updated(base_attrs, { + ((0, 102, 153), (11, 11, 11), 0, 0, 0): 4, + ((11, 11, 11), (0, 102, 153), 0, 0, 0): 5, + ((102, 204, 255), (0, 102, 153), 0, 0, 0): 6, + ((255, 255, 255), (0, 102, 153), 1, 0, 0): 7, + })), + ), + 'prep_cb': prepare_test_2, + 'row': dim.rows - 1, + } + ) + + args = [ + # Specify full path to tmux socket (testing tmux instance must not + # interfere with user one) + '-S', socket_path, + # Force 256-color mode + '-2', + # Request verbose logging just in case + '-v', + # Specify configuration file + '-f', conf_file, + # Run bash three times + 'new-session', 'bash --norc --noprofile -i', ';', + 'new-window', 'bash --norc --noprofile -i', ';', + 'new-window', 'bash --norc --noprofile -i', ';', + ] + + with PowerlineTestSuite('tmux') as suite: + return do_terminal_tests( + tests=tests, + cmd=tmux_exe, + dim=dim, + args=args, + env=env, + cwd=TEST_ROOT, + fin_cb=tmux_fin_cb, + last_attempt_cb=print_tmux_logs, + suite=suite, + ) + + +if __name__ == '__main__': + if main(): + raise SystemExit(0) + else: + raise SystemExit(1) diff --git a/tests/test_in_vterm/test_tmux.sh b/tests/test_in_vterm/test_tmux.sh new file mode 100755 index 0000000..ab4e007 --- /dev/null +++ b/tests/test_in_vterm/test_tmux.sh @@ -0,0 +1,44 @@ +#!/bin/bash +. tests/shlib/common.sh +. tests/shlib/vterm.sh + +enter_suite tmux final + +vterm_setup + +ln -s "$(command -v env)" "$TEST_ROOT/path" +ln -s "$(command -v cut)" "$TEST_ROOT/path" +ln -s "$ROOT/scripts/powerline-render" "$TEST_ROOT/path" +ln -s "$ROOT/scripts/powerline-config" "$TEST_ROOT/path" + +test_tmux() { + if test "$PYTHON_IMPLEMENTATION" = PyPy; then + # FIXME PyPy3 segfaults for some reason, PyPy does it as well, but + # occasionally. + return 0 + fi + if ! command -v "${POWERLINE_TMUX_EXE}" ; then + return 0 + fi + ln -sf "$(command -v "${POWERLINE_TMUX_EXE}")" "$TEST_ROOT/path/tmux" + f="$ROOT/tests/test_in_vterm/test_tmux.py" + if ! "${PYTHON}" "$f" ; then + local test_name="$("$POWERLINE_TMUX_EXE" -V 2>&1 | cut -d' ' -f2)" + fail "$test_name" F "Failed vterm test $f" + fi +} + +if test -z "$POWERLINE_TMUX_EXE" && test -d "$ROOT/tests/bot-ci/deps/tmux" +then + for tmux in "$ROOT"/tests/bot-ci/deps/tmux/tmux-*/tmux ; do + export POWERLINE_TMUX_EXE="$tmux" + test_tmux || true + done +else + export POWERLINE_TMUX_EXE="${POWERLINE_TMUX_EXE:-tmux}" + test_tmux || true +fi + +vterm_shutdown + +exit_suite diff --git a/tests/test_in_vterm/test_vim.py b/tests/test_in_vterm/test_vim.py new file mode 100755 index 0000000..0fbc319 --- /dev/null +++ b/tests/test_in_vterm/test_vim.py @@ -0,0 +1,73 @@ +#!/usr/bin/env python +# vim:fileencoding=utf-8:noet +from __future__ import (unicode_literals, division, absolute_import, print_function) + +import os +import sys + +from time import sleep +from subprocess import check_call +from glob import glob1 +from traceback import print_exc + +from powerline.lib.dict import updated + +from tests.modules.lib.terminal import (ExpectProcess, MutableDimensions, + do_terminal_tests, get_env) +from tests.modules import PowerlineTestSuite + + +TEST_ROOT = os.path.abspath(os.environ['TEST_ROOT']) + + +def main(attempts=3): + vterm_path = os.path.join(TEST_ROOT, 'path') + + vim_exe = os.path.join(vterm_path, 'vim') + + env = get_env(vterm_path, TEST_ROOT) + env['ROOT'] = os.path.abspath('.') + + dim = MutableDimensions(rows=50, cols=200) + + vimrc = os.path.join(TEST_ROOT, 'init.vim') + vimrc_contents = ''' + set laststatus=2 + set runtimepath=$ROOT/powerline/bindings/vim + ''' + with open(vimrc, 'w') as vd: + vd.write(vimrc_contents) + + base_attrs = { + (( 64, 64, 255), (0, 0, 0), 0, 0, 0): 'NT', # NonText + ((240, 240, 240), (0, 0, 0), 0, 0, 0): 'N', # Normal + } + + args = [ + '-u', vimrc, + '-i', 'NONE', + ] + + def feed(p): + p.send(':echo strtrans(eval(&statusline[2:]))\n') + + tests = ( + ) + + with PowerlineTestSuite('vim') as suite: + return do_terminal_tests( + tests=tests, + cmd=vim_exe, + dim=dim, + args=args, + env=env, + cwd=TEST_ROOT, + suite=suite, + ) + + +if __name__ == '__main__': + if main(): + raise SystemExit(0) + else: + raise SystemExit(1) diff --git a/tests/test_in_vterm/test_vim.sh b/tests/test_in_vterm/test_vim.sh new file mode 100755 index 0000000..2811e45 --- /dev/null +++ b/tests/test_in_vterm/test_vim.sh @@ -0,0 +1,39 @@ +#!/bin/sh +. tests/shlib/common.sh +. tests/shlib/vterm.sh +. tests/shlib/vim.sh + +enter_suite vvim final + +vterm_setup + +test_vim() { + if test "$PYTHON_IMPLEMENTATION" != CPython ; then + # Can only link with cpython + return 0 + fi + if ! command -v "$POWERLINE_VIM_EXE" ; then + return 0 + fi + ln -sf "$(command -v "${POWERLINE_VIM_EXE}")" "$TEST_ROOT/path/vim" + f="$ROOT/tests/test_in_vterm/test_vim.py" + if ! "${PYTHON}" "$f" ; then + local test_name="$(LANG=C "$POWERLINE_VIM_EXE" --cmd 'echo version' --cmd qa 2>&1 | tail -n2)" + fail "$test_name" F "Failed vterm test $f" + fi +} + +if test -z "$POWERLINE_VIM_EXE" && test -d "$ROOT/tests/bot-ci/deps/vim" +then + for vim in "$OLD_VIM" "$NEW_VIM" ; do + export POWERLINE_VIM_EXE="$vim" + test_vim || true + done +else + export POWERLINE_VIM_EXE="${POWERLINE_VIM_EXE:-vim}" + test_vim || true +fi + +vterm_shutdown + +exit_suite |