mirror of
https://github.com/kovidgoyal/kitty
synced 2026-07-17 14:04:52 +02:00
Merge branch 'copilot/fix-issue-9910' of https://github.com/kovidgoyal/kitty
Fixes #9910
This commit is contained in:
@@ -650,19 +650,26 @@ class TestDataTypes(BaseTest):
|
||||
shutil.rmtree(dot_config)
|
||||
with tempfile.TemporaryDirectory() as tdir:
|
||||
with open(tdir + '/macos-launch-services-cmdline', 'w') as f:
|
||||
print('kitty +runpy "import sys; print(sys.argv[-1])"', file=f)
|
||||
print('next-line', file=f)
|
||||
print()
|
||||
print('kitty --title from-file', file=f)
|
||||
if is_macos:
|
||||
env = os.environ.copy()
|
||||
env['KITTY_CONFIG_DIRECTORY'] = tdir
|
||||
env['KITTY_LAUNCHED_BY_LAUNCH_SERVICES'] = '1'
|
||||
cp = subprocess.run([kitty_exe(), '+runpy', 'import json, sys; print(json.dumps(sys.argv))'], env=env, stdout=subprocess.PIPE)
|
||||
actual = cp.stdout.strip().decode()
|
||||
# Test 1: file args are loaded when no extra user args are present
|
||||
cp = subprocess.run([kitty_exe(), '+testing-launcher-code'], env=env, stdout=subprocess.PIPE)
|
||||
actual = cp.stdout.decode()
|
||||
if cp.returncode != 0:
|
||||
print(actual)
|
||||
raise AssertionError(f'kitty +runpy failed with return code: {cp.returncode}')
|
||||
self.ae('next-line', actual)
|
||||
raise AssertionError(f'kitty +testing-launcher-code failed with return code: {cp.returncode}')
|
||||
self.assertIn('from-file', actual)
|
||||
# Test 2: extra args passed via open --args are appended after file args
|
||||
cp = subprocess.run([kitty_exe(), '+testing-launcher-code', '--title', 'from-args'], env=env, stdout=subprocess.PIPE)
|
||||
actual = cp.stdout.decode()
|
||||
if cp.returncode != 0:
|
||||
print(actual)
|
||||
raise AssertionError(f'kitty +testing-launcher-code failed with return code: {cp.returncode}')
|
||||
# from-args overrides from-file because user args are appended after file args
|
||||
self.assertIn('from-args', actual)
|
||||
os.makedirs(tdir + '/good/kitty')
|
||||
open(tdir + '/good/kitty/kitty.conf', 'w').close()
|
||||
data = os.urandom(32879)
|
||||
|
||||
@@ -125,14 +125,18 @@ version
|
||||
|
||||
|
||||
def launcher(self):
|
||||
import tempfile
|
||||
from kitty.constants import is_macos
|
||||
kexe = kitty_exe()
|
||||
cfgdir = None
|
||||
def get_report(cmdline: str, launch_services= False):
|
||||
def get_report(cmdline: str, launch_services= False, config_dir: str = ''):
|
||||
nonlocal cfgdir
|
||||
args = list(shlex_split(cmdline))
|
||||
env = dict(os.environ)
|
||||
if launch_services:
|
||||
env['KITTY_LAUNCHED_BY_LAUNCH_SERVICES'] = '1'
|
||||
if config_dir:
|
||||
env['KITTY_CONFIG_DIRECTORY'] = config_dir
|
||||
cp = subprocess.run([kexe, "+testing-launcher-code"] + args, env=env, stdout=subprocess.PIPE)
|
||||
self.assertEqual(cp.returncode, 0)
|
||||
ans = {}
|
||||
@@ -200,6 +204,17 @@ def launcher(self):
|
||||
dt('--detach --session=moose --detached-log=xyz', detached_log='xyz', session='moose')
|
||||
pn('+kitten panel -1 --edge=left', edge='left')
|
||||
|
||||
if is_macos:
|
||||
with tempfile.TemporaryDirectory() as tdir:
|
||||
with open(tdir + '/macos-launch-services-cmdline', 'w') as f:
|
||||
f.write('kitty --title from-file\n')
|
||||
# File args are used when launched by launch services
|
||||
r, output = get_report('', launch_services=True, config_dir=tdir)
|
||||
self.assertEqual(r.get('title'), 'from-file', f'Expected title=from-file in:\n{output}')
|
||||
# User args passed via open --args are appended after file args (and override them)
|
||||
r, output = get_report('--title from-args', launch_services=True, config_dir=tdir)
|
||||
self.assertEqual(r.get('title'), 'from-args', f'Expected title=from-args to override from-file in:\n{output}')
|
||||
|
||||
|
||||
def conf_parsing(self):
|
||||
from kitty.config import defaults, load_config
|
||||
|
||||
Reference in New Issue
Block a user