2017-01-10 06:49:33 +00:00
|
|
|
# vim: set filetype=fish:
|
|
|
|
#
|
|
|
|
# Test the `functions` builtin
|
|
|
|
|
|
|
|
function f1
|
|
|
|
end
|
|
|
|
|
|
|
|
# ==========
|
2017-05-01 02:53:13 +00:00
|
|
|
# Verify that `functions --details` works as expected when given too many args.
|
|
|
|
set x (functions --details f1 f2 2>&1)
|
|
|
|
if test "$x" != "functions: Expected exactly one function name for --details"
|
|
|
|
echo "Unexpected output for 'functions --details f1 f2': $x" >&2
|
2017-01-10 06:49:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# ==========
|
2017-05-01 02:53:13 +00:00
|
|
|
# Verify that `functions --details` works as expected when given the name of a
|
2017-01-10 06:49:33 +00:00
|
|
|
# known function.
|
2017-05-01 02:53:13 +00:00
|
|
|
set x (functions --details f1)
|
2017-01-10 06:49:33 +00:00
|
|
|
if test "$x" != "stdin"
|
2017-05-01 02:53:13 +00:00
|
|
|
echo "Unexpected output for 'functions --details f1': $x" >&2
|
2017-01-10 06:49:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# ==========
|
2017-05-01 02:53:13 +00:00
|
|
|
# Verify that `functions --details` works as expected when given the name of an
|
2017-01-10 06:49:33 +00:00
|
|
|
# unknown function.
|
2017-05-01 02:53:13 +00:00
|
|
|
set x (functions -D f2)
|
2017-01-10 06:49:33 +00:00
|
|
|
if test "$x" != "n/a"
|
2017-05-01 02:53:13 +00:00
|
|
|
echo "Unexpected output for 'functions --details f2': $x" >&2
|
2017-01-10 06:49:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# ==========
|
2017-05-01 02:53:13 +00:00
|
|
|
# Verify that `functions --details` works as expected when given the name of a
|
2017-01-10 06:49:33 +00:00
|
|
|
# function that could be autoloaded but isn't currently loaded.
|
2017-05-01 02:53:13 +00:00
|
|
|
set x (functions -D abbr)
|
2017-01-10 06:49:33 +00:00
|
|
|
if test (count $x) -ne 1
|
|
|
|
or not string match -q '*/share/functions/abbr.fish' "$x"
|
2017-05-01 02:53:13 +00:00
|
|
|
echo "Unexpected output for 'functions -D abbr': $x" >&2
|
2017-01-10 06:49:33 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# ==========
|
2017-05-01 02:53:13 +00:00
|
|
|
# Verify that `functions --verbose --details` works as expected when given the name of a
|
2017-01-10 06:49:33 +00:00
|
|
|
# function that was autoloaded.
|
2017-05-01 02:53:13 +00:00
|
|
|
set x (functions -v -D abbr)
|
2017-03-14 00:22:33 +00:00
|
|
|
if test (count $x) -ne 5
|
2017-01-10 06:49:33 +00: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
|
2017-05-22 05:22:55 +00:00
|
|
|
or test $x[5] != 'Manage abbreviations using new fish 3.0 scheme.'
|
2017-05-01 02:53:13 +00:00
|
|
|
echo "Unexpected output for 'functions -v -D abbr': $x" >&2
|
2017-01-10 06:49:33 +00:00
|
|
|
end
|
2017-03-14 00:22:33 +00:00
|
|
|
|
|
|
|
# ==========
|
2017-05-01 02:53:13 +00:00
|
|
|
# Verify that `functions --verbose --details` properly escapes a function
|
2017-03-14 00:22:33 +00:00
|
|
|
# with a multiline description.
|
|
|
|
function multiline_descr -d 'line 1\n
|
|
|
|
line 2 & more; way more'
|
|
|
|
end
|
2017-05-01 02:53:13 +00:00
|
|
|
set x (functions -v -D multiline_descr)
|
2017-03-14 00:22:33 +00:00
|
|
|
if test $x[5] != 'line 1\\\\n\\nline 2 & more; way more'
|
2017-05-01 02:53:13 +00:00
|
|
|
echo "Unexpected output for 'functions -v -D multiline_descr': $x" >&2
|
2017-03-14 00:22:33 +00:00
|
|
|
end
|