mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-27 03:13:37 +08:00
163 lines
2.2 KiB
Plaintext
163 lines
2.2 KiB
Plaintext
#Test scoping rules for functions
|
|
|
|
set -e smurf
|
|
|
|
function setter
|
|
set smurf green
|
|
end
|
|
|
|
function unsetter
|
|
set -e smurf
|
|
end
|
|
|
|
function call1
|
|
set smurf blue; setter; if test $smurf = blue; echo Test 1 pass; else; echo Test 1 fail; end
|
|
end
|
|
|
|
function call2
|
|
set smurf blue; unsetter; if test $smurf = blue; echo Test 2 pass; else; echo Test 2 fail; end
|
|
end
|
|
|
|
call1
|
|
call2
|
|
|
|
function call3
|
|
setter; if test $smurf = green; echo Test 3 pass; else; echo Test 3 fail; end
|
|
end
|
|
|
|
function call4
|
|
unsetter; if not set -q smurf; echo Test 4 pass; else; echo Test 4 fail; end
|
|
end
|
|
|
|
set -g smurf yellow
|
|
call3
|
|
call4
|
|
|
|
set -l foo 1
|
|
set -g bar 2
|
|
set -U baz 3
|
|
|
|
set -l -q foo
|
|
|
|
if test $status -ne 0
|
|
echo Test 5 fail
|
|
else
|
|
echo Test 5 pass
|
|
end;
|
|
|
|
if not set -g -q bar
|
|
echo Test 6 fail
|
|
else
|
|
echo Test 6 pass
|
|
end;
|
|
|
|
if not set -U -q baz
|
|
echo Test 7 fail
|
|
else
|
|
echo Test 7 pass
|
|
end;
|
|
|
|
set -u -l -q foo
|
|
if test $status -ne 0
|
|
echo Test 8 fail
|
|
else
|
|
echo Test 8 pass
|
|
|
|
end;
|
|
|
|
if not set -u -g -q bar
|
|
echo Test 9 fail
|
|
else
|
|
echo Test 9 pass
|
|
end;
|
|
|
|
if not set -u -U -q baz
|
|
echo Test 10 fail
|
|
else
|
|
echo Test 10 pass
|
|
end;
|
|
|
|
set -x -l -q foo
|
|
if test $status -eq 0
|
|
echo Test 11 fail
|
|
else
|
|
echo Test 11 pass
|
|
end;
|
|
|
|
if set -x -g -q bar
|
|
echo Test 12 fail
|
|
else
|
|
echo Test 12 pass
|
|
end;
|
|
|
|
if set -x -U -q baz
|
|
echo Test 13 fail
|
|
else
|
|
echo Test 13 pass
|
|
end;
|
|
|
|
set -x -l foo 1
|
|
set -x -g bar 2
|
|
set -x -U baz 3
|
|
|
|
set -l -q foo
|
|
if test $status -ne 0
|
|
echo Test 14 fail
|
|
else
|
|
echo Test 14 pass
|
|
end;
|
|
|
|
if not set -g -q bar
|
|
echo Test 15 fail
|
|
else
|
|
echo Test 15 pass
|
|
end;
|
|
|
|
if not set -U -q baz
|
|
echo Test 16 fail
|
|
else
|
|
echo Test 16 pass
|
|
|
|
end;
|
|
|
|
set -u -l -q foo
|
|
if test $status -ne 1
|
|
echo Test 17 fail
|
|
else
|
|
echo Test 17 pass
|
|
end;
|
|
|
|
if set -u -g -q bar
|
|
echo Test 18 fail
|
|
else
|
|
echo Test 18 pass
|
|
end;
|
|
|
|
if set -u -U -q baz
|
|
echo Test 19 fail
|
|
else
|
|
echo Test 19 pass
|
|
|
|
end;
|
|
|
|
set -x -l -q foo
|
|
if test $status -ne 0
|
|
echo Test 20 fail
|
|
else
|
|
echo Test 20 pass
|
|
end;
|
|
|
|
if not set -x -g -q bar
|
|
echo Test 21 fail
|
|
else
|
|
echo Test 21 pass
|
|
end;
|
|
|
|
if not set -x -U -q baz
|
|
echo Test 22 fail
|
|
else
|
|
echo Test 22 pass
|
|
end;
|
|
|
|
set -U -e baz
|