########################################################################
# #
# This software is part of the ast package #
# Copyright (c) 1982-2012 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> #
# #
########################################################################
function err_exit
{
print -u2 -n "\t"
let Errors+=1
}
alias err_exit='err_exit $LINENO'
integer Errors=0
done
i=i+5
if ((i != 27))
fi
fi
if [[ $u != UPPERCASE ]]
fi
if [[ $l != lowercase ]]
fi
if [[ $n != lowercase ]]
fi
if [[ t=tagged != $(typeset -t) ]]
fi
if [[ t != $(typeset +t) ]]
fi
if [[ $Z5 != 00123 ]]
fi
if [[ $RZ5 != 00026 ]]
fi
L=12345
if [[ $L != 123 ]]
fi
if [[ $L5 != "def " ]]
fi
fi
fi
if [[ $R5 != " def" ]]
fi
fi
fi
$SHELL -c 'print \$foo'
!
)
if [[ $x != bar ]]
then err_exit 'environment variables require re-export'
fi
if [[ $? == 0 ]]
fi
a=b
readonly $a=foo
if [[ $b != foo ]]
then err_exit 'readonly $a=b not working'
fi
then err_exit 'export not working'
fi
picture=(
size=(typeset -E x=2.5)
)
if [[ "${string}" != *'size=( typeset -E'* ]]
then err_exit 'print of compound exponential variable not working'
fi
sz=(typeset -E y=2.2)
if [[ "${sz}" == *'typeset -E -F'* ]]
then err_exit 'print of exponential shows both -E and -F attributes'
fi
typeset -Z2 m
then err_exit 'attributes not cleared for script execution'
fi
typeset -Z LAST=00
unset -f foo
function foo
{
if [[ $1 ]]
then LAST=$1
fi
}
foo 1
if (( ${#LAST} != 2 ))
then err_exit 'LAST!=2'
fi
if (( ${#LAST} != 2 ))
then err_exit 'LAST!=2'
fi
set -a
unset foo
then err_exit 'all export not working'
fi
unset foo
read foo <<!
!
then err_exit 'all export not working with read'
fi
then err_exit 'typeset without arguments outputs names without attributes'
fi
unset a z q x
if (( 'a' == 97 ))
then b1=aGVsbG8gd29ybGQ=
else b1=iIWTk5ZAppaZk4Q=
fi
z=$b1
typeset -b x=$b1
typeset -b q=$x$x
x+=$b1
{
} << !
!
then [[ $(env '!=1' $SHELL -c 'echo ok' 2>/dev/null) == ok ]] || err_exit 'malformed environment terminates shell'
fi
unset var
typeset -b var
unset var
else err_exit 'typeset -usi cannot be used for unsigned short'
fi
[[ $($SHELL -c 'unset foo;typeset -Z2 foo; print ${foo:-3}' 2> /dev/null) == 3 ]] || err_exit '${foo:-3} not 3 when typeset -Z2 field undefined'
[[ $($SHELL -c 'unset foo;typeset -Z2 foo; print ${foo:=3}' 2> /dev/null) == 03 ]] || err_exit '${foo:=-3} not 3 when typeset -Z2 foo undefined'
unset -f fun
function fun
{
}
[[ $($SHELL -c 'typeset -r IFS=;print -r $(pwd)' 2> /dev/null) == "$(pwd)" ]] || err_exit 'readonly IFS causes command substitution to fail'
fred[66]=88
unset x y z
y=03
unset x z
set +a
unset z
x='typeset -i z=45'
eval "$x"
unset z
x='typeset -a z=(a b c)'
eval "$x"
unset z
x='typeset -C z=(
foo=bar
xxx=bam
)'
eval "$x"
x=${x//$'\t'}
x=${x//$'(\n'/'('}
x=${x//$'\n'/';'}
x=${x%';)'}')'
unset z
x='typeset -A z=([bar]=bam [xyz]=bar)'
eval "$x"
unset z
x='typeset -n z=foo'
eval "$x"
typeset +n z
unset foo z
typeset -T Pt_t=(
float x=1 y=2
)
Pt_t z
x=${z//$'\t'}
x=${x//$'(\n'/'('}
x=${x//$'\n'/';'}
x=${x%';)'}')'
unset z
function foo
{
typeset -p bar
}
unset foo
[[ $(typeset -p foo) == 'typeset -L 5 foo' ]] || err_exit 'typeset -p not working for variables with attributes but without a value'
{ $SHELL <<- EOF
typeset -L3 foo=aaa
typeset -L6 foo=bbbbbb
[[ \$foo == bbbbbb ]]
EOF
{ $SHELL <<- EOF
typeset -R3 foo=aaa
typeset -R6 foo=bbbbbb
[[ \$foo == bbbbbb ]]
EOF
expected='YWJjZGVmZ2hpag=='
unset foo
read foo <<< 'abcdefghijklmnop'
unset foo
unset foo
typeset -b -A foo
[[ ${foo[4]} == "$expected" ]] || err_exit 'read -N10 foo, where foo is "typeset -b -A" foo not working'
unset foo
typeset -b -a foo
[[ ${foo[4]} == "$expected" ]] || err_exit 'read -N10 foo, where foo is "typeset -b -a" foo not working'
[[ $(printf %B foo[4]) == abcdefghij ]] || err_exit 'printf %B for binary associative array element not working'
[[ $(printf %B foo[4]) == abcdefghij ]] || err_exit 'printf %B for binary indexed array element not working'
unset foo
{
# check env var changes against a builtin that uses the env var
SEC=1234252800
EDT=03
PDT=00
set -- \
while (( $# >= 4 ))
do exp=$1
[[ $got == $exp ]] || err_exit "[ '$2' '$3' '$4' ] env sequence failed -- expected '$exp', got '$got'"
shift 4
done
}
unset v
unset x
unset x
{
[[ $x == 5 ]] || err_exit 'integer -s not working'
unset got
typeset -u got
exp=100
unset s
unset s
expected=$'(\n\t[0]=WORLD\n\t[1]=HELLO\n\t[2]=CHICKEN\n)'
[[ $(print -v s) == "$expected" ]] || err_exit 'typeset -u for associative array does not display correctly'
unset s
then [[ $(typeset +p s) == 'typeset -M totitle s' ]] || err_exit 'typeset -M totitle does not display correctly with typeset -p'
fi
compound -a a1
for ((i=1 ; i < 100 ; i++ ))
done
typeset -u PS1='hello --- '
typeset -b x
for (( i=0 ; i < ${#a[@]} ; i++ ))
do x+="${a[i]}"
done
[[ $(printf "%B" x) == hello ]] || err_exit "append for typeset -b not working: got '$(printf "%B" x)' should get hello"
(
$SHELL -c 'typeset v=foo; [[ $(typeset -p v[0]) == v=foo ]]'
unset x
expected='typeset -a x=(a\=3 b\=4)'
typeset -a x=( a=3 b=4)
[[ $(typeset -p x) == "$expected" ]] || err_exit 'assignment elements in typeset -a assignment not working'
unset z
z='typeset -a q=(a b c)'
$SHELL -c "$z; [[ \$(typeset -pa) == '$z' ]]" || err_exit 'typeset -pa does not list only index arrays'
z='typeset -C z=(foo=bar)'
$SHELL -c "$z; [[ \$(typeset -pC) == '$z' ]]" || err_exit 'typeset -pC does not list only compound variables'
unset y
z='typeset -A y=([a]=foo)'
$SHELL -c "$z; [[ \$(typeset -pA) == '$z' ]]" || err_exit 'typeset -pA does not list only associative arrays'
$SHELL 2> /dev/null -c 'typeset -C arr=( aa bb cc dd )' && err_exit 'invalid compound variable assignment not reported'
unset x
typeset -l x=
unset x
typeset -L4 x=$'\001abcdef'
[[ ${#x} == 5 ]] || err_exit "width of character '\01' is not zero"
unset x
typeset -L x=-1
unset val
typeset -i val=10#0-3
typeset -Z val=0-1
unset x
typeset -L -Z x=foo
[[ $(typeset -p x) == 'typeset -Z 3 -L 3 x=foo' ]] || err_exit '-LRZ without [n] not defaulting to width of variable'
unset foo
export foo