fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
5ade4a037
master
1#!/usr/bin/env python3 2import os 3import platform 4import signal 5import sys 6from pexpect_helper import SpawnedProc 7 8if "CI" in os .environ and platform .system ()in ["Darwin" ,"FreeBSD" ]: 9sys .exit (127 ) 10 11sp = SpawnedProc () 12send ,sendline ,sleep ,expect_prompt ,expect_str ,expect_re = ( 13sp .send , 14sp .sendline , 15sp .sleep , 16sp .expect_prompt , 17sp .expect_str , 18sp .expect_re , 19) 20 21# Ensure that signals don't tear escape sequences. See #8628. 22expect_prompt () 23 24# Allow for long delays before matching escape. 25sendline (r"set -g fish_escape_delay_ms 2000" ) 26expect_prompt () 27 28# Set up a handler for SIGUSR1. 29sendline (r"set -g sigusr1_count 0" ) 30expect_prompt () 31sendline (r"set -g wacky_count 0" ) 32expect_prompt () 33 34sendline ( 35r""" 36function usr1_handler --on-signal SIGUSR1; 37set sigusr1_count (math $sigusr1_count + 1); 38echo Got SIGUSR1 $sigusr1_count; 39commandline -f repaint; 40end 41""" .strip ().replace ("\n" ,os .linesep ) 42) 43expect_prompt () 44 45# Set up a wacky binding with an escape. 46sendline ( 47r""" 48function wacky_handler 49set wacky_count (math $wacky_count + 1); 50echo Wacky Handler $wacky_count 51end 52""" .strip ().replace ("\n" ,os .linesep ) 53) 54expect_prompt () 55 56sendline (r"bind a,b,c,\e,d,e,f wacky_handler" ) 57expect_prompt () 58 59sendline ("echo 'Catch' 'up'" ) 60expect_prompt ("Catch up" ) 61 62# We can respond to SIGUSR1. 63sleep (1 ) 64os .kill (sp .spawn .pid ,signal .SIGUSR1 ) 65expect_str (r"Got SIGUSR1 1" ) 66sendline (r"" ) 67expect_prompt () 68 69# Our wacky binding works. 70send ("abc\x1bdef" ) 71expect_str (r"Wacky Handler 1" ) 72sendline (r"" ) 73expect_prompt () 74 75# Now we interleave the sequence with SIGUSR1. 76# What we expect to happen is that the signal is "shuffled to the front" ahead of the key events. 77send ("abc" ) 78sleep (0.05 ) 79os .kill (sp .spawn .pid ,signal .SIGUSR1 ) 80sleep (0.05 ) 81send ("\x1bdef" ) 82expect_str (r"Got SIGUSR1 2" ) 83expect_str (r"Wacky Handler 2" ) 84sendline (r"" ) 85expect_prompt () 86 87# As before but it comes after the ESC. 88# The signal will arrive while we are waiting in readch_timed(). 89send ("abc\x1b" ) 90sleep (0.05 ) 91os .kill (sp .spawn .pid ,signal .SIGUSR1 ) 92sleep (0.05 ) 93send ("def" ) 94expect_str (r"Got SIGUSR1 3" ) 95expect_str (r"Wacky Handler 3" ) 96sendline (r"" ) 97expect_prompt ()