mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-25 12:23:09 +00:00
286c60bc9d
Before this fix, `function -a arg1 name1` would produce a function named 'arg1'. After this fix, it will produce a function named 'name'. See #2068 for more.
46 lines
1 KiB
Fish
46 lines
1 KiB
Fish
# vim: set filetype=fish:
|
|
#
|
|
# Test the `function` builtin
|
|
|
|
# utility function
|
|
function show_ary -a name --no-scope-shadowing
|
|
set -l count (count $$name)
|
|
echo "\$$name: ($count)"
|
|
if test $count -gt 0
|
|
for i in (seq $count)
|
|
echo "$i: '$$name[1][$i]'"
|
|
end
|
|
end
|
|
end
|
|
|
|
# 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
|
|
show_ary foo
|
|
show_ary bar
|
|
show_ary baz
|
|
end
|
|
echo "Testing -V"
|
|
frob
|
|
echo "Testing -V with changed variables"
|
|
set foo 'bad foo'
|
|
set bar 'bad bar'
|
|
set baz 'bad baz'
|
|
frob
|
|
|
|
# Test that -a does not mix up the function name with arguments
|
|
# See #2068
|
|
function name1 -a arg1 arg2 ; end
|
|
function -a arg1 arg2 name2 ; end
|
|
function name3 --argument-names arg1 arg2 ; end
|
|
function --argument-names arg1 arg2 name4 ; end
|
|
for i in (seq 4)
|
|
if functions -q name$i
|
|
echo "Function name$i found"
|
|
else
|
|
echo "Function name$i not found, but should have been"
|
|
end
|
|
end
|