2005-09-20 21:31:55 +08:00
|
|
|
#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
|
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
|
|
|
|
|