########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2010 AT&T Intellectual Property #
# and is licensed under the #
# Common Public License, Version 1.0 #
# by AT&T Intellectual Property #
# #
# A copy of the License is available at #
# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) #
# #
# Information and Software Systems Research #
# AT&T Research #
# Florham Park NJ #
# #
# David Korn <dgk@research.att.com> #
# #
########################################################################
function err_exit
{
print -u2 -n "\t"
let Errors+=1
}
alias err_exit='err_exit $LINENO'
integer Errors=0
unset ss
[[ ${#ss} == 0 ]] || err_exit '${#ss} should be 0 when ss is unset'
# RANDOM
fi
# SECONDS
sleep 3
fi
# _
if [[ $_ != def ]]
fi
# ERRNO
#set abc def
#rm -f foobar#
#ERRNO=
#if (( ERRNO == 0 ))
#then err_exit ERRNO variable not working
#fi
# PWD
fi
# PPID
exp=$$
fi
# OLDPWD
cd /
fi
# REPLY
read <<-!
!
fi
# LINENO
LINENO=10
#
# These lines intentionally left blank
#
fi
IFS=:
x=a::b::c
if [[ $x != a::b::c ]]
then err_exit "word splitting on constants"
fi
set -- $x
if [[ $# != 5 ]]
then err_exit ":: doesn't separate null arguments "
fi
set x
then err_exit "x\$1=value treated as an assignment"
fi
# check for attributes across subshells
typeset -i x=3
y=1/0
then err_exit "attributes not passed to subshells"
fi
unset x
function x.set
{
.sh.value=$0
}
x=bar
if [[ $x != x.set ]]
fi
x.get()
{
}
if [[ $x != bar ]]
fi
typeset +n foo
unset foo
(
unset foo
set +u
then err_exit '$foo not null after unset in subsehll'
fi
)
then err_exit 'unset foo in subshell produces side effect '
fi
unset foo
then err_exit '${foo?hi there} with foo unset does not print hi there on 2'
fi
x=$0
set foobar
if [[ ${@:0} != "$x foobar" ]]
then err_exit '${@:0} not expanding correctly'
fi
set --
if [[ ${*:0:1} != "$0" ]]
then err_exit '${@:0} not expanding correctly'
fi
ACCESS=0
function COUNT.set
{
}
COUNT=0
fi
if [[ $LANG != C ]]
then err_exit "C locale not working"
fi
unset RANDOM
unset -n foo
function foo.get
{
unset -f foo.get
}
fi
fi
# special variables
set -- 1 2 3 4 5 6 7 8 9 10
sleep 1000 &
if [[ $(print -r -- ${#10}) != 2 ]]
then err_exit '${#10}, where ${10}=10 not working'
fi
do false
then err_exit "\$$i not equal to \${$i}"
fi
then err_exit "\${$i%?} not correct"
fi
if [[ $i != [@*] && ${foo#?} != "$bar" ]]
then err_exit "\${$i#?} not correct"
fi
x error"
then err_exit "\${#$i} not correct"
fi
done
kill $!
unset x
CDPATH=/
if [[ $x != $tmp ]]
then err_exit 'CDPATH does not display new directory'
fi
CDPATH=/:
if [[ $x ]]
then err_exit 'CDPATH displays new directory when not used'
fi
if [[ $x != $tmp ]]
then err_exit "CDPATH ${tmp#/} does not display new directory"
fi
TMOUT=100
(TMOUT=20)
then err_exit 'setting TMOUT in subshell affects parent'
fi
unset y
function setdisc # var
{
eval function $1.get'
{
.sh.value=good
}
'
}
y=bad
setdisc y
if [[ $y != good ]]
then err_exit 'setdisc function not working'
fi
integer x=$LINENO
: $'\
'
then err_exit '\<newline> gets linenumber count wrong'
fi
set --
set -- "${@-}"
if (( $# !=1 ))
then err_exit '"${@-}" not expanding to null string'
fi
done
unset IFS
x y z
!
if [[ $b ]]
then err_exit 'IFS=" " not causing adjacent space to be null string'
fi
)
read -r a b c <<-!
x y z
!
if [[ $b != y ]]
then err_exit 'IFS not restored after subshell'
fi
unset IFS x
function split
{
i=$1 s=$2 r=$3
IFS=': '
set -- $i
IFS=' '
g="[$#]"
while :
do case $# in
0) break ;;
esac
g="$g($1)"
shift
done
"$s") ;;
esac
"$r") ;;
esac
}
'-' \
'a' \
'- -' \
'- a' \
'a -' \
'a b' \
'- - -' \
'- - a' \
'- a -' \
'- a b' \
'a - -' \
'a - b' \
'a b -' \
'a b c'
do
IFS=' '
set x $str
shift
case $# in
0) continue ;;
esac
f1=$1
esac
shift
case $# in
do
do
' ') ;;
esac
done
done
continue
;;
esac
f2=$1
esac
shift
case $# in
do
do
case ' ' in
esac
do
' ') ;;
esac
done
done
done
continue
;;
esac
f3=$1
esac
shift
case $# in
do
do
case ' ' in
esac
do
' ') continue ;;
esac
case ' ' in
esac
do
' ') ;;
x=${x#' '}
x=${x%' '}
;;
esac
done
done
done
done
continue
;;
esac
done
unset IFS
if [[ $( (print ${12345:?}) 2>&1) != *12345* ]]
then err_exit 'incorrect error message with ${12345?}'
fi
unset foobar
then err_exit 'incorrect error message with ${foobar?}'
fi
unset bar
then err_exit 'incorrect error message with ${foobar?}'
fi
{ $SHELL -c '
function foo
{
typeset SECONDS=0
sleep 1.5
print $SECONDS
}
x=$(foo)
(( x >1 && x < 2 ))
'
{
unset x
nameref x=$1
print -r -- "$x"
}
function fun
{
nameref x=$1
print -r -- "$x"
}
if [[ $1 ]]
else print -r -- "${.sh.file}"
fi
!
(
[[ $(posixfun .sh.subshell) == 2 ]] || err_exit ".sh.subshell not working for posix functions in subshells"
)
TIMEFORMAT='this is a test'
: ${.sh.version}
: ${.sh.version}
: ${.sh.version}
# unset discipline bug fix
function dave.unset
{
unset dave
}
unset dave
unset VAR
[[ $got == new ]] || err_exit "previously unset environment variable not passed to script, expected 'new', got '$got'"
[[ ! $VAR ]] || err_exit "previously unset environment variable set after script, expected '', got '$VAR'"
unset VAR
[[ $got == new ]] || err_exit "environment variable covering local variable not passed to script, expected 'new', got '$got'"
[[ $VAR == old ]] || err_exit "previously set local variable changed after script, expected 'old', got '$VAR'"
unset VAR
[[ $got == new ]] || err_exit "environment variable covering environment variable not passed to script, expected 'new', got '$got'"
[[ $VAR == old ]] || err_exit "previously set environment variable changed after script, expected 'old', got '$VAR'"
(
unset dave
function dave.append
{
dave=
}
case $? in
0) ;;
*) err_exit 'append discipline not working';;
esac
{
function .sh.foobar.get
{
}
x='a|b'
IFS='|'
set -- $x
set -x
set +x
exec 2>&3-
set -- $x
: & pid=$!
( : & )
unset foo
typeset -A foo
function foo.set
{
case ${.sh.subscript} in
then .sh.value=5
fi
;;
then foo[barrier_not_hit]=no
else foo[barrier_not_hit]=yes
fi
;;
esac
}
unset x
typeset -i x
function x.set
{
typeset sub=${.sh.subscript}
}
x[0]=0 x[1]=1 x[2]=2 x[3]=3
float seconds
unset a
function a.set
{
}
(
[[ ${.sh.subshell} == 1 ]] || err_exit '${.sh.subshell} should be 1'
(
[[ ${.sh.subshell} == 2 ]] || err_exit '${.sh.subshell} should be 2'
)
)
set -- {1..32768}
set --
unset r v x
x=foo
do nameref r=$v
unset $v
then [[ $r ]] && err_exit "unset $v failed -- expected '', got '$r'"
r=$x
[[ $r == $x ]] || err_exit "$v=$x failed -- expected '$x', got '$r'"
else err_exit "unset $v; : \$$v failed"
fi
done
x=x
do nameref r=$v
unset $v
[[ $r ]] && err_exit "unset $v failed -- expected '', got '$r'"
[[ $d ]] || err_exit "$v=$x failed -- expected locale diagnostic"
done
cd $tmp
exp='aaazzz'
[[ $got == "$exp" ]] || err_exit "cd with CDPATH after PATH change failed -- expected '$exp', got '$got'"
done
v=LC_CTYPE
unset $v
[[ -v $v ]] && err_exit "unset $v; [[ -v $v ]] failed"
eval $v=C
[[ -v $v ]] || err_exit "$v=C; [[ -v $v ]] failed"
cmd='set --nounset; unset foo; : ${!foo*}'