fork/fish-shell
git clone https://git.julia.blue/fork/fish-shell
eb535322d
master
1#!/usr/bin/env python3 2from pexpect_helper import SpawnedProc ,control 3import os 4import platform 5import sys 6 7# Skip on macOS on Github Actions because it's too resource-starved 8# and fails this a lot. 9# 10# Presumably we still have users on macOS that would notice binding errors 11if "CI" in os .environ and platform .system ()== "Darwin" : 12sys .exit (127 ) 13 14sp = SpawnedProc () 15send ,sendline ,sleep ,expect_prompt ,expect_re ,expect_str = ( 16sp .send , 17sp .sendline , 18sp .sleep , 19sp .expect_prompt , 20sp .expect_re , 21sp .expect_str , 22) 23expect_prompt () 24 25sendline ("bind ctrl-l repaint" ) 26expect_prompt () 27# Clear twice (regression test for #7280). 28send ("\f" ) 29expect_prompt (increment = False ) 30send ("\f" ) 31expect_prompt (increment = False ) 32 33# Test that kill-selection after selection is cleared doesn't crash 34sendline ("bind ctrl-space begin-selection" ) 35expect_prompt () 36sendline ("bind ctrl-w kill-selection end-selection" ) 37expect_prompt () 38send ("echo 123" ) 39# Send Ctrl-Space using CSI u encoding 40send ("\x1b[32;5u" ) 41# Send Ctrl-C to clear the command line 42send ("\x1b[99;5u" ) 43# Send Ctrl-W which used to crash 44send ("\x1b[119;5u" ) 45sendline ("bind --erase ctrl-space ctrl-w" ) 46expect_prompt () 47 48# Fish should start in default-mode (i.e., emacs) bindings. The default escape 49# timeout is 30ms. 50# 51# Because common CI systems are awful, we have to increase this: 52 53sendline ("set -g fish_escape_delay_ms 120" ) 54expect_prompt ("" ) 55 56# Verify the emacs transpose word (\et) behavior using various delays, 57# including none, after the escape character. 58 59# Start by testing with no delay. This should transpose the words. 60send ("echo abc def" ) 61send ("\033t\r" ) 62expect_prompt ("\r\n.*def abc\r\n" )# emacs transpose words, default timeout: no delay 63 64# Now test with a delay > 0 and < the escape timeout. This should transpose 65# the words. 66send ("echo ghi jkl" ) 67send ("\033" ) 68sleep (0.010 ) 69send ("t\r" ) 70# emacs transpose words, default timeout: short delay 71expect_prompt ("\r\n.*jkl ghi\r\n" ) 72 73# Now test with a delay > the escape timeout. The transposition should not 74# occur and the "t" should become part of the text that is echoed. 75send ("echo mno pqr" ) 76send ("\033" ) 77sleep (0.250 ) 78send ("t\r" ) 79# emacs transpose words, default timeout: long delay 80expect_prompt ("\r\n.*mno pqrt\r\n" ) 81 82# Now test that exactly the expected bind modes are defined 83sendline ("bind --list-modes" ) 84expect_prompt ("\r\n.*default" ,unmatched = "Unexpected bind modes" ) 85 86# Test vi key bindings. 87# This should leave vi mode in the insert state. 88sendline ("set -g fish_key_bindings fish_vi_key_bindings" ) 89expect_prompt () 90 91# Go through a prompt cycle to let fish catch up, it may be slow due to ASAN 92sendline ("echo success: default escape timeout" ) 93expect_prompt ( 94"\r\n.*success: default escape timeout" ,unmatched = "prime vi mode, default timeout" 95) 96 97send ("echo fail: default escape timeout" ) 98expect_str ("echo fail: default escape timeout" ) 99send ("\033" ) 100 101# Delay needed to allow fish to transition to vi "normal" mode. The delay is 102# longer than strictly necessary to let fish catch up as it may be slow due to 103# ASAN. 104sleep (0.250 ) 105send ("ddi" ) 106sendline ("echo success: default escape timeout" ) 107expect_prompt ( 108"\r\n.*success: default escape timeout\r\n" , 109unmatched = "vi replace line, default timeout: long delay" , 110) 111 112# Test replacing a single character. 113send ("echo TEXT" ) 114send ("\033" ) 115# Delay needed to allow fish to transition to vi "normal" mode. 116# Specifically alt+h *is* bound to __fish_man_page, 117# and I have seen this think that trigger with 300ms. 118# 119# The next step is to rip out this test because it's much more pain than it is worth 120sleep (0.400 ) 121send ("hhrAi\r" ) 122expect_prompt ( 123"\r\n.*TAXT\r\n" ,unmatched = "vi mode replace char, default timeout: long delay" 124) 125 126# Test deleting characters with 'x'. 127send ("echo MORE-TEXT" ) 128send ("\033" ) 129# Delay needed to allow fish to transition to vi "normal" mode. 130sleep (0.400 ) 131send ("xxxxx\r" ) 132 133# vi mode delete char, default timeout: long delay 134expect_prompt ( 135"\r\n.*MORE\r\n" ,unmatched = "vi mode delete char, default timeout: long delay" 136) 137 138# Test jumping forward til before a character with t 139send ("echo MORE-TEXT-IS-NICE" ) 140send ("\033" ) 141# Delay needed to allow fish to transition to vi "normal" mode. 142sleep (0.250 ) 143send ("0tTD\r" ) 144 145# vi mode forward-jump-till character, default timeout: long delay 146expect_prompt ( 147"\r\n.*MORE\r\n" , 148unmatched = "vi mode forward-jump-till character, default timeout: long delay" , 149) 150 151# DISABLED BECAUSE IT FAILS ON GITHUB ACTIONS 152# Test jumping backward til before a character with T 153# send("echo MORE-TEXT-IS-NICE") 154# send("\033") 155# # Delay needed to allow fish to transition to vi "normal" mode. 156# sleep(0.250) 157# send("TSD\r") 158# # vi mode backward-jump-till character, default timeout: long delay 159# expect_prompt( 160# "\r\n.*MORE-TEXT-IS\r\n", 161# unmatched="vi mode backward-jump-till character, default timeout: long delay", 162# ) 163 164# Test jumping backward with F and repeating 165send ("echo MORE-TEXT-IS-NICE" ) 166send ("\033" ) 167# Delay needed to allow fish to transition to vi "normal" mode. 168sleep (0.250 ) 169send ("F-;D\r" ) 170# vi mode backward-jump-to character and repeat, default timeout: long delay 171expect_prompt ( 172"\r\n.*MORE-TEXT\r\n" , 173unmatched = "vi mode backward-jump-to character and repeat, default timeout: long delay" , 174) 175 176# Test jumping backward with F w/reverse jump 177send ("echo MORE-TEXT-IS-NICE" ) 178send ("\033" ) 179# Delay needed to allow fish to transition to vi "normal" mode. 180sleep (0.250 ) 181send ("F-F-,D\r" ) 182# vi mode backward-jump-to character, and reverse, default timeout: long delay 183expect_prompt ( 184"\r\n.*MORE-TEXT-IS\r\n" , 185unmatched = "vi mode backward-jump-to character, and reverse, default timeout: long delay" , 186) 187 188# Verify that changing the escape timeout has an effect. 189send ("set -g fish_escape_delay_ms 100\r" ) 190expect_prompt () 191 192send ("echo fail: lengthened escape timeout" ) 193send ("\033" ) 194sleep (0.400 ) 195send ("ddi" ) 196sleep (0.25 ) 197send ("echo success: lengthened escape timeout\r" ) 198expect_prompt ( 199"\r\n.*success: lengthened escape timeout\r\n" , 200unmatched = "vi replace line, 100ms timeout: long delay" , 201) 202 203# Verify that we don't switch to vi normal mode if we don't wait long enough 204# after sending escape. 205send ("echo fail: no normal mode" ) 206send ("\033" ) 207sleep (0.010 ) 208send ("ddi" ) 209send ("inserted\r" ) 210expect_prompt ( 211"\r\n.*fail: no normal modediinserted\r\n" , 212unmatched = "vi replace line, 100ms timeout: short delay" , 213) 214 215# Now set it back to speed up the tests - these don't use any escape+thing bindings! 216send ("set -g fish_escape_delay_ms 50\r" ) 217expect_prompt () 218 219# Test 't' binding that contains non-zero arity function (forward-jump) followed 220# by another function (and) https://github.com/fish-shell/fish-shell/issues/2357 221send ("\033" ) 222sleep (0.200 ) 223send ("ddiecho TEXT" ) 224expect_str ("echo TEXT" ) 225send ("\033" ) 226sleep (0.200 ) 227send ("hhtTrN\r" ) 228expect_prompt ("\r\n.*TENT\r\n" ,unmatched = "Couldn't find expected output 'TENT'" ) 229 230# Test sequence key delay 231send ("set -g fish_sequence_key_delay_ms 200\r" ) 232expect_prompt () 233send ("bind -M insert jk 'commandline -i foo'\r" ) 234expect_prompt () 235send ("echo jk" ) 236send ("\r" ) 237expect_prompt ("foo" ) 238send ("echo j" ) 239sleep (0.300 ) 240send ("k\r" ) 241expect_prompt ("jk" ) 242send ("set -e fish_sequence_key_delay_ms\r" ) 243expect_prompt () 244send ("echo j" ) 245sleep (0.300 ) 246send ("k\r" ) 247expect_prompt ("foo" ) 248 249 250# Test '~' (togglecase-char) 251# HACK: Deactivated because it keeps failing on CI 252# send("\033") 253# sleep(0.100) 254# send("cc") 255# sleep(0.50) 256# send("echo some TExT\033") 257# sleep(0.300) 258# send("hh~~bbve~\r") 259# expect_prompt("\r\n.*SOME TeXT\r\n", unmatched="Couldn't find expected output 'SOME TeXT") 260 261send ("echo echo" ) 262send ("\033" ) 263sleep (0.200 ) 264send ("bgU\r" ) 265expect_prompt ("echo ECHO" ) 266 267send ("echo 125" ) 268send ("\033" ) 269sleep (0.200 ) 270send ("0$i34\r" ) 271expect_prompt ("echo 12345" ) 272 273# Test operator mode with count (d3w) 274send ("echo one two three four five" ) 275send ("\033" ) 276sleep (0.200 ) 277send ("0w" ) 278send ("d3w" ) 279sendline ("" ) 280expect_prompt ("echo four five" ) 281 282# Test count before operator (3dw) 283send ("echo one two three four five" ) 284send ("\033" ) 285sleep (0.200 ) 286send ("0w" ) 287send ("3dw" ) 288sendline ("" ) 289expect_prompt ("echo four five" ) 290 291# Test count on both (2d2w -> 4 words) 292send ("echo one two three four five six" ) 293send ("\033" ) 294sleep (0.200 ) 295send ("0w" ) 296send ("2d2w" ) 297sendline ("" ) 298expect_prompt ("echo five six" ) 299 300# Test change operator with count (c2w) 301send ("echo one two three" ) 302send ("\033" ) 303sleep (0.200 ) 304send ("0w" ) 305send ("c2wREPLACED" ) 306sendline ("" ) 307expect_prompt ("echo REPLACED three" ) 308 309# Test escape cancelling count 310send ("echo one two three" ) 311send ("\033" ) 312sleep (0.200 ) 313send ("0w" ) 314send ("3" ) 315send ("\033" ) 316sleep (0.100 ) 317send ("dw" ) 318sendline ("" ) 319expect_prompt ("echo two three" ) 320 321# Now test that exactly the expected bind modes are defined 322sendline ("bind --list-modes" ) 323expect_prompt ( 324"F\r\nT\r\ndefault\r\nf\r\ninsert\r\noperator\r\nreplace\r\nreplace_one\r\nt\r\nvisual\r\n" , 325unmatched = "Unexpected vi bind modes" , 326) 327 328# Test word movements 329# Test 'w' with underscore - should not jump over single punctuation 330send ("echo abc_def" ) 331send ("\033" ) 332sleep (0.200 ) 333send ("0wwD\r" )# From start, 'w' twice should stop at underscore, delete from there 334expect_prompt ( 335"\r\n.*abc\r\n" ,unmatched = "vi mode 'w' should stop at single punctuation" 336) 337 338# Test 'w' with multiple spaces - should skip spaces and land at start of next word 339send ("echo abc def" ) 340send ("\033" ) 341sleep (0.200 ) 342send ("0wwwD\r" )# Skip 'echo', 'abc', 'def', then delete last char 343expect_prompt ("\r\n.*abc de\r\n" ,unmatched = "vi mode 'w' with multiple spaces" ) 344 345# Test 'w' with multiple punctuations - should stop at punctuation group 346send ("echo abc...def" ) 347send ("\033" ) 348sleep (0.200 ) 349send ("0wwD\r" )# Skip 'echo', then 'w' should stop at first '.', delete to end 350expect_prompt ("\r\n.*abc\r\n" ,unmatched = "vi mode 'w' with multiple punctuations" ) 351 352# Test 'diw' when cursor is on space - should delete only spaces 353send ("echo abc def" ) 354send ("\033" ) 355sleep (0.200 ) 356send ("0wwhdiw\r" )# Move to 'def', back to space, delete inner word (spaces only) 357expect_prompt ( 358"\r\n.*abcdef\r\n" ,unmatched = "vi mode 'diw' on space should delete spaces" 359) 360 361# Test 'daw' - should delete word and trim trailing space 362send ("echo abc def ghi" ) 363send ("\033" ) 364sleep (0.200 ) 365send ("0wwdaw\r" )# Skip 'echo', move to 'def', delete word with space 366expect_prompt ("\r\n.*abc ghi\r\n" ,unmatched = "vi mode 'daw' should trim trailing space" ) 367 368# Test 'b' backward movement with punctuation - should stop at punctuation 369send ("echo abc_def" ) 370send ("\033" ) 371sleep (0.200 ) 372send ("bD\r" )# From end, 'b' should stop at 'd', delete to end 373expect_prompt ("\r\n.*abc_\r\n" ,unmatched = "vi mode 'b' should stop at punctuation" ) 374 375# Test 'e' end-of-word movement 376send ("echo abc_def" ) 377send ("\033" ) 378sleep (0.200 ) 379send ("0weD\r" )# From start, 'w' to 'abc', 'e' to end of 'abc', delete to end 380expect_prompt ("\r\n.*ab\r\n" ,unmatched = "vi mode 'e' should move to word end" ) 381 382# Test 'W' WORD movement - should skip punctuation within WORD 383send ("echo abc-def ghi" ) 384send ("\033" ) 385sleep (0.200 ) 386send ("0wWD\r" )# From start, 'w' to 'abc', 'W' should skip 'abc-def', delete 'ghi' 387expect_prompt ( 388"\r\n.*abc-def\r\n" , 389unmatched = "vi mode 'W' should treat punctuation as part of WORD" , 390) 391 392# Test 'E' end-of-WORD movement 393send ("echo abc-def ghi" ) 394send ("\033" ) 395sleep (0.200 ) 396send ("0wED\r" )# From start, 'w' to 'abc', 'E' to end of 'abc-def', delete to end 397expect_prompt ("\r\n.*abc-de\r\n" ,unmatched = "vi mode 'E' should move to WORD end" ) 398 399# Test 'B' backward WORD movement 400send ("echo abc-def ghi" ) 401send ("\033" ) 402sleep (0.200 ) 403send ("BD\r" )# From end, 'B' backward to 'ghi', delete to end 404expect_prompt ("\r\n.*abc-def\r\n" ,unmatched = "vi mode 'B' backward WORD movement" ) 405 406# Test 'ge' backward to end of previous word 407send ("echo abc def" ) 408send ("\033" ) 409sleep (0.200 ) 410send ("0wwgex\r" )# Move to 'def', 'ge' to 'c' of 'abc', delete char with 'x' 411expect_prompt ( 412"\r\n.*ab def\r\n" ,unmatched = "vi mode 'ge' should move to previous word end" 413) 414 415# Test 'gE' backward to end of previous WORD 416send ("echo abc-def ghi" ) 417send ("\033" ) 418sleep (0.200 ) 419send ( 420"0WWgEx\r" 421)# Use 'W' to move by WORDs: to 'abc-def', then 'ghi', then 'gE' back to 'f' of 'abc-def', delete char 422expect_prompt ( 423"\r\n.*abc-de ghi\r\n" ,unmatched = "vi mode 'gE' should move to previous WORD end" 424) 425 426# Test 'diW' (delete inner WORD) with punctuation 427send ("echo abc-def ghi" ) 428send ("\033" ) 429sleep (0.200 ) 430send ("0wldiW\r" )# Move to 'bc-def', delete inner WORD 431expect_prompt ("\r\n.*ghi\r\n" ,unmatched = "vi mode 'diW' should delete entire WORD" ) 432 433# Test 'daW' (delete a WORD) with punctuation 434send ("echo abc-def ghi" ) 435send ("\033" ) 436sleep (0.200 ) 437send ("0wldaW\r" )# Move to 'bc-def', delete a WORD with space 438expect_prompt ("\r\n.*ghi\r\n" ,unmatched = "vi mode 'daW' should delete WORD and space" ) 439 440# Test Unicode character category separation 441# In vim, different unicode categories are separated into words 442send ("echo abcあいう" ) 443send ("\033" ) 444sleep (0.200 ) 445send ("0wwD\r" )# Skip 'echo', then from 'a' of 'abc', 'w' should stop at 'あ' 446expect_prompt ( 447"\r\n.*abc\r\n" ,unmatched = "vi mode 'w' should stop at Unicode category boundary" 448) 449 450# Test Unicode with multiple categories 451send ("echo abcあいう甲乙" ) 452send ("\033" ) 453sleep (0.200 ) 454send ("0wwwD\r" )# Skip 'echo', 'abc', hiragana, then at kanji, delete to end 455expect_prompt ( 456"\r\n.*abcあいう\r\n" ,unmatched = "vi mode 'w' should separate hiragana and kanji" 457) 458 459# Test 'cw' - change word, deletes to start of next word (like vim's 'dw') 460send ("echo abc def" ) 461send ("\033" ) 462sleep (0.200 ) 463send ("0wcwXXX\r" )# Move to 'abc', 'cw' deletes 'abc', type 'XXX' 464expect_prompt ( 465"\r\n.*XXX def\r\n" ,unmatched = "vi mode 'cw' should delete to start of next word" 466) 467 468# Test 'ce' - change to end of word (like vim's 'de') 469send ("echo abc def" ) 470send ("\033" ) 471sleep (0.200 ) 472send ("0wceXXX\r" )# Move to 'abc', 'ce' deletes 'abc' (not the space), type 'XXX' 473expect_prompt ( 474"\r\n.*XXX def\r\n" ,unmatched = "vi mode 'ce' should change to end of word" 475) 476 477# Test 'cW' - change WORD, changes to end of WORD keeping trailing space (like 'cE') 478send ("echo abc-def ghi" ) 479send ("\033" ) 480sleep (0.200 ) 481send ( 482"0wcWXXX\r" 483)# Move to 'abc-def', 'cW' changes 'abc-def' (not the space), type 'XXX' 484expect_prompt ( 485"\r\n.*XXX ghi\r\n" ,unmatched = "vi mode 'cW' should change to end of WORD" 486) 487 488# Test 'cE' - change to end of WORD (like vim's 'dE') 489send ("echo abc-def ghi" ) 490send ("\033" ) 491sleep (0.200 ) 492send ( 493"0wcEXXX\r" 494)# Move to 'abc-def', 'cE' deletes 'abc-def' (not the space), type 'XXX' 495expect_prompt ( 496"\r\n.*XXX ghi\r\n" ,unmatched = "vi mode 'cE' should change to end of WORD" 497) 498 499# Test running commands on empty line (should not crash) 500send ("\033" ) 501sleep (0.200 ) 502send ("dawdiwdwdedgedgE\r" )# run many commands 503expect_prompt () 504 505# Test accepting autosuggestions with w/W 506sendline ("echo test-suggestion test-suggestion" ) 507expect_prompt () 508send ("echo te" ) 509sleep (0.100 ) 510send ("\033" )# Enter normal mode 511sleep (0.200 ) 512send ("w" )# forward-word-vi should accept 'st' from autosuggestion 513expect_str ("echo test" ) 514send ("w" )# forward-word-vi should accept '-' 515expect_str ("echo test-" ) 516send ("w" )# forward-word-vi should accept 'suggestion ' from autosuggestion 517expect_str ("echo test-suggestion " ) 518send ("W\r" )# forward-word-vi should accept 'test-suggestion' from autosuggestion 519expect_prompt ("test-suggestion test-suggestion" ) 520 521# Switch back to regular (emacs mode) key bindings. 522sendline ("set -g fish_key_bindings fish_default_key_bindings" ) 523expect_prompt () 524 525# Verify the custom escape timeout set earlier is still in effect. 526sendline ("echo fish_escape_delay_ms=$fish_escape_delay_ms" ) 527expect_prompt ( 528"\r\n.*fish_escape_delay_ms=50\r\n" , 529unmatched = "default-mode custom timeout not set correctly" , 530) 531 532sendline ("set -g fish_escape_delay_ms 200" ) 533expect_prompt () 534 535# Verify the emacs transpose word (\et) behavior using various delays, 536# including none, after the escape character. 537 538# Start by testing with no delay. This should transpose the words. 539send ("echo abc def" ) 540send ("\033" ) 541send ("t\r" ) 542expect_prompt ( 543"\r\n.*def abc\r\n" ,unmatched = "emacs transpose words fail, 200ms timeout: no delay" 544) 545 546# Verify special characters, such as \cV, are not intercepted by the kernel 547# tty driver. Rather, they can be bound and handled by fish. 548sendline ("bind ctrl-v 'echo ctrl-v seen'" ) 549expect_prompt () 550send ("\026\r" ) 551expect_prompt ("ctrl-v seen" ,unmatched = "ctrl-v not seen" ) 552 553send ("bind ctrl-o 'echo ctrl-o seen'\r" ) 554expect_prompt () 555send ("\017\r" ) 556expect_prompt ("ctrl-o seen" ,unmatched = "ctrl-o not seen" ) 557 558# \x17 is ctrl-w. 559send ("echo git@github.com:fish-shell/fish-shell" ) 560send ("\x17\x17\r" ) 561expect_prompt ("git@github.com:" ,unmatched = "ctrl-w does not stop at :" ) 562 563send ("echo git@github.com:fish-shell/fish-shell" ) 564send ("\x17\x17\x17\r" ) 565expect_prompt ("git@" ,unmatched = "ctrl-w does not stop at @" ) 566 567sendline ("abbr --add foo 'echo foonanana'" ) 568expect_prompt () 569sendline ("bind ' ' expand-abbr or self-insert" ) 570expect_prompt () 571send ("foo " ) 572expect_str ("echo foonanana" ) 573send (" banana\r" ) 574expect_str (" banana\r" ) 575expect_prompt ("foonanana banana" ) 576 577# Ensure that nul can be bound properly (#3189). 578send ("bind ctrl-space 'echo nul seen'\r" ) 579expect_prompt () 580send ("\0" * 3 ) 581# We need to sleep briefly before emitting a newline, because when we execute the 582# key bindings above we place the tty in external-proc mode (see #7483) and restoring 583# the mode to shell-mode races with the newline emitted below (i.e. sometimes it may 584# be echoed). 585sleep (0.1 ) 586send ("\r" ) 587expect_prompt ("nul seen\r\n.*nul seen\r\n.*nul seen" ,unmatched = "nul not seen" ) 588 589# Test self-insert-notfirst. (#6603) 590# Here the leading 'q's should be stripped, but the trailing ones not. 591sendline ("bind q self-insert-notfirst" ) 592expect_prompt () 593sendline ("qqqecho qqq" ) 594expect_prompt ("qqq" ,unmatched = "Leading qs not stripped" ) 595 596# Test bigword with single-character words. 597sendline ("bind ctrl-g kill-bigword" ) 598expect_prompt () 599send ("a b c d\x01" )# ctrl-a, move back to the beginning of the line 600send ("\x07" )# ctrl-g, kill bigword 601sendline ("echo" ) 602expect_prompt ("\n.*b c d" ) 603 604# Test that overriding the escape binding works 605# and does not inhibit other escape sequences (up-arrow in this case). 606sendline ("bind escape 'echo foo'" ) 607expect_prompt () 608send ("\x1b" ) 609expect_str ("foo" ) 610send ("\x1b[A" ) 611expect_str ("bind escape 'echo foo'" ) 612sendline ("bind --erase escape" ) 613expect_prompt () 614 615send (" a b c d\x01" )# ctrl-a, move back to the beginning of the line 616send ("\x07" )# ctrl-g, kill bigword 617sendline ("echo" ) 618expect_prompt ("\n.*b c d" ) 619 620# Check that ctrl-z can be bound 621sendline ('bind ctrl-z "echo bound ctrl-z"' ) 622expect_prompt () 623send ("\x1a" ) 624expect_str ("bound ctrl-z" ) 625 626send ("echo foobar" ) 627send ("\x02\x02\x02" )# ctrl-b, backward-char 628sendline ("\x1bu" )# alt+u, upcase word 629expect_prompt ("fooBAR" ) 630 631sendline ("bind ctrl-z history-prefix-search-backward" ) 632expect_prompt () 633sendline ("echo this continues" ) 634expect_prompt () 635send ("\x1a" ) 636sendline (" with this text" ) 637expect_prompt ("this continues with this text" ) 638 639sendline ( 640""" 641bind ctrl-g " 642commandline --insert 'echo foo ar' 643commandline -f backward-word 644commandline --insert b 645commandline -f backward-char 646commandline -f backward-char 647commandline -f delete-char 648" 649""" .strip () 650) 651expect_prompt () 652send ("\x07" )# ctrl-g 653send ("\r" ) 654expect_prompt ("foobar" ) 655 656# This should do nothing instead of crash 657sendline ("commandline -f backward-jump" ) 658expect_prompt () 659sendline ("commandline -f self-insert" ) 660expect_prompt () 661sendline ("commandline -f and" ) 662expect_prompt () 663 664sendline ("bind ctrl-g 'sleep 1' history-pager" ) 665expect_prompt () 666send ("\x07" )# ctrl-g 667send ("\x1b[27u" )# escape, to close pager 668 669sendline ("bind ctrl-g kill-inner-word" ) 670expect_prompt () 671send ("echo foo-bar" ) 672send ("\x07" )# ctrl-g 673sendline ("baz" ) 674expect_str ("foo-barbaz" ) 675expect_prompt () 676 677sendline ("bind ctrl-g kill-a-word" ) 678expect_prompt () 679send ("echo foo-bar" ) 680send ("\x07" )# ctrl-g 681sendline ("qux" ) 682expect_str ("foo-barqux" ) 683expect_prompt () 684 685sendline ("bind ctrl-g backward-word-end" ) 686sendline ("eco 12" + control ("g" )+ "h" ) 687expect_str ("12" ) 688expect_prompt () 689 690# Check that the builtin version of `exit` works 691# (for obvious reasons this MUST BE LAST) 692sendline ("function myexit; echo exit; exit; end; bind ctrl-z myexit" ) 693expect_prompt () 694send ("\x1a" ) 695expect_str ("exit" ) 696 697for t in range (0 ,50 ): 698if not sp .spawn .isalive (): 699break 700# This is cheesy, but on CI with thread-sanitizer this can be slow enough that the process is still running, so we sleep for a bit. 701sleep (0.1 ) 702else : 703"Fish did not exit via binding!" ) 704sys .exit (1 )