diff options
author | Kevin Ballard <kevin@sb.org> | 2014-10-02 15:59:24 -0700 |
---|---|---|
committer | Kevin Ballard <kevin@sb.org> | 2014-10-02 18:41:39 -0700 |
commit | cfc06203e7ad7707acadd160292d47b25d6daba6 (patch) | |
tree | 387a4aa8149477309f9c545dfb9c6ccf1ea24ac1 /tests/function.in | |
parent | 6d7a7b00d77098c93aa2b6c0deba4c18029b5a32 (diff) |
Add new `functions` flag -V/--inherit-variable
--inherit-variable takes a variable name and snapshots its current
value. When the function is executed, it will have a local variable with
this value already defined. Printing the function source will include
synthesized `set -l` lines for the values.
This is primarily useful for functions that are created on the fly, such
as in `psub`.
Diffstat (limited to 'tests/function.in')
-rw-r--r-- | tests/function.in | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/function.in b/tests/function.in new file mode 100644 index 00000000..e533b25b --- /dev/null +++ b/tests/function.in @@ -0,0 +1,32 @@ +# 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 |