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
|
|
|
|
|
|
|
|
for i in 1
|
|
|
|
set t6 $i
|
|
|
|
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
|
|
|
|
|
2005-09-27 17:40:25 +00:00
|
|
|
if test (../fish -c "echo $t8")
|
|
|
|
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
|
|
|
|
|
|
|
|
|
|
|
|
|