2014-10-02 22:59:24 +00:00
|
|
|
# vim: set filetype=fish:
|
|
|
|
#
|
|
|
|
# Test the `function` builtin
|
|
|
|
|
2017-08-04 05:01:56 +00:00
|
|
|
logmsg Test the -V flag
|
2014-10-02 22:59:24 +00:00
|
|
|
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
|
2017-08-04 05:01:56 +00:00
|
|
|
set --show foo bar baz
|
2014-10-02 22:59:24 +00:00
|
|
|
end
|
2017-08-04 05:01:56 +00:00
|
|
|
|
|
|
|
logmsg Testing -V
|
2014-10-02 22:59:24 +00:00
|
|
|
frob
|
2017-08-04 05:01:56 +00:00
|
|
|
|
|
|
|
logmsg Testing -V with changed variables
|
2014-10-02 22:59:24 +00:00
|
|
|
set foo 'bad foo'
|
|
|
|
set bar 'bad bar'
|
|
|
|
set baz 'bad baz'
|
|
|
|
frob
|
2015-05-17 21:17:01 +00:00
|
|
|
|
2016-11-17 06:00:33 +00:00
|
|
|
# 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.
|
2016-11-29 02:04:37 +00:00
|
|
|
function name1 -a arg1 arg2 ; echo hello; end
|
2015-05-17 21:17:01 +00:00
|
|
|
function -a arg1 arg2 name2 ; end
|
2016-11-29 02:04:37 +00:00
|
|
|
function name3 --argument-names arg1 arg2 ; echo hello; echo goodbye; end
|
2015-05-17 21:17:01 +00:00
|
|
|
function --argument-names arg1 arg2 name4 ; end
|
2016-11-17 06:00:33 +00:00
|
|
|
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"
|
2016-11-29 02:04:37 +00:00
|
|
|
|
2017-08-04 05:01:56 +00:00
|
|
|
logmsg Verify that functions can be copied. Tests against regression of issue \#3601
|
2016-11-29 02:04:37 +00:00
|
|
|
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"
|
2017-08-04 05:01:56 +00:00
|
|
|
|
|
|
|
logmsg Checking that the copied functions are identical other than the name
|
2018-12-16 19:23:41 +00:00
|
|
|
# Poor man's diff because on some systems diff defaults to unified output, but that prints filenames.
|
|
|
|
#
|
|
|
|
set -l name1 (functions name1)
|
|
|
|
set -l name1a (functions name1a)
|
|
|
|
set -l name3 (functions name3)
|
|
|
|
set -l name3a (functions name3a)
|
|
|
|
echo $name1[1]
|
|
|
|
echo $name1a[1]
|
|
|
|
test "$name1[2..-1]" = "$name1a[2..-1]"; and echo "1 = 1a"
|
|
|
|
echo $name3[1]
|
|
|
|
echo $name3a[1]
|
|
|
|
test "$name3[2..-1]" = "$name3a[2..-1]"; and echo "3 = 3a"
|
2017-01-10 06:49:33 +00:00
|
|
|
|
2018-02-25 18:25:29 +00:00
|
|
|
logmsg Checking reserved names
|
|
|
|
function test; echo banana; end
|
2019-02-01 17:29:54 +00:00
|
|
|
|
|
|
|
logmsg Checking `functions -q` without arguments
|
|
|
|
functions -q; or echo "False"
|
2016-11-29 02:04:37 +00:00
|
|
|
exit 0
|