2015-01-11 01:09:14 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
# vim:fileencoding=utf-8:noet
|
|
|
|
from __future__ import (unicode_literals, division, absolute_import, print_function)
|
|
|
|
|
|
|
|
import os
|
2015-02-19 09:35:29 +01:00
|
|
|
import sys
|
2017-04-30 01:13:41 +02:00
|
|
|
import json
|
2015-01-11 01:09:14 +01:00
|
|
|
|
|
|
|
from time import sleep
|
|
|
|
from subprocess import check_call
|
|
|
|
from difflib import ndiff
|
2015-02-19 09:35:29 +01:00
|
|
|
from glob import glob1
|
2015-01-11 01:09:14 +01:00
|
|
|
|
|
|
|
from powerline.lib.unicode import u
|
2015-01-16 20:44:34 +01:00
|
|
|
from powerline.bindings.tmux import get_tmux_version
|
|
|
|
from powerline import get_fallback_logger
|
2015-01-11 01:09:14 +01:00
|
|
|
|
|
|
|
from tests.lib.terminal import ExpectProcess
|
|
|
|
|
|
|
|
|
2015-08-21 17:39:52 +02:00
|
|
|
VTERM_TEST_DIR = os.path.abspath('tests/vterm_tmux')
|
2015-02-19 09:35:29 +01:00
|
|
|
|
|
|
|
|
2017-04-02 17:29:25 +02:00
|
|
|
def convert_expected_result(p, expected_result):
|
|
|
|
return p.get_highlighted_text(expected_result, {})
|
|
|
|
|
|
|
|
|
2015-01-11 01:09:14 +01:00
|
|
|
def cell_properties_key_to_shell_escape(cell_properties_key):
|
|
|
|
fg, bg, bold, underline, italic = cell_properties_key
|
|
|
|
return('\x1b[38;2;{0};48;2;{1}{bold}{underline}{italic}m'.format(
|
|
|
|
';'.join((str(i) for i in fg)),
|
|
|
|
';'.join((str(i) for i in bg)),
|
|
|
|
bold=(';1' if bold else ''),
|
|
|
|
underline=(';4' if underline else ''),
|
|
|
|
italic=(';3' if italic else ''),
|
|
|
|
))
|
|
|
|
|
|
|
|
|
2015-02-19 09:35:29 +01:00
|
|
|
def test_expected_result(p, expected_result, cols, rows, print_logs):
|
2017-04-30 01:13:41 +02:00
|
|
|
expected_text, attrs = expected_result
|
2015-05-10 14:33:43 +02:00
|
|
|
attempts = 3
|
2015-02-07 03:00:37 +01:00
|
|
|
result = None
|
|
|
|
while attempts:
|
2017-04-02 17:29:25 +02:00
|
|
|
actual_text, all_attrs = p.get_row(rows - 1, attrs)
|
|
|
|
if actual_text == expected_text:
|
2015-02-07 03:00:37 +01:00
|
|
|
return True
|
|
|
|
attempts -= 1
|
|
|
|
print('Actual result does not match expected. Attempts left: {0}.'.format(attempts))
|
2015-02-07 09:14:09 +01:00
|
|
|
sleep(2)
|
2015-02-07 03:00:37 +01:00
|
|
|
print('Result:')
|
2017-04-02 17:29:25 +02:00
|
|
|
print(actual_text)
|
2015-02-07 03:00:37 +01:00
|
|
|
print('Expected:')
|
2017-04-02 17:29:25 +02:00
|
|
|
print(expected_text)
|
|
|
|
print('Attributes:')
|
|
|
|
print(all_attrs)
|
2015-02-07 03:00:37 +01:00
|
|
|
p.send(b'powerline-config tmux setup\n')
|
|
|
|
sleep(5)
|
|
|
|
print('Screen:')
|
2017-04-02 17:29:25 +02:00
|
|
|
screen, screen_attrs = p.get_screen(attrs)
|
|
|
|
print(screen)
|
|
|
|
print(screen_attrs)
|
2015-02-07 03:00:37 +01:00
|
|
|
print('_' * 80)
|
|
|
|
print('Diff:')
|
|
|
|
print('=' * 80)
|
2017-04-02 17:29:25 +02:00
|
|
|
print(''.join((u(line) for line in ndiff([actual_text], [expected_text]))))
|
2015-02-19 09:35:29 +01:00
|
|
|
if print_logs:
|
|
|
|
for f in glob1(VTERM_TEST_DIR, '*.log'):
|
|
|
|
print('_' * 80)
|
|
|
|
print(os.path.basename(f) + ':')
|
|
|
|
print('=' * 80)
|
|
|
|
with open(f, 'r') as F:
|
|
|
|
for line in F:
|
|
|
|
sys.stdout.write(line)
|
|
|
|
os.unlink(f)
|
2015-02-07 03:00:37 +01:00
|
|
|
return False
|
|
|
|
|
|
|
|
|
2017-04-30 01:13:41 +02:00
|
|
|
def get_expected_result(tmux_version,
|
|
|
|
expected_result_old,
|
|
|
|
expected_result_1_7=None,
|
|
|
|
expected_result_new=None,
|
|
|
|
expected_result_2_0=None):
|
2015-05-23 15:10:46 +02:00
|
|
|
if tmux_version >= (2, 0) and expected_result_2_0:
|
|
|
|
return expected_result_2_0
|
|
|
|
elif tmux_version >= (1, 8) and expected_result_new:
|
|
|
|
return expected_result_new
|
|
|
|
elif tmux_version >= (1, 7) and expected_result_1_7:
|
|
|
|
return expected_result_1_7
|
|
|
|
else:
|
|
|
|
return expected_result_old
|
|
|
|
|
|
|
|
|
2015-02-19 09:19:38 +01:00
|
|
|
def main(attempts=3):
|
2015-01-11 01:09:14 +01:00
|
|
|
vterm_path = os.path.join(VTERM_TEST_DIR, 'path')
|
2015-02-21 13:18:59 +01:00
|
|
|
socket_path = 'tmux-socket'
|
2015-01-11 01:09:14 +01:00
|
|
|
rows = 50
|
|
|
|
cols = 200
|
|
|
|
|
2015-01-16 19:45:48 +01:00
|
|
|
tmux_exe = os.path.join(vterm_path, 'tmux')
|
|
|
|
|
2015-02-20 21:47:18 +01:00
|
|
|
if os.path.exists('tests/bot-ci/deps/libvterm/libvterm.so'):
|
|
|
|
lib = 'tests/bot-ci/deps/libvterm/libvterm.so'
|
|
|
|
else:
|
2015-02-20 21:48:26 +01:00
|
|
|
lib = os.environ.get('POWERLINE_LIBVTERM', 'libvterm.so')
|
2015-02-20 21:47:18 +01:00
|
|
|
|
2017-04-30 01:13:41 +02:00
|
|
|
env = {
|
|
|
|
# Reasoning:
|
|
|
|
# 1. vt* TERMs (used to be vt100 here) make tmux-1.9 use
|
|
|
|
# different and identical colors for inactive windows. This
|
|
|
|
# is not like tmux-1.6: foreground color is different from
|
|
|
|
# separator color and equal to (0, 102, 153) for some reason
|
|
|
|
# (separator has correct color). tmux-1.8 is fine, so are
|
|
|
|
# older versions (though tmux-1.6 and tmux-1.7 do not have
|
|
|
|
# highlighting for previously active window) and my system
|
|
|
|
# tmux-1.9a.
|
|
|
|
# 2. screen, xterm and some other non-256color terminals both
|
|
|
|
# have the same issue and make libvterm emit complains like
|
|
|
|
# `Unhandled CSI SGR 3231`.
|
|
|
|
# 3. screen-256color, xterm-256color and other -256color
|
|
|
|
# terminals make libvterm emit complains about unhandled
|
|
|
|
# escapes to stderr.
|
|
|
|
# 4. `st-256color` does not have any of the above problems, but
|
|
|
|
# it may be not present on the target system because it is
|
|
|
|
# installed with x11-terms/st and not with sys-libs/ncurses.
|
|
|
|
#
|
|
|
|
# For the given reasons decision was made: to fix tmux-1.9 tests
|
|
|
|
# and not make libvterm emit any data to stderr st-256color
|
|
|
|
# $TERM should be used, up until libvterm has its own terminfo
|
|
|
|
# database entry (if it ever will). To make sure that relevant
|
|
|
|
# terminfo entry is present on the target system it should be
|
|
|
|
# distributed with powerline test package. To make distribution
|
|
|
|
# not require modifying anything outside of powerline test
|
|
|
|
# directory TERMINFO variable is set.
|
|
|
|
'TERMINFO': os.path.join(VTERM_TEST_DIR, 'terminfo'),
|
|
|
|
'TERM': 'st-256color',
|
|
|
|
'PATH': vterm_path,
|
|
|
|
'SHELL': os.path.join(VTERM_TEST_DIR, 'path', 'bash'),
|
|
|
|
'POWERLINE_CONFIG_PATHS': os.path.abspath('powerline/config_files'),
|
|
|
|
'POWERLINE_COMMAND': 'powerline-render',
|
|
|
|
'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'),
|
|
|
|
)
|
|
|
|
)),
|
|
|
|
'LD_LIBRARY_PATH': os.environ.get('LD_LIBRARY_PATH', ''),
|
|
|
|
'PYTHONPATH': os.environ.get('PYTHONPATH', ''),
|
|
|
|
}
|
|
|
|
|
2015-01-11 01:09:14 +01:00
|
|
|
try:
|
|
|
|
p = ExpectProcess(
|
2015-02-20 21:47:18 +01:00
|
|
|
lib=lib,
|
2015-01-11 01:09:14 +01:00
|
|
|
rows=rows,
|
|
|
|
cols=cols,
|
2015-01-16 19:45:48 +01:00
|
|
|
cmd=tmux_exe,
|
2015-01-11 01:09:14 +01:00
|
|
|
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', os.path.abspath('powerline/bindings/tmux/powerline.conf'),
|
|
|
|
# Run bash three times
|
|
|
|
'new-session', 'bash --norc --noprofile -i', ';',
|
|
|
|
'new-window', 'bash --norc --noprofile -i', ';',
|
|
|
|
'new-window', 'bash --norc --noprofile -i', ';',
|
|
|
|
],
|
|
|
|
cwd=VTERM_TEST_DIR,
|
2017-04-30 01:13:41 +02:00
|
|
|
env=env,
|
2015-01-11 01:09:14 +01:00
|
|
|
)
|
|
|
|
p.start()
|
2015-05-23 15:10:46 +02:00
|
|
|
sleep(5)
|
|
|
|
tmux_version = get_tmux_version(get_fallback_logger())
|
2017-04-30 01:13:41 +02:00
|
|
|
expected_result = get_expected_result(
|
|
|
|
tmux_version,
|
|
|
|
expected_result_old=(
|
|
|
|
'{1: 0 }{2: }{3: S2 string here }{4: 0 }'
|
|
|
|
'{5:| }{6:bash }{3: }{4: 1- }'
|
|
|
|
'{5:| }{6:bash }{3: }{7: }'
|
|
|
|
'{8:2* | }{9:bash }{10: }'
|
|
|
|
'{3:' + (' ' * 124) + '}'
|
|
|
|
'{5: }{11: S1 string here }', {
|
|
|
|
((0, 0, 0), (243, 243, 243), 1, 0, 0): 1,
|
|
|
|
((243, 243, 243), (11, 11, 11), 0, 0, 0): 2,
|
|
|
|
((255, 255, 255), (11, 11, 11), 0, 0, 0): 3,
|
|
|
|
((133, 133, 133), (11, 11, 11), 0, 0, 0): 4,
|
|
|
|
((88, 88, 88), (11, 11, 11), 0, 0, 0): 5,
|
|
|
|
((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,
|
|
|
|
((199, 199, 199), (88, 88, 88), 0, 0, 0): 11,
|
|
|
|
}),
|
|
|
|
expected_result_new=(
|
|
|
|
'{1: 0 }{2: }{3: S2 string here }{4: 0 }'
|
|
|
|
'{5:| }{6:bash }{3: }{4: 1- }'
|
|
|
|
'{5:| }{7:bash }{3: }{8: }'
|
|
|
|
'{9:2* | }{10:bash }{7: }'
|
|
|
|
'{3:' + (' ' * 124) + '}'
|
|
|
|
'{5: }{11: S1 string here }', {
|
|
|
|
((0, 0, 0), (243, 243, 243), 1, 0, 0): 1,
|
|
|
|
((243, 243, 243), (11, 11, 11), 0, 0, 0): 2,
|
|
|
|
((255, 255, 255), (11, 11, 11), 0, 0, 0): 3,
|
|
|
|
((133, 133, 133), (11, 11, 11), 0, 0, 0): 4,
|
|
|
|
((88, 88, 88), (11, 11, 11), 0, 0, 0): 5,
|
|
|
|
((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,
|
|
|
|
((199, 199, 199), (88, 88, 88), 0, 0, 0): 11,
|
|
|
|
}),
|
|
|
|
expected_result_2_0=(
|
|
|
|
'{1: 0 }{2: }{3: S2 string here }{4: 0 }'
|
|
|
|
'{5:| }{6:bash }{3: }{4: 1- }'
|
|
|
|
'{5:| }{7:bash }{3: }{8: }'
|
|
|
|
'{9:2* | }{10:bash }{7: }'
|
|
|
|
'{3:' + (' ' * 125) + '}{5: }{11: S1 string here }', {
|
|
|
|
((0, 0, 0), (243, 243, 243), 1, 0, 0): 1,
|
|
|
|
((243, 243, 243), (11, 11, 11), 0, 0, 0): 2,
|
|
|
|
((255, 255, 255), (11, 11, 11), 0, 0, 0): 3,
|
|
|
|
((133, 133, 133), (11, 11, 11), 0, 0, 0): 4,
|
|
|
|
((88, 88, 88), (11, 11, 11), 0, 0, 0): 5,
|
|
|
|
((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,
|
|
|
|
((199, 199, 199), (88, 88, 88), 0, 0, 0): 11,
|
|
|
|
}),
|
|
|
|
)
|
2015-05-23 15:10:46 +02:00
|
|
|
ret = None
|
2015-02-19 09:35:29 +01:00
|
|
|
if not test_expected_result(p, expected_result, cols, rows, not attempts):
|
2015-02-19 09:19:38 +01:00
|
|
|
if attempts:
|
2015-02-21 01:42:58 +01:00
|
|
|
pass
|
|
|
|
# Will rerun main later.
|
2015-02-19 09:19:38 +01:00
|
|
|
else:
|
2015-05-23 15:10:46 +02:00
|
|
|
ret = False
|
|
|
|
elif ret is not False:
|
|
|
|
ret = True
|
|
|
|
cols = 40
|
|
|
|
p.resize(rows, cols)
|
|
|
|
sleep(5)
|
2017-04-30 01:13:41 +02:00
|
|
|
expected_result = get_expected_result(
|
|
|
|
tmux_version,
|
|
|
|
expected_result_old=('{1:' + (' ' * cols) + '}', {
|
|
|
|
((255, 255, 255), (11, 11, 11), 0, 0, 0): 1,
|
|
|
|
}),
|
|
|
|
expected_result_1_7=(
|
|
|
|
'{1: 0 }'
|
|
|
|
'{2: }{3: <}{4:h }{3: }{5: }'
|
|
|
|
'{6:2* | }{7:bash }{8: }{3: }{9: }'
|
|
|
|
'{10: S1 string here }', {
|
|
|
|
((0, 0, 0), (243, 243, 243), 1, 0, 0): 1,
|
|
|
|
((243, 243, 243), (11, 11, 11), 0, 0, 0): 2,
|
|
|
|
((255, 255, 255), (11, 11, 11), 0, 0, 0): 3,
|
|
|
|
((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,
|
|
|
|
((88, 88, 88), (11, 11, 11), 0, 0, 0): 9,
|
|
|
|
((199, 199, 199), (88, 88, 88), 0, 0, 0): 10,
|
|
|
|
}),
|
|
|
|
expected_result_new=(
|
|
|
|
'{1: 0 }'
|
|
|
|
'{2: }{3: <}{4:h }{3: }{5: }'
|
|
|
|
'{6:2* | }{7:bash }{4: }{3: }{8: }'
|
|
|
|
'{9: S1 string here }', {
|
|
|
|
((0, 0, 0), (243, 243, 243), 1, 0, 0): 1,
|
|
|
|
((243, 243, 243), (11, 11, 11), 0, 0, 0): 2,
|
|
|
|
((255, 255, 255), (11, 11, 11), 0, 0, 0): 3,
|
|
|
|
((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,
|
|
|
|
((88, 88, 88), (11, 11, 11), 0, 0, 0): 8,
|
|
|
|
((199, 199, 199), (88, 88, 88), 0, 0, 0): 9,
|
|
|
|
}),
|
|
|
|
expected_result_2_0=(
|
|
|
|
'{1: 0 }'
|
|
|
|
'{2: }{3:<}{4:ash }{3: }{5: }'
|
|
|
|
'{6:2* | }{7:bash }{4: }{8: }'
|
|
|
|
'{9: S1 string here }', {
|
|
|
|
((0, 0, 0), (243, 243, 243), 1, 0, 0): 1,
|
|
|
|
((243, 243, 243), (11, 11, 11), 0, 0, 0): 2,
|
|
|
|
((255, 255, 255), (11, 11, 11), 0, 0, 0): 3,
|
|
|
|
((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,
|
|
|
|
((88, 88, 88), (11, 11, 11), 0, 0, 0): 8,
|
|
|
|
((199, 199, 199), (88, 88, 88), 0, 0, 0): 9,
|
|
|
|
}),
|
|
|
|
)
|
2015-05-23 15:10:46 +02:00
|
|
|
if not test_expected_result(p, expected_result, cols, rows, not attempts):
|
|
|
|
if attempts:
|
|
|
|
pass
|
|
|
|
else:
|
|
|
|
ret = False
|
|
|
|
elif ret is not False:
|
|
|
|
ret = True
|
|
|
|
if ret is not None:
|
|
|
|
return ret
|
2015-01-11 01:09:14 +01:00
|
|
|
finally:
|
2017-04-30 01:13:41 +02:00
|
|
|
check_call([tmux_exe, '-S', socket_path, 'kill-server'], env=env,
|
|
|
|
cwd=VTERM_TEST_DIR)
|
2015-02-21 01:42:58 +01:00
|
|
|
return main(attempts=(attempts - 1))
|
2015-01-11 01:09:14 +01:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
if main():
|
|
|
|
raise SystemExit(0)
|
|
|
|
else:
|
|
|
|
raise SystemExit(1)
|