mirror of
https://github.com/powerline/powerline.git
synced 2025-07-23 22:05:43 +02:00
Merge pull request #1778 from ZyX-I/vterm-standard-tmpdir
Switch vterm tests to use “standard” temporary directory in tests/tmp
This commit is contained in:
commit
36dba1134f
@ -63,11 +63,13 @@ class ExpectProcess(threading.Thread):
|
||||
self.shutdown_event = threading.Event()
|
||||
|
||||
def run(self):
|
||||
child = pexpect.spawn(self.cmd, self.args, cwd=self.cwd, env=self.env)
|
||||
sleep(0.5)
|
||||
child.setwinsize(self.dim.rows, self.dim.cols)
|
||||
sleep(0.5)
|
||||
self.child = child
|
||||
with self.child_lock:
|
||||
child = pexpect.spawn(self.cmd, self.args, cwd=self.cwd,
|
||||
env=self.env)
|
||||
sleep(0.5)
|
||||
child.setwinsize(self.dim.rows, self.dim.cols)
|
||||
sleep(0.5)
|
||||
self.child = child
|
||||
status = None
|
||||
while status is None and not self.shutdown_event.is_set():
|
||||
try:
|
||||
@ -141,9 +143,8 @@ class ExpectProcess(threading.Thread):
|
||||
return '\n'.join(lines), attrs
|
||||
|
||||
|
||||
def test_expected_result(p, test, last_attempt, last_attempt_cb=None):
|
||||
def test_expected_result(p, test, last_attempt, last_attempt_cb, attempts):
|
||||
expected_text, attrs = test['expected_result']
|
||||
attempts = 3
|
||||
result = None
|
||||
while attempts:
|
||||
actual_text, all_attrs = p.get_row(test['row'], attrs)
|
||||
@ -252,7 +253,8 @@ def do_terminal_tests(tests, cmd, dim, args, env, cwd=None, fin_cb=None,
|
||||
ret = (
|
||||
ret
|
||||
and test_expected_result(p, test, attempts == 0,
|
||||
last_attempt_cb)
|
||||
last_attempt_cb,
|
||||
test.get('attempts', 3))
|
||||
)
|
||||
|
||||
if ret:
|
||||
|
@ -1,26 +1,19 @@
|
||||
. tests/shlib/common.sh
|
||||
. tests/bot-ci/scripts/common/main.sh
|
||||
set +x
|
||||
|
||||
vterm_setup() {
|
||||
local test_dir="$1" ; shift
|
||||
local vterm_suf="$1" ; shift
|
||||
|
||||
rm -rf "$test_dir"
|
||||
mkdir "$test_dir"
|
||||
mkdir "$test_dir/path"
|
||||
make_test_root "vterm_$vterm_suf"
|
||||
|
||||
ln -s "$(which "${PYTHON}")" "$test_dir/path/python"
|
||||
ln -s "$(which bash)" "$test_dir/path"
|
||||
mkdir "$TEST_ROOT/path"
|
||||
|
||||
cp -r "$ROOT/tests/terminfo" "$test_dir"
|
||||
ln -s "$(which "${PYTHON}")" "$TEST_ROOT/path/python"
|
||||
ln -s "$(which bash)" "$TEST_ROOT/path"
|
||||
|
||||
cp -r "$ROOT/tests/terminfo" "$TEST_ROOT"
|
||||
}
|
||||
|
||||
vterm_shutdown() {
|
||||
local test_dir="$1" ; shift
|
||||
|
||||
if test $FAILED -eq 0 ; then
|
||||
rm -rf "$test_dir"
|
||||
else
|
||||
echo "$FAIL_SUMMARY"
|
||||
fi
|
||||
rm_test_root
|
||||
}
|
||||
|
@ -19,7 +19,7 @@ from tests.modules.lib.terminal import (ExpectProcess, MutableDimensions,
|
||||
do_terminal_tests, get_env)
|
||||
|
||||
|
||||
VTERM_TEST_DIR = os.path.abspath('tests/vterm_tmux')
|
||||
TEST_ROOT = os.path.abspath(os.environ['TEST_ROOT'])
|
||||
|
||||
|
||||
def tmux_logs_iter(test_dir):
|
||||
@ -28,7 +28,7 @@ def tmux_logs_iter(test_dir):
|
||||
|
||||
|
||||
def print_tmux_logs():
|
||||
for f in tmux_logs_iter(VTERM_TEST_DIR):
|
||||
for f in tmux_logs_iter(TEST_ROOT):
|
||||
print('_' * 80)
|
||||
print(os.path.basename(f) + ':')
|
||||
print('=' * 80)
|
||||
@ -57,15 +57,15 @@ def tmux_fin_cb(p, cmd, env):
|
||||
try:
|
||||
check_call([
|
||||
cmd, '-S', env['POWERLINE_TMUX_SOCKET_PATH'], 'kill-server'
|
||||
], env=env, cwd=VTERM_TEST_DIR)
|
||||
], env=env, cwd=TEST_ROOT)
|
||||
except Exception:
|
||||
print_exc()
|
||||
for f in tmux_logs_iter(VTERM_TEST_DIR):
|
||||
for f in tmux_logs_iter(TEST_ROOT):
|
||||
os.unlink(f)
|
||||
|
||||
|
||||
def main(attempts=3):
|
||||
vterm_path = os.path.join(VTERM_TEST_DIR, 'path')
|
||||
vterm_path = os.path.join(TEST_ROOT, 'path')
|
||||
|
||||
tmux_exe = os.path.join(vterm_path, 'tmux')
|
||||
|
||||
@ -73,7 +73,7 @@ def main(attempts=3):
|
||||
if os.path.exists(socket_path):
|
||||
os.unlink(socket_path)
|
||||
|
||||
env = get_env(vterm_path, VTERM_TEST_DIR, {
|
||||
env = get_env(vterm_path, TEST_ROOT, {
|
||||
'POWERLINE_THEME_OVERRIDES': ';'.join((
|
||||
key + '=' + json.dumps(val)
|
||||
for key, val in (
|
||||
@ -99,7 +99,7 @@ def main(attempts=3):
|
||||
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(VTERM_TEST_DIR, 'tmux.conf'))
|
||||
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)
|
||||
|
||||
@ -235,7 +235,7 @@ def main(attempts=3):
|
||||
dim=dim,
|
||||
args=args,
|
||||
env=env,
|
||||
cwd=VTERM_TEST_DIR,
|
||||
cwd=TEST_ROOT,
|
||||
fin_cb=tmux_fin_cb,
|
||||
last_attempt_cb=print_tmux_logs,
|
||||
)
|
||||
|
@ -4,14 +4,12 @@
|
||||
|
||||
enter_suite tmux
|
||||
|
||||
VTERM_TEST_DIR="$ROOT/tests/vterm_tmux"
|
||||
vterm_setup tmux
|
||||
|
||||
vterm_setup "$VTERM_TEST_DIR"
|
||||
|
||||
ln -s "$(which env)" "$VTERM_TEST_DIR/path"
|
||||
ln -s "$(which cut)" "$VTERM_TEST_DIR/path"
|
||||
ln -s "$ROOT/scripts/powerline-render" "$VTERM_TEST_DIR/path"
|
||||
ln -s "$ROOT/scripts/powerline-config" "$VTERM_TEST_DIR/path"
|
||||
ln -s "$(which env)" "$TEST_ROOT/path"
|
||||
ln -s "$(which 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
|
||||
@ -22,7 +20,7 @@ test_tmux() {
|
||||
if ! which "${POWERLINE_TMUX_EXE}" ; then
|
||||
return 0
|
||||
fi
|
||||
ln -sf "$(which "${POWERLINE_TMUX_EXE}")" "$VTERM_TEST_DIR/path/tmux"
|
||||
ln -sf "$(which "${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)"
|
||||
@ -41,6 +39,6 @@ else
|
||||
test_tmux || true
|
||||
fi
|
||||
|
||||
vterm_shutdown "$VTERM_TEST_DIR"
|
||||
vterm_shutdown
|
||||
|
||||
exit_suite
|
||||
|
@ -4,41 +4,62 @@ from __future__ import (unicode_literals, division, absolute_import, print_funct
|
||||
|
||||
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 tests.modules.lib.terminal import (ExpectProcess, MutableDimensions,
|
||||
do_terminal_tests, get_env)
|
||||
|
||||
|
||||
VTERM_TEST_DIR = os.path.abspath('tests/vterm_vim')
|
||||
TEST_ROOT = os.path.abspath(os.environ['TEST_ROOT'])
|
||||
|
||||
|
||||
def main(attempts=3):
|
||||
vterm_path = os.path.join(VTERM_TEST_DIR, 'path')
|
||||
vterm_path = os.path.join(TEST_ROOT, 'path')
|
||||
|
||||
vim_exe = os.path.join(vterm_path, 'vim')
|
||||
|
||||
env = get_env(vterm_path, VTERM_TEST_DIR)
|
||||
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 = (
|
||||
)
|
||||
|
||||
args = []
|
||||
|
||||
return do_terminal_tests(
|
||||
tests=tests,
|
||||
cmd=vim_exe,
|
||||
dim=dim,
|
||||
args=args,
|
||||
env=env,
|
||||
cwd=VTERM_TEST_DIR,
|
||||
cwd=TEST_ROOT,
|
||||
)
|
||||
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
#!/bin/sh
|
||||
. tests/shlib/common.sh
|
||||
. tests/shlib/vterm.sh
|
||||
. tests/shlib/vim.sh
|
||||
|
||||
enter_suite vim
|
||||
|
||||
make_test_root
|
||||
vterm_setup vim
|
||||
|
||||
# Define some overrides. These ones must be ignored and do not affect Vim
|
||||
# status/tab lines.
|
||||
@ -46,4 +47,6 @@ if test -e "$OLD_VIM" ; then
|
||||
done
|
||||
fi
|
||||
|
||||
vterm_shutdown
|
||||
|
||||
exit_suite
|
||||
|
Loading…
x
Reference in New Issue
Block a user