########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2011 AT&T Intellectual Property #
# and is licensed under the #
# Eclipse Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# (with md5 checksum b35adb5213ca9657e911e9befb180842) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# David Korn <dgk@research.att.com> #
# #
########################################################################
# test the behavior of return and exit with functions
function err_exit
{
print -u2 -n "\t"
let Errors+=1
}
alias err_exit='err_exit $LINENO'
integer Errors=0
unset HISTFILE
function foo
{
> $file
if (( $1 == 0 ))
then return $2
elif (( $1 == 1 ))
then exit $2
else bar "$@"
fi
}
function bar
{
if (( $1 == 2 ))
then return $2
elif (( $1 == 3 ))
then exit $2
fi
}
function funcheck
{
if [[ -f $file ]]
fi
}
(exit 35)
ret=$?
fi
(return 35)
ret=$?
fi
ret=$?
fi
ret=$?
fi
(foo 3 3)
ret=$?
fi
return 3
exit 4
!
( . $file )
ret=$?
fi
( $file )
ret=$?
fi
: line 1
# next line should fail and cause an exit
: > /
exit 4
!
ret=$?
fi
ret=$?
fi
print -r -- "$0"
!
x=$( . $file)
if [[ $x != $0 ]]
then err_exit "\$0 in a dot script is $x. Should be $0"
fi
typeset -i x=1/0
print hello
!
)
if [[ $x != hello ]]
then err_exit "interactive shell terminates with error in bltin"
fi
x=$( set -e
false
print bad
)
if [[ $x != '' ]]
then err_exit "set -e doesn't terminate script on error"
fi
x=$( set -e
false
print bad
)
if (( $? != 0 ))
then err_exit "exit 0 in trap should doesn't set exit value to 0"
fi
$SHELL <<\!
trap 'exit 8' EXIT
exit 1
!
if (( $? != 8 ))
then err_exit "exit 8 in trap should set exit value to 8"
fi