File: function.in

package info (click to toggle)
fish 3.0.2-2%2Bdeb10u1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 36,448 kB
  • sloc: ansic: 75,559; cpp: 43,314; sh: 9,096; javascript: 7,710; python: 2,538; makefile: 1,461; objc: 709; perl: 367; xml: 18
file content (54 lines) | stat: -rw-r--r-- 1,713 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# vim: set filetype=fish:
#
# Test the `function` builtin

logmsg Test the -V flag
set -g foo 'global foo'
set -l foo 'local foo'
set bar one 'two    2' \t '' 3
set baz
function frob -V foo -V bar -V baz
    set --show foo bar baz
end

logmsg Testing -V
frob

logmsg Testing -V with changed variables
set foo 'bad foo'
set bar 'bad bar'
set baz 'bad baz'
frob

# This sequence of tests originally verified that functions `name2` and
# `name4` were created. See issue #2068. That behavior is not what we want.
# The function name must always be the first argument of the `function`
# command. See issue #2827.
function name1 -a arg1 arg2 ; echo hello; end
function -a arg1 arg2 name2 ; end
function name3 --argument-names arg1 arg2 ; echo hello; echo goodbye; end
function --argument-names arg1 arg2 name4 ; end
function name5 abc --argument-names def ; end
functions -q name1; and echo "Function name1 found"
functions -q name2; or echo "Function name2 not found as expected"
functions -q name3; and echo "Function name3 found"
functions -q name4; or echo "Function name4 not found as expected"

logmsg Verify that functions can be copied. Tests against regression of issue \#3601
functions -c name1 name1a
functions --copy name3 name3a
functions -q name1a
or echo "Function name1a not found as expected"
functions -q name3a
or echo "Function name3a not found as expected"

logmsg Checking that the copied functions are identical other than the name
diff (functions name1 | psub) (functions name1a | psub)
diff (functions name3 | psub) (functions name3a | psub)

logmsg Checking reserved names
function test; echo banana; end

logmsg Checking `functions -q` without arguments
functions -q; or echo "False"
exit 0