2024-04-12 10:19:32 +00:00
|
|
|
#RUN: %fish %s
|
2020-02-08 14:29:33 +00:00
|
|
|
# Test scoping rules for functions and status
|
2005-09-20 13:31:55 +00:00
|
|
|
|
|
|
|
set -e smurf
|
|
|
|
|
2010-09-18 02:18:26 +00:00
|
|
|
function setter
|
2020-03-09 18:36:12 +00:00
|
|
|
set smurf green
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
|
2010-09-18 02:18:26 +00:00
|
|
|
function unsetter
|
2020-03-09 18:36:12 +00:00
|
|
|
set -e smurf
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
|
2010-09-18 02:18:26 +00:00
|
|
|
function call1
|
2020-03-09 18:36:12 +00:00
|
|
|
set smurf blue
|
|
|
|
setter
|
|
|
|
if test $smurf = blue
|
|
|
|
echo Test 1 pass
|
|
|
|
else
|
|
|
|
echo Test 1 fail
|
|
|
|
end
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
|
2010-09-18 02:18:26 +00:00
|
|
|
function call2
|
2020-03-09 18:36:12 +00:00
|
|
|
set smurf blue
|
|
|
|
unsetter
|
|
|
|
if test $smurf = blue
|
|
|
|
echo Test 2 pass
|
|
|
|
else
|
|
|
|
echo Test 2 fail
|
|
|
|
end
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
call1
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 1 pass
|
2005-09-20 13:31:55 +00:00
|
|
|
call2
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 2 pass
|
2005-09-20 13:31:55 +00:00
|
|
|
|
2010-09-18 02:18:26 +00:00
|
|
|
function call3
|
2020-03-09 18:36:12 +00:00
|
|
|
setter
|
|
|
|
if test $smurf = green
|
|
|
|
echo Test 3 pass
|
|
|
|
else
|
|
|
|
echo Test 3 fail
|
|
|
|
end
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
|
2010-09-18 02:18:26 +00:00
|
|
|
function call4
|
2020-03-09 18:36:12 +00:00
|
|
|
unsetter
|
|
|
|
if not set -q smurf
|
|
|
|
echo Test 4 pass
|
|
|
|
else
|
|
|
|
echo Test 4 fail
|
|
|
|
end
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
set -g smurf yellow
|
|
|
|
call3
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 3 pass
|
2005-09-20 13:31:55 +00:00
|
|
|
call4
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 4 pass
|
2005-09-20 13:31:55 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
set -l foo 1
|
|
|
|
set -g bar 2
|
|
|
|
set -U baz 3
|
2012-06-18 17:20:40 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
set -l -q foo
|
2012-06-18 17:20:40 +00:00
|
|
|
|
|
|
|
if test $status -ne 0
|
2016-11-28 03:05:37 +00:00
|
|
|
echo Test 5 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 5 pass
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 5 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
if not set -g -q bar
|
|
|
|
echo Test 6 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 6 pass
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 6 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
if not set -U -q baz
|
|
|
|
echo Test 7 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 7 pass
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 7 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
set -u -l -q foo
|
|
|
|
if test $status -ne 0
|
|
|
|
echo Test 8 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 8 pass
|
|
|
|
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 8 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
if not set -u -g -q bar
|
|
|
|
echo Test 9 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 9 pass
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 9 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
if not set -u -U -q baz
|
|
|
|
echo Test 10 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 10 pass
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 10 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
set -x -l -q foo
|
2012-06-18 17:20:40 +00:00
|
|
|
if test $status -eq 0
|
2016-11-28 03:05:37 +00:00
|
|
|
echo Test 11 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 11 pass
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 11 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
if set -x -g -q bar
|
|
|
|
echo Test 12 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 12 pass
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 12 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
if set -x -U -q baz
|
|
|
|
echo Test 13 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 13 pass
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 13 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
|
|
|
set -x -l foo 1
|
|
|
|
set -x -g bar 2
|
|
|
|
set -x -U baz 3
|
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
set -l -q foo
|
|
|
|
if test $status -ne 0
|
|
|
|
echo Test 14 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 14 pass
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 14 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
if not set -g -q bar
|
|
|
|
echo Test 15 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 15 pass
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 15 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
if not set -U -q baz
|
|
|
|
echo Test 16 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 16 pass
|
|
|
|
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 16 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
set -u -l -q foo
|
|
|
|
if test $status -ne 1
|
|
|
|
echo Test 17 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 17 pass
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 17 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
if set -u -g -q bar
|
|
|
|
echo Test 18 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 18 pass
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 18 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
if set -u -U -q baz
|
|
|
|
echo Test 19 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 19 pass
|
|
|
|
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 19 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
set -x -l -q foo
|
|
|
|
if test $status -ne 0
|
|
|
|
echo Test 20 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 20 pass
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 20 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
if not set -x -g -q bar
|
|
|
|
echo Test 21 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 21 pass
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 21 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
2016-11-28 03:05:37 +00:00
|
|
|
if not set -x -U -q baz
|
|
|
|
echo Test 22 fail
|
2012-06-18 17:20:40 +00:00
|
|
|
else
|
|
|
|
echo Test 22 pass
|
2020-03-09 18:36:12 +00:00
|
|
|
end
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Test 22 pass
|
2012-06-18 17:20:40 +00:00
|
|
|
|
|
|
|
set -U -e baz
|
2013-01-31 23:57:08 +00:00
|
|
|
|
2020-02-08 14:29:33 +00:00
|
|
|
# Verify subcommand statuses
|
2013-01-31 23:57:08 +00:00
|
|
|
echo (false) $status (true) $status (false) $status
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: 1 0 1
|
2013-01-31 23:57:08 +00:00
|
|
|
|
2020-02-08 14:29:33 +00:00
|
|
|
# Verify that set passes through exit status, except when passed -n or -q or -e
|
2020-03-09 18:36:12 +00:00
|
|
|
false
|
|
|
|
set foo bar
|
|
|
|
echo 1 $status # passthrough
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: 1 1
|
2020-03-09 18:36:12 +00:00
|
|
|
true
|
|
|
|
set foo bar
|
|
|
|
echo 2 $status # passthrough
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: 2 0
|
2020-03-09 18:36:12 +00:00
|
|
|
false
|
|
|
|
set -q foo
|
|
|
|
echo 3 $status # no passthrough
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: 3 0
|
2020-03-09 18:36:12 +00:00
|
|
|
true
|
|
|
|
set -q foo
|
|
|
|
echo 4 $status # no passthrough
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: 4 0
|
2020-03-09 18:36:12 +00:00
|
|
|
false
|
|
|
|
set -n >/dev/null
|
|
|
|
echo 5 $status # no passthrough
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: 5 0
|
2020-03-09 18:36:12 +00:00
|
|
|
false
|
|
|
|
set -e foo
|
|
|
|
echo 6 $status # no passthrough
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: 6 0
|
2020-03-09 18:36:12 +00:00
|
|
|
true
|
|
|
|
set -e foo
|
|
|
|
echo 7 $status # no passthrough
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: 7 4
|
2020-03-09 18:36:12 +00:00
|
|
|
false
|
|
|
|
set -h >/dev/null
|
2021-11-04 05:52:17 +00:00
|
|
|
# CHECKERR: fish: set: missing man page
|
|
|
|
# CHECKERR: Documentation may not be installed.
|
|
|
|
# CHECKERR: `help set` will show an online version
|
2021-03-19 16:20:30 +00:00
|
|
|
|
2020-03-09 18:36:12 +00:00
|
|
|
echo 8 $status # no passthrough
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: 8 0
|
2020-03-09 18:36:12 +00:00
|
|
|
true
|
|
|
|
set -NOT_AN_OPTION 2>/dev/null
|
|
|
|
echo 9 $status # no passthrough
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: 9 2
|
2020-03-09 18:36:12 +00:00
|
|
|
false
|
|
|
|
set foo (echo A; true)
|
|
|
|
echo 10 $status $foo
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: 10 0 A
|
2020-03-09 18:36:12 +00:00
|
|
|
true
|
|
|
|
set foo (echo B; false)
|
|
|
|
echo 11 $status $foo
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: 11 1 B
|
2013-01-31 23:57:08 +00:00
|
|
|
true
|
2015-10-23 22:15:39 +00:00
|
|
|
|
|
|
|
function setql_check
|
2020-03-09 18:36:12 +00:00
|
|
|
set -l setql_foo val
|
|
|
|
if set -ql setql_foo
|
|
|
|
echo Pass
|
|
|
|
else
|
|
|
|
echo Fail
|
|
|
|
end
|
2015-10-23 22:15:39 +00:00
|
|
|
end
|
|
|
|
setql_check
|
2020-02-08 14:29:33 +00:00
|
|
|
#CHECK: Pass
|