fork/fish-shell

git clone https://git.julia.blue/fork/fish-shell

Fabian Boehmtests/abbrs: Disable check that fails on CI2dedff220

master
5.3 KiB194 linesraw
1#!/usr/bin/env python3
2from pexpect_helper import SpawnedProc
3
4sp = SpawnedProc()
5send, sendline, sleep, expect_prompt, expect_re, expect_str = (
6    sp.send,
7    sp.sendline,
8    sp.sleep,
9    sp.expect_prompt,
10    sp.expect_re,
11    sp.expect_str,
12)
13expect_prompt()
14
15# ? prints the command line, bracketed by <>, then clears it.
16sendline(r"""bind '?' 'echo "<$(commandline)>"; commandline ""'; """)
17expect_prompt()
18
19# Basic test.
20# Default abbreviations expand only in command position.
21sendline(r"abbr alpha beta")
22expect_prompt()
23
24send(r"alpha ?")
25expect_str(r"<beta >")
26
27send(r"echo alpha ?")
28expect_str(r"<echo alpha >")
29
30send(r"alpha;?")
31expect_str(r"<beta;>")
32
33# Abbreviation expansions may have multiple words.
34sendline(r"abbr --add emacsnw emacs -nw -l")
35expect_prompt()
36send(r"emacsnw ?")
37expect_str(r"<emacs -nw -l >")
38
39# Regression test that abbreviations still expand in incomplete positions.
40sendline(r"""abbr --erase (abbr --list)""")
41expect_prompt()
42sendline(r"""abbr --add foo echo bar""")
43expect_prompt()
44sendline(r"if foo")
45expect_str(r"if echo bar")
46sendline(r"end")
47expect_prompt(r"bar")
48
49# Regression test that 'echo (' doesn't hang.
50sendline(r"echo )")
51expect_str(r"Unexpected ')' for unopened parenthesis")
52send(r"?")
53expect_str(r"<echo )>")
54
55# Support position anywhere.
56sendline(r"abbr alpha --position anywhere beta2")
57expect_prompt()
58
59send(r"alpha ?")
60expect_str(r"<beta2 >")
61
62send(r"echo alpha ?")
63expect_str(r"<echo beta2 >")
64
65# Support regex.
66sendline(r"abbr alpha --regex 'A[0-9]+Z' beta3")
67expect_prompt()
68send(r"A123Z ?")
69expect_str(r"<beta3 >")
70send(r"AZ ?")
71expect_str(r"<AZ >")
72send(r"QA123Z ?")  # fails as the regex must match the entire string
73expect_str(r"<QA123Z >")
74send(r"A0000000000000000000009Z ?")
75expect_str(r"<beta3 >")
76
77# Support functions. Here anything in between @@ is uppercased, except 'nope'.
78sendline(
79    r"""function uppercaser
80            string match --quiet '*nope*' $argv[1] && return 1
81            string trim --chars @ $argv | string upper
82        end
83    """.strip()
84)
85expect_prompt()
86sendline(r"abbr uppercaser --regex '@.+@' --function uppercaser")
87expect_prompt()
88send(r"@abc@ ?")
89expect_str(r"<ABC >")
90send(r"@nope@ ?")
91expect_str(r"<@nope@ >")
92sendline(r"abbr --erase uppercaser")
93expect_prompt()
94
95# -f works as shorthand for --function.
96sendline(r"abbr uppercaser2 --regex '@.+@' -f uppercaser")
97expect_prompt()
98send(r"@abc@ ?")
99expect_str(r"<ABC >")
100send(r"@nope@ ?")
101expect_str(r"<@nope@ >")
102sendline(r"abbr --erase uppercaser2")
103expect_prompt()
104
105# Abbreviations which cause the command line to become incomplete or invalid
106# are visibly expanded.
107sendline(r"abbr openparen --position anywhere '('")
108expect_prompt()
109sendline(r"abbr closeparen --position anywhere ')'")
110expect_prompt()
111sendline(r"echo openparen")
112expect_str(r"echo (")
113send(r"?")
114expect_str(r"<echo (>")
115sendline(r"echo closeparen")
116expect_str(r"echo )")
117send(r"?")
118expect_str(r"<echo )>")
119sendline(r"echo openparen seq 5 closeparen")  # expands on enter
120expect_prompt(r"1 2 3 4 5")
121sendline(r"echo openparen seq 5 closeparen ")  # expands on space
122expect_prompt(r"1 2 3 4 5")
123
124
125# Verify that 'commandline' is accurate.
126# Abbreviation functions cannot usefully change the command line, but they can read it.
127sendline(
128    r"""function check_cmdline
129            set -g last_cmdline (commandline)
130            set -g last_cursor (commandline --cursor)
131            false
132        end
133    """.strip()
134)
135expect_prompt()
136sendline(r"abbr check_cmdline --regex '@.+@' --function check_cmdline")
137expect_prompt()
138send(r"@abc@ ?")
139expect_str(r"<@abc@ >")
140sendline(r"echo $last_cursor : $last_cmdline")
141expect_prompt(r"6 : @abc@ ")
142
143
144# Test cursor positioning.
145sendline(r"""abbr --erase (abbr --list) """)
146expect_prompt()
147sendline(r"""abbr LLL --position anywhere --set-cursor 'abc%ghi'""")
148expect_prompt()
149send(r"""echo LLL def?""")
150expect_str(r"<echo abcdefghi >")
151
152sendline(r"""abbr --erase (abbr --list) """)
153expect_prompt()
154sendline(r"""abbr LLL --position anywhere --set-cursor=!HERE! '!HERE! | less'""")
155expect_prompt()
156send(r"""echo LLL derp?""")
157expect_str(r"<echo derp | less >")
158
159sendline(r"""abbr foo --command echo bar""")
160expect_prompt()
161sendline(r"""printf '%s\n' foo """)
162expect_prompt("foo")
163sendline(r"""echo foo """)
164expect_prompt("bar")
165sendline(r"""true; and echo foo """)
166expect_prompt("bar")
167sendline(r"""true; and builtin echo foo """)
168expect_prompt("bar")
169sendline(r"""abbr fruit --command={git,hg,svn} banana""")
170expect_prompt()
171sendline(
172    r"""function git; echo git $argv; end; function hg; echo hg $argv; end; function svn; echo svn $argv; end"""
173)
174expect_prompt()
175sendline(r"""git fruit""")
176expect_prompt("git banana")
177sendline(r"""abbr""")
178expect_prompt(
179    "abbr -a --position anywhere --command git --command hg --command svn -- fruit banana"
180)
181sendline(r"""function banana; echo I am a banana; end""")
182expect_prompt()
183sendline(r"""abbr fruit --command={git,hg,svn,} banana""")
184expect_prompt()
185sendline(r"""fruit foo""")
186expect_prompt("I am a banana")
187
188# FIXME: This fails regularly on CI, output like
189# \r\n\x1b]133;C;cmdline_url=echo%20bar\x07bar\r\n\x1b]133;D;0\x07\x1b[?25h⏎
190# {{spaces}}\r⏎ \r\rprompt 39>\x1b[?2004h
191# (don't add the literal string "bar" here or the expect_prompt will match it - so we add some no-op quotes)
192# sendline(r"""function replace; commandline -r ""; echo echo b''ar; end; abbr foo --function replace""")
193# sendline("foo")
194# expect_prompt("bar")