From 261057396c8b7f1925a4a78f95449e1f7be1afb0 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Mon, 21 Feb 2022 19:29:35 +0530 Subject: [PATCH] Fix zsh integration test on CI Also, add various other robustness improvements to the test --- .github/workflows/ci.py | 3 +++ kitty_tests/shell_integration.py | 15 ++++++++++----- test.py | 2 +- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.py b/.github/workflows/ci.py index 87273e05b..b7ebed1e8 100644 --- a/.github/workflows/ci.py +++ b/.github/workflows/ci.py @@ -38,6 +38,9 @@ def install_deps(): ' libxcursor-dev libxcb-xkb-dev libdbus-1-dev libxkbcommon-dev libharfbuzz-dev libx11-xcb-dev zsh' ' libpng-dev liblcms2-dev libfontconfig-dev libxkbcommon-x11-dev libcanberra-dev librsync-dev uuid-dev' ' zsh bash dash fish') + # for some reason these directories are world writable which causes zsh + # compinit to break + run('sudo chmod -R og-w /usr/share/zsh') if is_bundle: install_bundle() else: diff --git a/kitty_tests/shell_integration.py b/kitty_tests/shell_integration.py index 0af158967..2132b822a 100644 --- a/kitty_tests/shell_integration.py +++ b/kitty_tests/shell_integration.py @@ -8,7 +8,7 @@ import tempfile import unittest from contextlib import contextmanager -from kitty.constants import terminfo_dir +from kitty.constants import kitty_base_dir, terminfo_dir from kitty.fast_data_types import CURSOR_BEAM from kitty.shell_integration import setup_zsh_env @@ -22,13 +22,17 @@ def safe_env_for_running_shell(home_dir, rc='', shell='zsh'): 'TERM': 'xterm-kitty', 'TERMINFO': terminfo_dir, 'KITTY_SHELL_INTEGRATION': 'enabled', + 'KITTY_INSTALLATION_DIR': kitty_base_dir, } + for x in ('USER', 'LANG'): + if os.environ.get(x): + ans[x] = os.environ[x] if shell == 'zsh': ans['ZLE_RPROMPT_INDENT'] = '0' with open(os.path.join(home_dir, '.zshenv'), 'w') as f: print('unset GLOBAL_RCS', file=f) with open(os.path.join(home_dir, '.zshrc'), 'w') as f: - print(rc, file=f) + print(rc + '\n', file=f) setup_zsh_env(ans) return ans @@ -36,10 +40,10 @@ def safe_env_for_running_shell(home_dir, rc='', shell='zsh'): class ShellIntegration(BaseTest): @contextmanager - def run_shell(self, shell='zsh', rc=''): + def run_shell(self, shell='zsh', rc='', cmd='{shell} -il'): home_dir = os.path.realpath(tempfile.mkdtemp()) try: - pty = self.create_pty(f'{shell} -il', cwd=home_dir, env=safe_env_for_running_shell(home_dir, rc)) + pty = self.create_pty(cmd.format(**locals()), cwd=home_dir, env=safe_env_for_running_shell(home_dir, rc)) i = 10 while i > 0 and not pty.screen_contents().strip(): pty.process_input_from_child() @@ -66,4 +70,5 @@ RPS1="{rps1}" self.ae(pty.callbacks.titlebuf, '~') pty.send_cmd_to_child('mkdir test && ls -a') pty.wait_till(lambda: pty.screen_contents().count(ps1) == 2) - self.ae(pty.last_cmd_output(), str(pty.screen.line(1))) + q = '\n'.join(str(pty.screen.line(i)) for i in range(1, pty.screen.cursor.y)) + self.ae(pty.last_cmd_output(), q) diff --git a/test.py b/test.py index 1383415ea..26e484507 100755 --- a/test.py +++ b/test.py @@ -5,8 +5,8 @@ import importlib import os import sys import warnings -from tempfile import TemporaryDirectory from contextlib import contextmanager +from tempfile import TemporaryDirectory from typing import Iterator base = os.path.dirname(os.path.abspath(__file__))