From cfc06203e7ad7707acadd160292d47b25d6daba6 Mon Sep 17 00:00:00 2001 From: Kevin Ballard Date: Thu, 2 Oct 2014 15:59:24 -0700 Subject: 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`. --- tests/function.err | 0 tests/function.in | 32 ++++++++++++++++++++++++++++++++ tests/function.out | 20 ++++++++++++++++++++ tests/function.status | 1 + 4 files changed, 53 insertions(+) create mode 100644 tests/function.err create mode 100644 tests/function.in create mode 100644 tests/function.out create mode 100644 tests/function.status (limited to 'tests') diff --git a/tests/function.err b/tests/function.err new file mode 100644 index 00000000..e69de29b 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 diff --git a/tests/function.out b/tests/function.out new file mode 100644 index 00000000..3fa70990 --- /dev/null +++ b/tests/function.out @@ -0,0 +1,20 @@ +Testing -V +$foo: (1) +1: 'local foo' +$bar: (5) +1: 'one' +2: 'two 2' +3: ' ' +4: '' +5: '3' +$baz: (0) +Testing -V with changed variables +$foo: (1) +1: 'local foo' +$bar: (5) +1: 'one' +2: 'two 2' +3: ' ' +4: '' +5: '3' +$baz: (0) diff --git a/tests/function.status b/tests/function.status new file mode 100644 index 00000000..573541ac --- /dev/null +++ b/tests/function.status @@ -0,0 +1 @@ +0 -- cgit v1.2.3