Skip testing bash on macOS as it is too old

This commit is contained in:
Kovid Goyal 2022-02-22 14:53:46 +05:30
parent 7fe1376e34
commit b59212696a
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -8,7 +8,7 @@ import tempfile
import unittest import unittest
from contextlib import contextmanager from contextlib import contextmanager
from kitty.constants import kitty_base_dir, terminfo_dir from kitty.constants import kitty_base_dir, terminfo_dir, is_macos
from kitty.fast_data_types import CURSOR_BEAM from kitty.fast_data_types import CURSOR_BEAM
from kitty.shell_integration import rc_inset, setup_zsh_env from kitty.shell_integration import rc_inset, setup_zsh_env
@ -35,12 +35,10 @@ def safe_env_for_running_shell(home_dir, rc='', shell='zsh'):
print(rc + '\n', file=f) print(rc + '\n', file=f)
setup_zsh_env(ans) setup_zsh_env(ans)
elif shell == 'bash': elif shell == 'bash':
with open(os.path.join(home_dir, '.bash_profile'), 'w') as f: ans['ENV'] = '~/.bashrc'
print('if [ -f ~/.bashrc ]; then . ~/.bashrc; fi', file=f)
with open(os.path.join(home_dir, '.bashrc'), 'w') as f: with open(os.path.join(home_dir, '.bashrc'), 'w') as f:
# there is no way to prevent bash from reading the system # get out of POSIX mode
# /etc/profile and some distros set a PROMPT_COMMAND in it. print('set +o posix', file=f)
print('unset PROMPT_COMMAND', file=f)
# ensure LINES and COLUMNS are kept up to date # ensure LINES and COLUMNS are kept up to date
print('shopt -s checkwinsize', file=f) print('shopt -s checkwinsize', file=f)
# Not sure why bash turns off echo in this scenario # Not sure why bash turns off echo in this scenario
@ -51,11 +49,22 @@ def safe_env_for_running_shell(home_dir, rc='', shell='zsh'):
return ans return ans
def launch_cmd_for_shell(shell):
if shell == 'bash':
# Sadly we cannot use --noprofile as the idiotic Linux distros compile
# bash with -DSYS_BASHRC which causes it to unconditionally source the
# system wide bashrc file (which is distro dependent). So we use POSIX
# mode.
return 'bash --posix'
return shell
class ShellIntegration(BaseTest): class ShellIntegration(BaseTest):
@contextmanager @contextmanager
def run_shell(self, shell='zsh', rc='', cmd='{shell} -il'): def run_shell(self, shell='zsh', rc='', cmd=''):
home_dir = os.path.realpath(tempfile.mkdtemp()) home_dir = os.path.realpath(tempfile.mkdtemp())
cmd = cmd or launch_cmd_for_shell(shell)
try: try:
pty = self.create_pty(cmd.format(**locals()), cwd=home_dir, env=safe_env_for_running_shell(home_dir, rc=rc, shell=shell)) pty = self.create_pty(cmd.format(**locals()), cwd=home_dir, env=safe_env_for_running_shell(home_dir, rc=rc, shell=shell))
i = 10 i = 10
@ -78,8 +87,8 @@ RPS1="{rps1}"
q = ps1 + ' ' * (pty.screen.columns - len(ps1) - len(rps1)) + rps1 q = ps1 + ' ' * (pty.screen.columns - len(ps1) - len(rps1)) + rps1
try: try:
pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_BEAM) pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_BEAM)
except TimeoutError: except TimeoutError as e:
raise AssertionError(f'Cursor was not changed to beam. Screen contents: {repr(pty.screen_contents())}') raise AssertionError(f'Cursor was not changed to beam. Screen contents: {repr(pty.screen_contents())}') from e
self.ae(pty.screen_contents(), q) self.ae(pty.screen_contents(), q)
self.ae(pty.callbacks.titlebuf[-1], '~') self.ae(pty.callbacks.titlebuf[-1], '~')
pty.callbacks.clear() pty.callbacks.clear()
@ -105,7 +114,7 @@ RPS1="{rps1}"
self.ae('40', str(pty.screen.line(pty.screen.cursor.y - 1))) self.ae('40', str(pty.screen.line(pty.screen.cursor.y - 1)))
self.ae(q, str(pty.screen.line(pty.screen.cursor.y - 2))) self.ae(q, str(pty.screen.line(pty.screen.cursor.y - 2)))
@unittest.skipUnless(shutil.which('bash'), 'bash not installed') @unittest.skipUnless(not is_macos and shutil.which('bash'), 'macOS bash is too old' if is_macos else 'bash not installed')
def test_bash_integration(self): def test_bash_integration(self):
ps1 = 'prompt> ' ps1 = 'prompt> '
with self.run_shell( with self.run_shell(
@ -114,8 +123,8 @@ PS1="{ps1}"
''') as pty: ''') as pty:
try: try:
pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_BEAM) pty.wait_till(lambda: pty.screen.cursor.shape == CURSOR_BEAM)
except TimeoutError: except TimeoutError as e:
raise AssertionError(f'Cursor was not changed to beam. Screen contents: {repr(pty.screen_contents())}') raise AssertionError(f'Cursor was not changed to beam. Screen contents: {repr(pty.screen_contents())}') from e
pty.wait_till(lambda: pty.screen_contents().count(ps1) == 1) pty.wait_till(lambda: pty.screen_contents().count(ps1) == 1)
self.ae(pty.screen_contents(), ps1) self.ae(pty.screen_contents(), ps1)
pty.wait_till(lambda: pty.callbacks.titlebuf[-1:] == ['~']) pty.wait_till(lambda: pty.callbacks.titlebuf[-1:] == ['~'])