2024-04-12 18:19:32 +08:00
|
|
|
#RUN: %fish %s
|
2019-10-08 03:21:38 +08:00
|
|
|
function t --argument-names a b c
|
|
|
|
echo t
|
|
|
|
end
|
2020-02-08 03:40:25 +08: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
|
|
|
|
set --show foo bar baz
|
|
|
|
end
|
|
|
|
|
|
|
|
frob
|
|
|
|
#CHECK: $foo: set in local scope, unexported, with 1 elements
|
2020-04-26 00:33:47 +08:00
|
|
|
#CHECK: $foo[1]: |local foo|
|
2020-02-08 03:40:25 +08:00
|
|
|
#CHECK: $foo: set in global scope, unexported, with 1 elements
|
2020-04-26 00:33:47 +08:00
|
|
|
#CHECK: $foo[1]: |global foo|
|
2020-02-08 03:40:25 +08:00
|
|
|
#CHECK: $bar: set in local scope, unexported, with 5 elements
|
2020-04-26 00:33:47 +08:00
|
|
|
#CHECK: $bar[1]: |one|
|
|
|
|
#CHECK: $bar[2]: |two 2|
|
|
|
|
#CHECK: $bar[3]: |\t|
|
|
|
|
#CHECK: $bar[4]: ||
|
|
|
|
#CHECK: $bar[5]: |3|
|
2020-02-08 03:40:25 +08:00
|
|
|
#CHECK: $bar: set in global scope, unexported, with 5 elements
|
2020-04-26 00:33:47 +08:00
|
|
|
#CHECK: $bar[1]: |one|
|
|
|
|
#CHECK: $bar[2]: |two 2|
|
|
|
|
#CHECK: $bar[3]: |\t|
|
|
|
|
#CHECK: $bar[4]: ||
|
|
|
|
#CHECK: $bar[5]: |3|
|
2020-02-08 03:40:25 +08:00
|
|
|
#CHECK: $baz: set in local scope, unexported, with 0 elements
|
|
|
|
#CHECK: $baz: set in global scope, unexported, with 0 elements
|
|
|
|
|
|
|
|
set foo 'bad foo'
|
|
|
|
set bar 'bad bar'
|
|
|
|
set baz 'bad baz'
|
|
|
|
frob
|
|
|
|
#CHECK: $foo: set in local scope, unexported, with 1 elements
|
2020-04-26 00:33:47 +08:00
|
|
|
#CHECK: $foo[1]: |local foo|
|
2020-02-08 03:40:25 +08:00
|
|
|
#CHECK: $foo: set in global scope, unexported, with 1 elements
|
2020-04-26 00:33:47 +08:00
|
|
|
#CHECK: $foo[1]: |global foo|
|
2020-02-08 03:40:25 +08:00
|
|
|
#CHECK: $bar: set in local scope, unexported, with 5 elements
|
2020-04-26 00:33:47 +08:00
|
|
|
#CHECK: $bar[1]: |one|
|
|
|
|
#CHECK: $bar[2]: |two 2|
|
|
|
|
#CHECK: $bar[3]: |\t|
|
|
|
|
#CHECK: $bar[4]: ||
|
|
|
|
#CHECK: $bar[5]: |3|
|
2020-02-08 03:40:25 +08:00
|
|
|
#CHECK: $bar: set in global scope, unexported, with 1 elements
|
2020-04-26 00:33:47 +08:00
|
|
|
#CHECK: $bar[1]: |bad bar|
|
2020-02-08 03:40:25 +08:00
|
|
|
#CHECK: $baz: set in local scope, unexported, with 0 elements
|
|
|
|
#CHECK: $baz: set in global scope, unexported, with 1 elements
|
2020-04-26 00:33:47 +08:00
|
|
|
#CHECK: $baz[1]: |bad baz|
|
2020-02-08 03:40:25 +08: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.
|
|
|
|
function name1 -a arg1 arg2
|
|
|
|
echo hello
|
|
|
|
end
|
2020-03-10 02:44:41 +08:00
|
|
|
function -a arg1 arg2 name2
|
|
|
|
end
|
2021-11-04 13:52:17 +08:00
|
|
|
#CHECKERR: {{.*}}checks/function.fish (line {{\d+}}): function: -a: invalid function name
|
2020-03-10 02:44:41 +08:00
|
|
|
#CHECKERR: function -a arg1 arg2 name2
|
2020-02-08 03:40:25 +08:00
|
|
|
#CHECKERR: ^
|
2020-03-10 02:44:41 +08:00
|
|
|
function name3 --argument-names arg1 arg2
|
|
|
|
echo hello
|
|
|
|
echo goodbye
|
|
|
|
end
|
|
|
|
function --argument-names arg1 arg2 name4
|
|
|
|
end
|
2021-11-04 13:52:17 +08:00
|
|
|
#CHECKERR: {{.*}}checks/function.fish (line {{\d+}}): function: --argument-names: invalid function name
|
2020-03-10 02:44:41 +08:00
|
|
|
#CHECKERR: function --argument-names arg1 arg2 name4
|
2020-02-08 03:40:25 +08:00
|
|
|
#CHECKERR: ^
|
2020-03-10 02:44:41 +08:00
|
|
|
function name5 abc --argument-names def
|
|
|
|
end
|
2021-11-04 13:52:17 +08:00
|
|
|
#CHECKERR: {{.*}}checks/function.fish (line {{\d+}}): function: abc: unexpected positional argument
|
2020-03-10 02:44:41 +08:00
|
|
|
#CHECKERR: function name5 abc --argument-names def
|
2020-02-08 03:40:25 +08:00
|
|
|
#CHECKERR: ^
|
|
|
|
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"
|
|
|
|
#CHECK: Function name1 found
|
|
|
|
#CHECK: Function name2 not found as expected
|
|
|
|
#CHECK: Function name3 found
|
|
|
|
#CHECK: Function name4 not found as expected
|
|
|
|
|
|
|
|
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"
|
|
|
|
|
|
|
|
# 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)
|
2023-02-13 23:59:28 +08:00
|
|
|
# First two lines for the copied and non-copied functions are different. Skip it for now.
|
2020-12-12 06:05:22 +08:00
|
|
|
test "$name1[3..-1]" = "$name1a[3..-1]"; and echo "1 = 1a"
|
2020-02-08 03:40:25 +08:00
|
|
|
#CHECK: 1 = 1a
|
2020-12-12 06:05:22 +08:00
|
|
|
test "$name3[3..-1]" = "$name3a[3..-1]"; and echo "3 = 3a"
|
2020-02-08 03:40:25 +08:00
|
|
|
#CHECK: 3 = 3a
|
|
|
|
|
2023-02-13 23:59:28 +08:00
|
|
|
# Test the first two lines.
|
|
|
|
string join \n -- $name1[1..2]
|
|
|
|
#CHECK: # Defined in {{(?:(?!, copied).)*}}
|
2024-05-06 22:50:21 +08:00
|
|
|
#CHECK: function name1 --argument-names arg1 --argument-names arg2
|
2023-02-13 23:59:28 +08:00
|
|
|
string join \n -- $name1a[1..2]
|
|
|
|
#CHECK: # Defined in {{.*}}, copied in {{.*}}
|
2024-05-06 22:50:21 +08:00
|
|
|
#CHECK: function name1a --argument-names arg1 --argument-names arg2
|
2023-02-13 23:59:28 +08:00
|
|
|
string join \n -- $name3[1..2]
|
|
|
|
#CHECK: # Defined in {{(?:(?!, copied).)*}}
|
2024-05-06 22:50:21 +08:00
|
|
|
#CHECK: function name3 --argument-names arg1 --argument-names arg2
|
2023-02-13 23:59:28 +08:00
|
|
|
string join \n -- $name3a[1..2]
|
|
|
|
#CHECK: # Defined in {{.*}}, copied in {{.*}}
|
2024-05-06 22:50:21 +08:00
|
|
|
#CHECK: function name3a --argument-names arg1 --argument-names arg2
|
2023-02-13 23:59:28 +08:00
|
|
|
|
2020-03-10 02:44:41 +08:00
|
|
|
function test
|
|
|
|
echo banana
|
|
|
|
end
|
2021-11-04 13:52:17 +08:00
|
|
|
#CHECKERR: {{.*}}checks/function.fish (line {{\d+}}): function: test: cannot use reserved keyword as function name
|
2020-03-10 02:44:41 +08:00
|
|
|
#CHECKERR: function test
|
2020-02-08 03:40:25 +08:00
|
|
|
#CHECKERR: ^
|
|
|
|
|
2020-03-10 02:44:41 +08:00
|
|
|
functions -q; or echo False
|
2020-02-08 03:40:25 +08:00
|
|
|
#CHECK: False
|
2022-10-29 16:24:03 +08:00
|
|
|
|
|
|
|
# See that we don't count a file with an empty function name,
|
|
|
|
# or directories
|
|
|
|
set -l tmpdir (mktemp -d)
|
|
|
|
touch $tmpdir/.fish
|
|
|
|
mkdir $tmpdir/directory.fish
|
|
|
|
touch $tmpdir/actual_function.fish
|
|
|
|
|
|
|
|
begin
|
|
|
|
set -l fish_function_path $tmpdir
|
|
|
|
functions
|
|
|
|
end
|
|
|
|
# CHECK: actual_function
|
|
|
|
|
|
|
|
# these are functions defined either in this file,
|
|
|
|
# or eagerly in share/config.fish.
|
|
|
|
# I don't know of a way to ignore just them.
|
|
|
|
#
|
|
|
|
# CHECK: bg
|
|
|
|
# CHECK: disown
|
|
|
|
# CHECK: fg
|
|
|
|
# CHECK: fish_command_not_found
|
|
|
|
# CHECK: fish_sigtrap_handler
|
|
|
|
# CHECK: frob
|
|
|
|
# CHECK: kill
|
|
|
|
# CHECK: name1
|
|
|
|
# CHECK: name1a
|
|
|
|
# CHECK: name3
|
|
|
|
# CHECK: name3a
|
|
|
|
# CHECK: t
|
|
|
|
# CHECK: wait
|
|
|
|
|
|
|
|
rm -r $tmpdir
|
|
|
|
|
2024-11-12 00:50:20 +08:00
|
|
|
functions -e foo
|
|
|
|
|
2023-12-02 01:14:54 +08:00
|
|
|
function foo -p bar; end
|
|
|
|
# CHECKERR: {{.*}}function.fish (line {{\d+}}): function: bar: invalid process id
|
|
|
|
# CHECKERR: function foo -p bar; end
|
|
|
|
# CHECKERR: ^~~~~~~~~~~~~~~~~~~^
|
|
|
|
|
2024-05-06 22:54:20 +08:00
|
|
|
function foo --argument-names "banana pajama"; end
|
|
|
|
# CHECKERR: {{.*}}function.fish (line {{\d+}}): function: banana pajama: invalid variable name. See `help identifiers`
|
|
|
|
# CHECKERR: function foo --argument-names "banana pajama"; end
|
|
|
|
# CHECKERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
|
|
|
|
|
|
|
|
|
2024-11-12 00:50:20 +08:00
|
|
|
function foo --argument-names status; end
|
|
|
|
# CHECKERR: {{.*}}function.fish (line {{\d+}}): function: variable 'status' is read-only
|
|
|
|
# CHECKERR: function foo --argument-names status; end
|
|
|
|
# CHECKERR: ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^
|
|
|
|
|
|
|
|
echo status $status
|
|
|
|
# CHECK: status 2
|
|
|
|
|
|
|
|
functions -q foo
|
|
|
|
echo exists $status
|
|
|
|
# CHECK: exists 1
|
|
|
|
|
2020-02-08 03:40:25 +08:00
|
|
|
exit 0
|