2020-02-08 05:10:55 +08:00
|
|
|
#RUN: %fish %s
|
2017-01-10 14:49:33 +08:00
|
|
|
# Test the `functions` builtin
|
|
|
|
|
|
|
|
function f1
|
|
|
|
end
|
|
|
|
|
|
|
|
# ==========
|
2017-05-01 10:53:13 +08:00
|
|
|
# Verify that `functions --details` works as expected when given too many args.
|
|
|
|
set x (functions --details f1 f2 2>&1)
|
2019-09-18 13:00:08 +08:00
|
|
|
if test "$x" != "functions --details: Expected 1 args, got 2"
|
2017-05-01 10:53:13 +08:00
|
|
|
echo "Unexpected output for 'functions --details f1 f2': $x" >&2
|
2017-01-10 14:49:33 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# ==========
|
2017-05-01 10:53:13 +08:00
|
|
|
# Verify that `functions --details` works as expected when given the name of a
|
2017-01-10 14:49:33 +08:00
|
|
|
# known function.
|
2020-02-08 05:10:55 +08:00
|
|
|
functions --details f1
|
|
|
|
#CHECK: {{.*}}checks/functions.fish
|
2017-01-10 14:49:33 +08:00
|
|
|
|
|
|
|
# ==========
|
2017-05-01 10:53:13 +08:00
|
|
|
# Verify that `functions --details` works as expected when given the name of an
|
2017-01-10 14:49:33 +08:00
|
|
|
# unknown function.
|
2017-05-01 10:53:13 +08:00
|
|
|
set x (functions -D f2)
|
2020-03-10 02:36:12 +08:00
|
|
|
if test "$x" != n/a
|
2017-05-01 10:53:13 +08:00
|
|
|
echo "Unexpected output for 'functions --details f2': $x" >&2
|
2017-01-10 14:49:33 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# ==========
|
2017-05-01 10:53:13 +08:00
|
|
|
# Verify that `functions --details` works as expected when given the name of a
|
2017-01-10 14:49:33 +08:00
|
|
|
# function that could be autoloaded but isn't currently loaded.
|
2017-05-01 10:53:13 +08:00
|
|
|
set x (functions -D abbr)
|
2017-01-10 14:49:33 +08:00
|
|
|
if test (count $x) -ne 1
|
2020-03-10 02:36:12 +08:00
|
|
|
or not string match -q '*/share/functions/abbr.fish' "$x"
|
2017-05-01 10:53:13 +08:00
|
|
|
echo "Unexpected output for 'functions -D abbr': $x" >&2
|
2017-01-10 14:49:33 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
# ==========
|
2017-05-01 10:53:13 +08:00
|
|
|
# Verify that `functions --verbose --details` works as expected when given the name of a
|
2017-01-10 14:49:33 +08:00
|
|
|
# function that was autoloaded.
|
2017-05-01 10:53:13 +08:00
|
|
|
set x (functions -v -D abbr)
|
2017-03-14 08:22:33 +08:00
|
|
|
if test (count $x) -ne 5
|
2020-03-10 02:36:12 +08:00
|
|
|
or not string match -q '*/share/functions/abbr.fish' $x[1]
|
|
|
|
or test $x[2] != autoloaded
|
|
|
|
or test $x[3] != 1
|
|
|
|
or test $x[4] != scope-shadowing
|
|
|
|
or test $x[5] != 'Manage abbreviations'
|
2017-05-01 10:53:13 +08:00
|
|
|
echo "Unexpected output for 'functions -v -D abbr': $x" >&2
|
2017-01-10 14:49:33 +08:00
|
|
|
end
|
2017-03-14 08:22:33 +08:00
|
|
|
|
|
|
|
# ==========
|
2017-05-01 10:53:13 +08:00
|
|
|
# Verify that `functions --verbose --details` properly escapes a function
|
2017-03-14 08:22:33 +08:00
|
|
|
# with a multiline description.
|
|
|
|
function multiline_descr -d 'line 1\n
|
|
|
|
line 2 & more; way more'
|
|
|
|
end
|
2017-05-01 10:53:13 +08:00
|
|
|
set x (functions -v -D multiline_descr)
|
2017-03-14 08:22:33 +08:00
|
|
|
if test $x[5] != 'line 1\\\\n\\nline 2 & more; way more'
|
2017-05-01 10:53:13 +08:00
|
|
|
echo "Unexpected output for 'functions -v -D multiline_descr': $x" >&2
|
2017-03-14 08:22:33 +08:00
|
|
|
end
|
2018-07-23 02:22:47 +08:00
|
|
|
|
|
|
|
# ==========
|
|
|
|
# Verify function description setting
|
2020-03-10 02:36:12 +08:00
|
|
|
function test_func_desc
|
|
|
|
end
|
2018-07-23 02:22:47 +08:00
|
|
|
functions test_func_desc | string match --quiet '*description*'
|
|
|
|
and echo "Unexpected description" >&2
|
|
|
|
|
|
|
|
functions --description description1 test_func_desc
|
|
|
|
functions test_func_desc | string match --quiet '*description1*'
|
|
|
|
or echo "Failed to find description 1" >&2
|
|
|
|
|
|
|
|
functions -d description2 test_func_desc
|
|
|
|
functions test_func_desc | string match --quiet '*description2*'
|
|
|
|
or echo "Failed to find description 2" >&2
|
2019-06-23 00:20:54 +08:00
|
|
|
|
2020-11-29 13:20:43 +08:00
|
|
|
# ==========
|
|
|
|
# Verify that the functions are printed in order.
|
|
|
|
functions f1 test_func_desc
|
|
|
|
# CHECK: # Defined in {{.*}}
|
|
|
|
# CHECK: function f1
|
|
|
|
# CHECK: end
|
|
|
|
# CHECK: # Defined in {{.*}}
|
|
|
|
# CHECK: function test_func_desc --description description2
|
|
|
|
# CHECK: end
|
|
|
|
|
2019-06-23 00:20:54 +08:00
|
|
|
# Note: This test isn't ideal - if ls was loaded before,
|
|
|
|
# or doesn't exist, it'll succeed anyway.
|
|
|
|
#
|
|
|
|
# But we can't *confirm* that an ls function exists,
|
|
|
|
# so this is the best we can do.
|
|
|
|
functions --erase ls
|
|
|
|
type -t ls
|
2020-02-08 05:10:55 +08:00
|
|
|
#CHECK: file
|
2020-12-12 06:05:22 +08:00
|
|
|
|
2021-02-09 05:25:30 +08:00
|
|
|
# ==========
|
|
|
|
# Verify that `functions --query` does not return 0 if there are 256 missing functions
|
|
|
|
functions --query a(seq 1 256)
|
|
|
|
echo $status
|
|
|
|
#CHECK: 255
|
|
|
|
|
2020-12-12 06:05:22 +08:00
|
|
|
echo "function t; echo tttt; end" | source
|
|
|
|
functions t
|
|
|
|
# CHECK: # Defined via `source`
|
|
|
|
# CHECK: function t
|
|
|
|
# CHECK: echo tttt;
|
|
|
|
# CHECK: end
|
|
|
|
|