2005-09-20 21:31:55 +08:00
|
|
|
#Test scoping rules for functions
|
|
|
|
|
|
|
|
set -e smurf
|
|
|
|
|
2010-09-18 10:18:26 +08:00
|
|
|
function setter
|
2005-09-20 21:31:55 +08:00
|
|
|
set smurf green
|
|
|
|
end
|
|
|
|
|
2010-09-18 10:18:26 +08:00
|
|
|
function unsetter
|
2005-09-20 21:31:55 +08:00
|
|
|
set -e smurf
|
|
|
|
end
|
|
|
|
|
2010-09-18 10:18:26 +08:00
|
|
|
function call1
|
2005-09-20 21:31:55 +08:00
|
|
|
set smurf blue; setter; if test $smurf = blue; echo Test 1 pass; else; echo Test 1 fail; end
|
|
|
|
end
|
|
|
|
|
2010-09-18 10:18:26 +08:00
|
|
|
function call2
|
2005-09-20 21:31:55 +08:00
|
|
|
set smurf blue; unsetter; if test $smurf = blue; echo Test 2 pass; else; echo Test 2 fail; end
|
|
|
|
end
|
|
|
|
|
|
|
|
call1
|
|
|
|
call2
|
|
|
|
|
2010-09-18 10:18:26 +08:00
|
|
|
function call3
|
2005-09-20 21:31:55 +08:00
|
|
|
setter; if test $smurf = green; echo Test 3 pass; else; echo Test 3 fail; end
|
|
|
|
end
|
|
|
|
|
2010-09-18 10:18:26 +08:00
|
|
|
function call4
|
2006-06-05 21:31:33 +08:00
|
|
|
unsetter; if not set -q smurf; echo Test 4 pass; else; echo Test 4 fail; end
|
2005-09-20 21:31:55 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
set -g smurf yellow
|
|
|
|
call3
|
|
|
|
call4
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
set -l foo 1
|
|
|
|
set -g bar 2
|
|
|
|
set -U baz 3
|
2012-06-19 01:20:40 +08:00
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
set -l -q foo
|
2012-06-19 01:20:40 +08:00
|
|
|
|
|
|
|
if test $status -ne 0
|
2016-11-28 11:05:37 +08:00
|
|
|
echo Test 5 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 5 pass
|
|
|
|
end;
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
if not set -g -q bar
|
|
|
|
echo Test 6 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 6 pass
|
|
|
|
end;
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
if not set -U -q baz
|
|
|
|
echo Test 7 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 7 pass
|
|
|
|
end;
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
set -u -l -q foo
|
|
|
|
if test $status -ne 0
|
|
|
|
echo Test 8 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 8 pass
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
if not set -u -g -q bar
|
|
|
|
echo Test 9 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 9 pass
|
|
|
|
end;
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
if not set -u -U -q baz
|
|
|
|
echo Test 10 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 10 pass
|
|
|
|
end;
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
set -x -l -q foo
|
2012-06-19 01:20:40 +08:00
|
|
|
if test $status -eq 0
|
2016-11-28 11:05:37 +08:00
|
|
|
echo Test 11 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 11 pass
|
|
|
|
end;
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
if set -x -g -q bar
|
|
|
|
echo Test 12 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 12 pass
|
|
|
|
end;
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
if set -x -U -q baz
|
|
|
|
echo Test 13 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 13 pass
|
|
|
|
end;
|
|
|
|
|
|
|
|
set -x -l foo 1
|
|
|
|
set -x -g bar 2
|
|
|
|
set -x -U baz 3
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
set -l -q foo
|
|
|
|
if test $status -ne 0
|
|
|
|
echo Test 14 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 14 pass
|
|
|
|
end;
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
if not set -g -q bar
|
|
|
|
echo Test 15 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 15 pass
|
|
|
|
end;
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
if not set -U -q baz
|
|
|
|
echo Test 16 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 16 pass
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
set -u -l -q foo
|
|
|
|
if test $status -ne 1
|
|
|
|
echo Test 17 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 17 pass
|
|
|
|
end;
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
if set -u -g -q bar
|
|
|
|
echo Test 18 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 18 pass
|
|
|
|
end;
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
if set -u -U -q baz
|
|
|
|
echo Test 19 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 19 pass
|
|
|
|
|
|
|
|
end;
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
set -x -l -q foo
|
|
|
|
if test $status -ne 0
|
|
|
|
echo Test 20 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 20 pass
|
|
|
|
end;
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
if not set -x -g -q bar
|
|
|
|
echo Test 21 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 21 pass
|
|
|
|
end;
|
|
|
|
|
2016-11-28 11:05:37 +08:00
|
|
|
if not set -x -U -q baz
|
|
|
|
echo Test 22 fail
|
2012-06-19 01:20:40 +08:00
|
|
|
else
|
|
|
|
echo Test 22 pass
|
|
|
|
end;
|
|
|
|
|
|
|
|
set -U -e baz
|
2013-02-01 07:57:08 +08:00
|
|
|
|
2017-07-25 02:42:54 +08:00
|
|
|
echo "# Verify subcommand statuses"
|
2013-02-01 07:57:08 +08:00
|
|
|
echo (false) $status (true) $status (false) $status
|
|
|
|
|
2017-07-25 02:42:54 +08:00
|
|
|
echo "# Verify that set passes through exit status, except when passed -n or -q or -e"
|
2013-02-01 07:57:08 +08:00
|
|
|
false ; set foo bar ; echo 1 $status # passthrough
|
|
|
|
true ; set foo bar ; echo 2 $status # passthrough
|
|
|
|
false ; set -q foo ; echo 3 $status # no passthrough
|
|
|
|
true ; set -q foo ; echo 4 $status # no passthrough
|
|
|
|
false ; set -n > /dev/null ; echo 5 $status # no passthrough
|
|
|
|
false ; set -e foo ; echo 6 $status # no passthrough
|
|
|
|
true ; set -e foo ; echo 7 $status # no passthrough
|
|
|
|
false ; set -h > /dev/null ; echo 8 $status # no passthrough
|
|
|
|
true ; set -NOT_AN_OPTION 2> /dev/null ; echo 9 $status # no passthrough
|
|
|
|
false ; set foo (echo A; true) ; echo 10 $status $foo
|
|
|
|
true ; set foo (echo B; false) ; echo 11 $status $foo
|
|
|
|
true
|
2015-10-24 06:15:39 +08:00
|
|
|
|
2017-07-25 02:42:54 +08:00
|
|
|
echo "# Verify set -ql behavior" # see 2502
|
2015-10-24 06:15:39 +08:00
|
|
|
function setql_check
|
|
|
|
set -l setql_foo val
|
|
|
|
if set -ql setql_foo
|
|
|
|
echo Pass
|
|
|
|
else
|
|
|
|
echo Fail
|
|
|
|
end
|
|
|
|
end
|
|
|
|
setql_check
|