fork/fish-shell

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

Johannes Altmanningerconfig.fish: don't load default theme in noninteractive shellse2b18fc5b

master
9.1 KiB320 linesraw
1#RUN: %fish %s
2# Test the `functions` builtin
3
4function f1
5end
6
7# ==========
8# Verify that `functions --details` works as expected when given too many args.
9functions --details f1 f2
10#CHECKERR: functions: --details: expected 1 arguments; got 2
11
12# Verify that it still mentions "--details" even if it isn't the last option.
13functions --details --verbose f1 f2
14#CHECKERR: functions: --details: expected 1 arguments; got 2
15
16# ==========
17# Verify that `functions --details` works as expected when given the name of a
18# known function.
19functions --details f1
20#CHECK: {{.*}}checks/functions.fish
21
22# ==========
23# Verify that `functions --details` works as expected when given the name of an
24# unknown function.
25functions -D f2
26#CHECK: n/a
27
28# ==========
29# Verify that `functions --details` works as expected when given the name of a
30# function that could be autoloaded but isn't currently loaded.
31set x (functions -D vared)
32if test (count $x) -ne 1
33    or not string match -rq '.*functions/vared\.fish' "$x"
34    echo "Unexpected output for 'functions -D vared': $x" >&2
35end
36
37# ==========
38# Verify that `functions --verbose --details` works as expected when given the name of a
39# function that was autoloaded.
40set x (functions -v -D vared)
41if test (count $x) -ne 5
42    or not string match -rq '.*functions/vared\.fish' $x[1]
43    or test $x[2] != autoloaded
44    or test $x[3] != 7
45    or test $x[4] != scope-shadowing
46    or test $x[5] != 'Edit variable value'
47    echo "Unexpected output for 'functions -v -D vared': $x" >&2
48end
49
50# ==========
51# Verify that `functions --verbose --details` properly escapes a function
52# with a multiline description.
53function multiline_descr -d 'line 1\n
54line 2 & more; way more'
55end
56set x (functions -v -D multiline_descr)
57if test $x[5] != 'line 1\\\\n\\nline 2 & more; way more'
58    echo "Unexpected output for 'functions -v -D multiline_descr': $x" >&2
59end
60
61# ==========
62# Verify that `functions --details` works as expected when given the name of a
63# function that is copied. (Prints the filename where it was copied.)
64functions -c f1 f1a
65functions -D f1a
66#CHECK: {{.*}}checks/functions.fish
67functions -Dv f1a
68#CHECK: {{.*}}checks/functions.fish
69#CHECK: {{.*}}checks/functions.fish
70#CHECK: {{\d+}}
71#CHECK: scope-shadowing
72#CHECK:
73echo "functions -c f1 f1b" | source
74functions -D f1b
75#CHECK: -
76functions -Dv f1b
77#CHECK: -
78#CHECK: {{.*}}checks/functions.fish
79#CHECK: {{\d+}}
80#CHECK: scope-shadowing
81#CHECK:
82
83# ==========
84# Verify function description setting
85function test_func_desc
86end
87functions test_func_desc | string match --quiet '*description*'
88and echo "Unexpected description" >&2
89
90functions --description description1 test_func_desc
91functions test_func_desc | string match --quiet '*description1*'
92or echo "Failed to find description 1" >&2
93
94functions -d description2 test_func_desc
95functions test_func_desc | string match --quiet '*description2*'
96or echo "Failed to find description 2" >&2
97
98# ==========
99# Verify that the functions are printed in order.
100functions f1 test_func_desc
101# CHECK: # Defined in {{.*}}
102# CHECK: function f1
103# CHECK: end
104# CHECK: # Defined in {{.*}}
105# CHECK: function test_func_desc --description description2
106# CHECK: end
107
108# Note: This test isn't ideal - if ls was loaded before,
109# or doesn't exist, it'll succeed anyway.
110#
111# But we can't *confirm* that an ls function exists,
112# so this is the best we can do.
113functions --erase ls
114type -t ls
115#CHECK: file
116
117# ==========
118# Verify that `functions --query` does not return 0 if there are 256 missing functions
119functions --query a(seq 1 256)
120echo $status
121#CHECK: 255
122
123echo "function t; echo tttt; end" | source
124functions t
125# CHECK: # Defined via `source`
126# CHECK: function t
127# CHECK: echo tttt;
128# CHECK: end
129
130functions --no-details t
131# CHECK: function t
132# CHECK: echo tttt;
133# CHECK: end
134
135functions -c t t2
136functions t2
137# CHECK: # Defined via `source`, copied in {{.*}}checks/functions.fish @ line {{\d+}}
138# CHECK: function t2
139# CHECK: echo tttt;
140# CHECK: end
141functions -D t2
142#CHECK: {{.*}}checks/functions.fish
143functions -Dv t2
144#CHECK: {{.*}}checks/functions.fish
145#CHECK: -
146#CHECK: {{\d+}}
147#CHECK: scope-shadowing
148#CHECK:
149
150functions -c first
151# CHECKERR: functions: Expected exactly two names (current function name, and new function name)
152# CHECKERR: {{.*}}/checks/functions.fish (line {{\d+}}):
153# CHECKERR: functions -c first
154# CHECKERR: ^
155# CHECKERR: (Type 'help functions' for related documentation)
156
157functions -c first second third
158# CHECKERR: functions: Expected exactly two names (current function name, and new function name)
159# CHECKERR: {{.*}}/checks/functions.fish (line {{\d+}}):
160# CHECKERR: functions -c first second third
161# CHECKERR: ^
162# CHECKERR: (Type 'help functions' for related documentation)
163
164functions -c unknown_function copy
165# CHECKERR: functions: Function 'unknown_function' does not exist
166# CHECKERR: {{.*}}/checks/functions.fish (line {{\d+}}):
167# CHECKERR: functions -c unknown_function copy
168# CHECKERR: ^
169# CHECKERR: (Type 'help functions' for related documentation)
170
171function to_copy
172end
173functions -c -- to_copy -invalid_name
174# CHECKERR: functions: Illegal function name '-invalid_name'
175# CHECKERR: {{.*}}/checks/functions.fish (line {{\d+}}):
176# CHECKERR: functions -c -- to_copy -invalid_name
177# CHECKERR: ^
178# CHECKERR: (Type 'help functions' for related documentation)
179
180functions -c -- to_copy function
181# CHECKERR: functions: Illegal function name 'function'
182# CHECKERR: {{.*}}/checks/functions.fish (line {{\d+}}):
183# CHECKERR: functions -c -- to_copy function
184# CHECKERR: ^
185# CHECKERR: (Type 'help functions' for related documentation)
186
187functions -c -- to_copy to_copy
188# CHECKERR: functions: Function 'to_copy' already exists. Cannot create copy of 'to_copy'
189# CHECKERR: {{.*}}/checks/functions.fish (line {{\d+}}):
190# CHECKERR: functions -c -- to_copy to_copy
191# CHECKERR: ^
192# CHECKERR: (Type 'help functions' for related documentation)
193
194echo "functions -c t t3" | source
195functions t3
196# CHECK: # Defined via `source`, copied via `source`
197# CHECK: function t3
198# CHECK: echo tttt;
199# CHECK: end
200functions -D t3
201#CHECK: -
202functions -Dv t3
203#CHECK: -
204#CHECK: -
205#CHECK: {{\d+}}
206#CHECK: scope-shadowing
207#CHECK:
208
209functions --no-details t2
210# CHECK: function t2
211# CHECK: echo tttt;
212# CHECK: end
213
214functions --no-details --details t
215# CHECKERR: functions: invalid option combination
216# CHECKERR:
217# CHECKERR: {{.*}}checks/functions.fish (line {{\d+}}):
218# CHECKERR: functions --no-details --details t
219# CHECKERR: ^
220# CHECKERR: (Type 'help functions' for related documentation)
221# XXX FIXME ^ caret should point at --no-details --details
222
223function term1 --on-signal TERM
224end
225function term2 --on-signal TERM
226end
227function term3 --on-signal TERM
228end
229
230functions --handlers-type signal
231# CHECK: Event signal
232# CHECK: SIGTRAP fish_sigtrap_handler
233# CHECK: SIGTERM term1
234# CHECK: SIGTERM term2
235# CHECK: SIGTERM term3
236
237functions -t invalid_type
238# CHECKERR: functions: Expected generic | variable | signal | exit | job-id for --handlers-type
239
240# See how --names and --all work.
241# We don't want to list all of our functions here,
242# so we just match a few that we know are there.
243functions -n | string match cd
244# CHECK: cd
245
246functions --names | string match __fish_config_interactive
247echo $status
248# CHECK: 1
249
250functions --names -a | string match __fish_config_interactive
251# CHECK: __fish_config_interactive
252
253functions --description ""
254# CHECKERR: functions: Expected exactly one function name
255# CHECKERR: {{.*}}checks/functions.fish (line {{\d+}}):
256# CHECKERR: functions --description ""
257# CHECKERR: ^
258# CHECKERR: (Type 'help functions' for related documentation)
259
260function foo --on-variable foo
261end
262# This should print *everything*
263functions --handlers-type "" | string match 'Event *'
264# CHECK: Event signal
265# CHECK: Event variable
266# CHECK: Event generic
267functions -e foo
268
269functions --details --verbose thisfunctiondoesnotexist
270# CHECK: n/a
271# CHECK: n/a
272# CHECK: 0
273# CHECK: n/a
274# CHECK: n/a
275
276functions --banana
277# CHECKERR: functions: --banana: unknown option
278echo $status
279# CHECK: 2
280
281functions --all=arg
282# CHECKERR: functions: --all=arg: option does not take an argument
283echo $status
284# CHECK: 2
285
286# Test --color option
287function test_color_option
288    echo hello
289end
290
291functions --color=invalid
292# CHECKERR: functions: Invalid value for '--color' option: 'invalid'. Expected 'always', 'never', or 'auto'
293
294functions --color
295# CHECKERR: functions: --color: option requires an argument
296
297functions --no-details --color=never test_color_option
298# CHECK: function test_color_option
299# CHECK:     echo hello
300# CHECK: end
301
302fish_config theme choose default
303string escape (functions --no-details --color=always test_color_option)
304# CHECK: function\ \e\[36mtest_color_option\e\[32m
305# CHECK: \e\[39m\ \ \ \ echo\ \e\[36mhello\e\[32m
306# CHECK: \e\[39mend\e\[32m\e\[39m
307
308functions --names --query
309# CHECKERR: functions: invalid option combination
310# CHECKERR: {{.*}}/checks/functions.fish (line {{\d+}}):
311# CHECKERR: functions --names --query
312# CHECKERR: ^
313# CHECKERR: (Type 'help functions' for related documentation)
314
315functions -d desc unknown_function
316# CHECKERR: functions: Function 'unknown_function' does not exist
317# CHECKERR: {{.*}}/checks/functions.fish (line {{\d+}}):
318# CHECKERR: functions -d desc unknown_function
319# CHECKERR: ^
320# CHECKERR: (Type 'help functions' for related documentation)