#   This program is free software: you can redistribute it and/or modify
#   it under the terms of the GNU General Public License as published by
#   the Free Software Foundation, either version 3 of the License, or
#   (at your option) any later version.
#
#   This program is distributed in the hope that it will be useful,
#   but WITHOUT ANY WARRANTY; without even the implied warranty of
#   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#   GNU General Public License for more details.
#
#   You should have received a copy of the GNU General Public License
#   along with this program.  If not, see <http://www.gnu.org/licenses/>.
#

# set of tests for posix interp 1009, unset variable in tempenv

# posix doesn't have local variables, but other shells echo
# 
# local local global global
#
# ash-based shells unset local x in f1 after call to f2; we can do this
# with localvar_unset option

f1()
{
	local x=local
	echo $FUNCNAME: x = $x
	f2
	echo after f2: x = ${x-unset}
}

f2()
{
	echo $FUNCNAME: x = $x
	unset x	
}

x=global
f1
echo default after f1: x = $x

shopt -s localvar_unset
x=global
f1
echo localvar_unset after f1: x = $x
shopt -u localvar_unset

unset -f f1 f2
unset -v x

# posix says this should echo temp, then global

f1()
{
	echo $FUNCNAME: x = $x
	unset x	
}

x=global
x=temp f1

echo after f1: x = $x
unset -f f1
unset -v x

# posix says this should echo 'unset'
# interp 1009

x=global
x=temp unset x
echo 1009: after bash unset: x = ${x-unset}

set -o posix
x=global
x=temp unset x
echo 1009: after posix unset: x = ${x-unset}
set +o posix

unset -v x

# posix says this should echo local, unset, global

f1()
{
	local x=local
	echo $FUNCNAME: x = $x
	x=temp unset x	
	echo after unset $FUNCNAME: x = ${x-unset}
}

x=global
f1
echo 1009: after bash f1: x = $x

set -o posix
x=global
f1
echo 1009: after posix f1: x = $x
set +o posix

unset -f f1
unset -v x
