mirror of
https://github.com/powerline/powerline.git
synced 2025-07-25 06:46:33 +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()
|
self.shutdown_event = threading.Event()
|
||||||
|
|
||||||
def run(self):
|
def run(self):
|
||||||
child = pexpect.spawn(self.cmd, self.args, cwd=self.cwd, env=self.env)
|
with self.child_lock:
|
||||||
sleep(0.5)
|
child = pexpect.spawn(self.cmd, self.args, cwd=self.cwd,
|
||||||
child.setwinsize(self.dim.rows, self.dim.cols)
|
env=self.env)
|
||||||
sleep(0.5)
|
sleep(0.5)
|
||||||
self.child = child
|
child.setwinsize(self.dim.rows, self.dim.cols)
|
||||||
|
sleep(0.5)
|
||||||
|
self.child = child
|
||||||
status = None
|
status = None
|
||||||
while status is None and not self.shutdown_event.is_set():
|
while status is None and not self.shutdown_event.is_set():
|
||||||
try:
|
try:
|
||||||
@ -141,9 +143,8 @@ class ExpectProcess(threading.Thread):
|
|||||||
return '\n'.join(lines), attrs
|
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']
|
expected_text, attrs = test['expected_result']
|
||||||
attempts = 3
|
|
||||||
result = None
|
result = None
|
||||||
while attempts:
|
while attempts:
|
||||||
actual_text, all_attrs = p.get_row(test['row'], attrs)
|
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 = (
|
||||||
ret
|
ret
|
||||||
and test_expected_result(p, test, attempts == 0,
|
and test_expected_result(p, test, attempts == 0,
|
||||||
last_attempt_cb)
|
last_attempt_cb,
|
||||||
|
test.get('attempts', 3))
|
||||||
)
|
)
|
||||||
|
|
||||||
if ret:
|
if ret:
|
||||||
|
@ -1,26 +1,19 @@
|
|||||||
. tests/shlib/common.sh
|
. tests/shlib/common.sh
|
||||||
. tests/bot-ci/scripts/common/main.sh
|
|
||||||
set +x
|
set +x
|
||||||
|
|
||||||
vterm_setup() {
|
vterm_setup() {
|
||||||
local test_dir="$1" ; shift
|
local vterm_suf="$1" ; shift
|
||||||
|
|
||||||
rm -rf "$test_dir"
|
make_test_root "vterm_$vterm_suf"
|
||||||
mkdir "$test_dir"
|
|
||||||
mkdir "$test_dir/path"
|
|
||||||
|
|
||||||
ln -s "$(which "${PYTHON}")" "$test_dir/path/python"
|
mkdir "$TEST_ROOT/path"
|
||||||
ln -s "$(which bash)" "$test_dir/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() {
|
vterm_shutdown() {
|
||||||
local test_dir="$1" ; shift
|
rm_test_root
|
||||||
|
|
||||||
if test $FAILED -eq 0 ; then
|
|
||||||
rm -rf "$test_dir"
|
|
||||||
else
|
|
||||||
echo "$FAIL_SUMMARY"
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
@ -19,7 +19,7 @@ from tests.modules.lib.terminal import (ExpectProcess, MutableDimensions,
|
|||||||
do_terminal_tests, get_env)
|
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):
|
def tmux_logs_iter(test_dir):
|
||||||
@ -28,7 +28,7 @@ def tmux_logs_iter(test_dir):
|
|||||||
|
|
||||||
|
|
||||||
def print_tmux_logs():
|
def print_tmux_logs():
|
||||||
for f in tmux_logs_iter(VTERM_TEST_DIR):
|
for f in tmux_logs_iter(TEST_ROOT):
|
||||||
print('_' * 80)
|
print('_' * 80)
|
||||||
print(os.path.basename(f) + ':')
|
print(os.path.basename(f) + ':')
|
||||||
print('=' * 80)
|
print('=' * 80)
|
||||||
@ -57,15 +57,15 @@ def tmux_fin_cb(p, cmd, env):
|
|||||||
try:
|
try:
|
||||||
check_call([
|
check_call([
|
||||||
cmd, '-S', env['POWERLINE_TMUX_SOCKET_PATH'], 'kill-server'
|
cmd, '-S', env['POWERLINE_TMUX_SOCKET_PATH'], 'kill-server'
|
||||||
], env=env, cwd=VTERM_TEST_DIR)
|
], env=env, cwd=TEST_ROOT)
|
||||||
except Exception:
|
except Exception:
|
||||||
print_exc()
|
print_exc()
|
||||||
for f in tmux_logs_iter(VTERM_TEST_DIR):
|
for f in tmux_logs_iter(TEST_ROOT):
|
||||||
os.unlink(f)
|
os.unlink(f)
|
||||||
|
|
||||||
|
|
||||||
def main(attempts=3):
|
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')
|
tmux_exe = os.path.join(vterm_path, 'tmux')
|
||||||
|
|
||||||
@ -73,7 +73,7 @@ def main(attempts=3):
|
|||||||
if os.path.exists(socket_path):
|
if os.path.exists(socket_path):
|
||||||
os.unlink(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((
|
'POWERLINE_THEME_OVERRIDES': ';'.join((
|
||||||
key + '=' + json.dumps(val)
|
key + '=' + json.dumps(val)
|
||||||
for key, val in (
|
for key, val in (
|
||||||
@ -99,7 +99,7 @@ def main(attempts=3):
|
|||||||
conf_path = os.path.abspath('powerline/bindings/tmux/powerline.conf')
|
conf_path = os.path.abspath('powerline/bindings/tmux/powerline.conf')
|
||||||
conf_line = 'source "' + (
|
conf_line = 'source "' + (
|
||||||
conf_path.replace('\\', '\\\\').replace('"', '\\"')) + '"\n'
|
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:
|
with open(conf_file, 'w') as cf_fd:
|
||||||
cf_fd.write(conf_line)
|
cf_fd.write(conf_line)
|
||||||
|
|
||||||
@ -235,7 +235,7 @@ def main(attempts=3):
|
|||||||
dim=dim,
|
dim=dim,
|
||||||
args=args,
|
args=args,
|
||||||
env=env,
|
env=env,
|
||||||
cwd=VTERM_TEST_DIR,
|
cwd=TEST_ROOT,
|
||||||
fin_cb=tmux_fin_cb,
|
fin_cb=tmux_fin_cb,
|
||||||
last_attempt_cb=print_tmux_logs,
|
last_attempt_cb=print_tmux_logs,
|
||||||
)
|
)
|
||||||
|
@ -4,14 +4,12 @@
|
|||||||
|
|
||||||
enter_suite tmux
|
enter_suite tmux
|
||||||
|
|
||||||
VTERM_TEST_DIR="$ROOT/tests/vterm_tmux"
|
vterm_setup tmux
|
||||||
|
|
||||||
vterm_setup "$VTERM_TEST_DIR"
|
ln -s "$(which env)" "$TEST_ROOT/path"
|
||||||
|
ln -s "$(which cut)" "$TEST_ROOT/path"
|
||||||
ln -s "$(which env)" "$VTERM_TEST_DIR/path"
|
ln -s "$ROOT/scripts/powerline-render" "$TEST_ROOT/path"
|
||||||
ln -s "$(which cut)" "$VTERM_TEST_DIR/path"
|
ln -s "$ROOT/scripts/powerline-config" "$TEST_ROOT/path"
|
||||||
ln -s "$ROOT/scripts/powerline-render" "$VTERM_TEST_DIR/path"
|
|
||||||
ln -s "$ROOT/scripts/powerline-config" "$VTERM_TEST_DIR/path"
|
|
||||||
|
|
||||||
test_tmux() {
|
test_tmux() {
|
||||||
if test "$PYTHON_IMPLEMENTATION" = PyPy; then
|
if test "$PYTHON_IMPLEMENTATION" = PyPy; then
|
||||||
@ -22,7 +20,7 @@ test_tmux() {
|
|||||||
if ! which "${POWERLINE_TMUX_EXE}" ; then
|
if ! which "${POWERLINE_TMUX_EXE}" ; then
|
||||||
return 0
|
return 0
|
||||||
fi
|
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"
|
f="$ROOT/tests/test_in_vterm/test_tmux.py"
|
||||||
if ! "${PYTHON}" "$f" ; then
|
if ! "${PYTHON}" "$f" ; then
|
||||||
local test_name="$("$POWERLINE_TMUX_EXE" -V 2>&1 | cut -d' ' -f2)"
|
local test_name="$("$POWERLINE_TMUX_EXE" -V 2>&1 | cut -d' ' -f2)"
|
||||||
@ -41,6 +39,6 @@ else
|
|||||||
test_tmux || true
|
test_tmux || true
|
||||||
fi
|
fi
|
||||||
|
|
||||||
vterm_shutdown "$VTERM_TEST_DIR"
|
vterm_shutdown
|
||||||
|
|
||||||
exit_suite
|
exit_suite
|
||||||
|
@ -4,41 +4,62 @@ from __future__ import (unicode_literals, division, absolute_import, print_funct
|
|||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import json
|
|
||||||
|
|
||||||
from time import sleep
|
from time import sleep
|
||||||
from subprocess import check_call
|
from subprocess import check_call
|
||||||
from glob import glob1
|
from glob import glob1
|
||||||
from traceback import print_exc
|
from traceback import print_exc
|
||||||
|
|
||||||
|
from powerline.lib.dict import updated
|
||||||
|
|
||||||
from tests.modules.lib.terminal import (ExpectProcess, MutableDimensions,
|
from tests.modules.lib.terminal import (ExpectProcess, MutableDimensions,
|
||||||
do_terminal_tests, get_env)
|
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):
|
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')
|
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)
|
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 = (
|
tests = (
|
||||||
)
|
)
|
||||||
|
|
||||||
args = []
|
|
||||||
|
|
||||||
return do_terminal_tests(
|
return do_terminal_tests(
|
||||||
tests=tests,
|
tests=tests,
|
||||||
cmd=vim_exe,
|
cmd=vim_exe,
|
||||||
dim=dim,
|
dim=dim,
|
||||||
args=args,
|
args=args,
|
||||||
env=env,
|
env=env,
|
||||||
cwd=VTERM_TEST_DIR,
|
cwd=TEST_ROOT,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@ -1,10 +1,11 @@
|
|||||||
#!/bin/sh
|
#!/bin/sh
|
||||||
. tests/shlib/common.sh
|
. tests/shlib/common.sh
|
||||||
|
. tests/shlib/vterm.sh
|
||||||
. tests/shlib/vim.sh
|
. tests/shlib/vim.sh
|
||||||
|
|
||||||
enter_suite vim
|
enter_suite vim
|
||||||
|
|
||||||
make_test_root
|
vterm_setup vim
|
||||||
|
|
||||||
# Define some overrides. These ones must be ignored and do not affect Vim
|
# Define some overrides. These ones must be ignored and do not affect Vim
|
||||||
# status/tab lines.
|
# status/tab lines.
|
||||||
@ -46,4 +47,6 @@ if test -e "$OLD_VIM" ; then
|
|||||||
done
|
done
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
vterm_shutdown
|
||||||
|
|
||||||
exit_suite
|
exit_suite
|
||||||
|
Loading…
x
Reference in New Issue
Block a user