2005-09-20 13:31:55 +00:00
|
|
|
# Environment variable tests
|
|
|
|
|
|
|
|
#Test if variables can be properly set
|
|
|
|
|
|
|
|
set smurf blue
|
|
|
|
|
|
|
|
if test $smurf = blue
|
|
|
|
echo Test 1 pass
|
|
|
|
else
|
|
|
|
echo Test 1 fail
|
|
|
|
end
|
|
|
|
|
|
|
|
# Test if variables can be erased
|
|
|
|
|
|
|
|
set -e smurf
|
|
|
|
|
|
|
|
if test $smurf
|
|
|
|
echo Test 2 fail
|
|
|
|
else
|
|
|
|
echo Test 2 pass
|
|
|
|
end
|
|
|
|
|
|
|
|
# Test if local variables go out of scope
|
|
|
|
|
2005-09-27 08:35:54 +00:00
|
|
|
set -e t3
|
2005-09-20 13:31:55 +00:00
|
|
|
if true
|
2005-09-27 17:40:25 +00:00
|
|
|
set -l t3 bar
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if test $t3
|
2005-09-27 17:40:25 +00:00
|
|
|
echo Test 3 fail
|
2005-09-20 13:31:55 +00:00
|
|
|
else
|
2005-09-27 17:40:25 +00:00
|
|
|
echo Test 3 pass
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Test if globals can be set in block scope
|
|
|
|
|
|
|
|
if true
|
2005-09-27 17:40:25 +00:00
|
|
|
set -g baz qux
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if test $baz = qux
|
2005-09-27 17:40:25 +00:00
|
|
|
echo Test 4 pass
|
2005-09-20 13:31:55 +00:00
|
|
|
else
|
2005-09-27 17:40:25 +00:00
|
|
|
echo Test 4 fail
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
#Test that scope is preserved when setting a new value
|
|
|
|
|
|
|
|
set t5 a
|
|
|
|
|
|
|
|
if true
|
2005-09-27 17:40:25 +00:00
|
|
|
set t5 b
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
if test $t5 = b
|
2005-09-27 17:40:25 +00:00
|
|
|
echo Test 5 pass
|
2005-09-20 13:31:55 +00:00
|
|
|
else
|
2005-09-27 17:40:25 +00:00
|
|
|
echo Test 5 fail
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
# Test that scope is preserved in double blocks
|
|
|
|
|
2010-09-18 02:18:26 +00:00
|
|
|
for i in 1
|
2005-09-20 13:31:55 +00:00
|
|
|
set t6 $i
|
2010-09-18 02:18:26 +00:00
|
|
|
for j in a
|
2005-09-27 17:40:25 +00:00
|
|
|
if test $t6$j = 1a
|
2005-09-20 13:31:55 +00:00
|
|
|
echo Test 6 pass
|
|
|
|
else
|
|
|
|
echo Test 6 fail
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# Test if variables in for loop blocks do not go out of scope on new laps
|
|
|
|
|
|
|
|
set res fail
|
|
|
|
|
2005-10-02 13:44:06 +00:00
|
|
|
set -e t7
|
2005-09-20 13:31:55 +00:00
|
|
|
for i in 1 2
|
2005-09-27 17:40:25 +00:00
|
|
|
if test $i = 1
|
2005-10-02 13:44:06 +00:00
|
|
|
set t7 lala
|
2005-09-27 17:40:25 +00:00
|
|
|
else
|
2005-10-02 13:44:06 +00:00
|
|
|
if test $t7
|
2005-09-27 17:40:25 +00:00
|
|
|
set res pass
|
|
|
|
end
|
|
|
|
end
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
echo Test 7 $res
|
|
|
|
|
|
|
|
# Test if variables are properly exported
|
|
|
|
|
2005-09-27 08:35:54 +00:00
|
|
|
set -e t8
|
2005-09-20 13:31:55 +00:00
|
|
|
if true
|
2005-09-27 17:40:25 +00:00
|
|
|
set -lx t8 foo
|
|
|
|
if test (../fish -c "echo $t8") = foo
|
|
|
|
echo Test 8 pass
|
2005-09-20 13:31:55 +00:00
|
|
|
else
|
2005-09-27 17:40:25 +00:00
|
|
|
echo Test 8 fail
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Test if exported variables go out of scope
|
|
|
|
|
2010-09-18 02:18:26 +00:00
|
|
|
if test (../fish -c "echo $t8")
|
2005-09-27 17:40:25 +00:00
|
|
|
echo Test 9 fail
|
2005-09-20 13:31:55 +00:00
|
|
|
else
|
2005-09-27 17:40:25 +00:00
|
|
|
echo Test 9 pass
|
2005-09-20 13:31:55 +00:00
|
|
|
end
|
|
|
|
|
2006-06-05 13:31:33 +00:00
|
|
|
# Test erasing variables in specific scope
|
2005-09-20 13:31:55 +00:00
|
|
|
|
2006-06-05 13:31:33 +00:00
|
|
|
set -eU foo
|
|
|
|
set -g foo bar
|
|
|
|
begin
|
|
|
|
set -l foo baz
|
|
|
|
set -eg foo
|
|
|
|
end
|
|
|
|
|
|
|
|
if set -q foo
|
|
|
|
echo Test 10 fail
|
|
|
|
else
|
|
|
|
echo Test 10 pass
|
|
|
|
end
|
|
|
|
|
|
|
|
|
2012-05-10 08:04:18 +00:00
|
|
|
set foo abc def
|
|
|
|
set -e foo[1]
|
|
|
|
if test $foo '=' def
|
|
|
|
echo Test 11 pass
|
|
|
|
else
|
|
|
|
echo Test 11 fail
|
|
|
|
end
|
2012-12-29 18:25:00 +00:00
|
|
|
|
|
|
|
# Test combinations of export and scope
|
|
|
|
|
|
|
|
set -ge foo
|
|
|
|
|
|
|
|
set -Ue foo
|
|
|
|
set -Ux foo bar
|
|
|
|
set foo baz
|
|
|
|
if test (/bin/sh -c 'echo $foo') = baz -a (../fish -c 'echo $foo') = baz
|
|
|
|
echo Test 12 pass
|
|
|
|
else
|
|
|
|
echo Test 12 fail
|
|
|
|
end
|
|
|
|
|
|
|
|
set -Ue foo
|
|
|
|
set -Ux foo bar
|
|
|
|
set -U foo baz
|
|
|
|
if test (/bin/sh -c 'echo $foo') = baz -a (../fish -c 'echo $foo') = baz
|
|
|
|
echo Test 13 pass
|
|
|
|
else
|
|
|
|
echo Test 13 fail
|
|
|
|
end
|
|
|
|
|
|
|
|
set -Ux foo bar
|
|
|
|
set -u foo bar
|
|
|
|
if test (/bin/sh -c 'echo $foo') = '' -a (../fish -c 'echo $foo') = bar
|
|
|
|
echo Test 14 pass
|
|
|
|
else
|
|
|
|
echo Test 14 fail
|
|
|
|
end
|
|
|
|
|
|
|
|
set -Ux foo bar
|
|
|
|
set -Uu foo baz
|
|
|
|
if test (/bin/sh -c 'echo $foo') = '' -a (../fish -c 'echo $foo') = baz
|
|
|
|
echo Test 15 pass
|
|
|
|
else
|
|
|
|
echo Test 15 fail
|
|
|
|
end
|
|
|
|
|
|
|
|
set -eU foo
|
|
|
|
|
|
|
|
# test erasing variables without a specified scope
|
|
|
|
|
|
|
|
set -g test16res
|
|
|
|
|
|
|
|
set -U foo universal
|
|
|
|
set -g foo global
|
|
|
|
begin
|
|
|
|
set -l foo blocklocal
|
|
|
|
function test16
|
|
|
|
set -l foo function
|
|
|
|
begin
|
|
|
|
set -l foo functionblock
|
|
|
|
|
|
|
|
set test16res $test16res (echo $foo)
|
|
|
|
set -e foo
|
|
|
|
set test16res $test16res (echo $foo)
|
|
|
|
set -e foo
|
|
|
|
set test16res $test16res (echo $foo)
|
|
|
|
set -e foo
|
|
|
|
set test16res $test16res (echo $foo)
|
|
|
|
set -e foo
|
|
|
|
set test16res $test16res (echo $foo)
|
|
|
|
end
|
|
|
|
set test16res $test16res (echo $foo)
|
|
|
|
set -e foo
|
|
|
|
end
|
|
|
|
test16
|
|
|
|
set test16res $test16res (echo $foo)
|
|
|
|
end
|
|
|
|
set test16res $test16res (echo $foo)
|
|
|
|
|
|
|
|
#echo count: (count $test16res) "content:[$test16res]"
|
|
|
|
|
|
|
|
if test (count $test16res) = 8 -a "$test16res" = "functionblock function global universal blocklocal "
|
|
|
|
echo Test 16 pass
|
|
|
|
else
|
|
|
|
echo Test 16 fail
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
# clear foo for other shells
|
|
|
|
set -eU foo
|
|
|
|
true
|