########################################################################
# #
# 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
# test shell builtin commands
builtin getconf
set -- - foobar
set -- -x foobar
OPTIND=1
getopts :r:s var -r
then err_exit "'getopts :r:s var -r' not working"
fi
OPTIND=1
getopts :d#u OPT -d 16177
fi
OPTIND=1
while getopts 'ab' option -a -b
done
USAGE=$'[-][S:server?Operate on the specified \asubservice\a:]:[subservice:=pmserver]
{
[p:pmserver]
[r:repserver]
[11:notifyd]
}'
while (( $# > 1 ))
do OPTIND=1
shift 2
done
read <<!
!
print x:y | IFS=: read a b
if [[ $a != x ]]
then err_exit "IFS=: read ... not working"
fi
read <<!
hello \
!
read -d x <<!
!
read <<\!
hello \
world \
!
print "one\ntwo" | { read line
read line
}
read <<\!
\
a\
\
\
b
!
then err_exit "read multiple continuation failed"
fi
then err_exit "read from pipeline failed"
fi
if [[ $line != "" ]]
fi
if [[ $(print -R -) != - ]]
then err_exit "print -R not working correctly"
fi
if [[ $(print -- -) != - ]]
then err_exit "print -- not working correctly"
fi
then err_exit "%n format of printf not working"
fi
x=$0
if [[ $(eval 'print $0') != $x ]]
then err_exit '$0 not correct for eval'
fi
unset x
readonly x
set -- $(readonly)
if [[ " $@ " != *" x "* ]]
then err_exit 'unset readonly variables are not displayed'
fi
do print $i
continue 10
done
) != $'foo\nbar' ]]
then err_exit 'continue breaks out of loop'
fi
print $i
done
) != foo ]]
fi
done
if [[ $(print -f "%b" "\a\n\v\b\r\f\E\03\\oo") != $'\a\n\v\b\r\f\E\03\\oo' ]]
then err_exit 'print -f "%b" not working'
fi
if [[ $(print -f "%P" "[^x].*b\$") != '*[!x]*b' ]]
then err_exit 'print -f "%P" not working'
fi
if [[ $(print -f "%(pattern)q" "[^x].*b\$") != '*[!x]*b' ]]
then err_exit 'print -f "%(pattern)q" not working'
fi
then err_exit 'break labels not working'
fi
if [[ $(command -v if) != if ]]
then err_exit 'command -v not working'
fi
read -r var <<\!
!
if [[ $var != "" ]]
then err_exit "read -r of blank line not working"
fi
trap 'print TERM' TERM
got=$(trap)
exp='print TERM'
[[ $($SHELL -c 'trap "print ok" SIGTERM; kill -s SIGTERM $$' 2> /dev/null) == ok ]] || err_exit 'SIGTERM not recognized'
[[ $($SHELL -c 'trap "print ok" sigterm; kill -s sigterm $$' 2> /dev/null) == ok ]] || err_exit 'SIGTERM not recognized'
[[ $($SHELL -c '( trap "" TERM);kill $$;print bad' == bad) ]] 2> /dev/null && err_exit 'trap ignored in subshell causes it to be ignored by parent'
n=123
typeset -A base
for i in d i o u x X
then err_exit "printf %$i not working"
fi
done
then err_exit 'trap on EXIT not working'
fi
then err_exit 'trap on EXIT not being cleared'
fi
if [[ $(LC_MESSAGES=C type test) != 'test is a shell builtin' ]]
then err_exit 'whence -v test not a builtin'
fi
builtin -d test
if [[ $(type test) == *builtin* ]]
then err_exit 'whence -v test after builtin -d incorrect'
fi
fi
then err_exit 'printf \0 not working'
fi
then err_exit 'printf %bx%s\n not working'
fi
then err_exit 'printf %10.%s\n not working'
fi
float x2=.0000625
then err_exit 'printf "%10.5E" not normalizing correctly'
fi
x2=.000000001
then err_exit 'printf "%g" not working correctly'
fi
#FIXME#($SHELL read -s foobar <<\!
#FIXME#testing
#FIXME#!
then err_exit 'printf is not processing formats beginning with + correctly'
fi
then err_exit "printf not exiting non-zero with conversion errors"
fi
then err_exit 'trap builtin terminating after --version'
fi
then err_exit 'set builtin terminating after --veresion'
fi
unset -f foobar
function foobar
{
print 'hello world'
}
OPTIND=1
then err_exit '\f...\f not working in getopts usage strings'
fi
then err_exit 'printf %H not working'
fi
then err_exit 'printf %(html)q not working'
fi
then err_exit 'printf %(url)q not working'
fi
then err_exit 'printf %T not working'
fi
if [[ $(printf '%(ere)q %(ere)q %(ere)q %(ere)q\n' 'a.b' '*.c' '^' '!(*.*)') != '^a\.b$ \.c$ ^\^$ ^(.*\..*)!$' ]]
then err_exit 'printf %(ere)q not working'
fi
then err_exit "printf '%..:c' not working"
fi
then err_exit "printf '%..*c' not working"
fi
then err_exit "printf '%..:s' not working"
fi
then err_exit "printf '%..*s' not working"
fi
# we won't get hit by the one second boundary twice, right?
err_exit 'printf "%T" now'
{
read line
}
print $'line1\nline2' | behead
then err_exit "read reading ahead on a pipe"
fi
read -n1 y <<!
!
exp=a
if [[ $y != $exp ]]
fi
then err_exit 'read of incomplete line not working correctly'
fi
set -f
set -- *
if [[ $1 != '*' ]]
then err_exit 'set -f not working'
fi
false &
pid1=$!
pid2=$(
wait $pid1
print $!
)
wait $pid1
wait $pid2
env=
for v in ${v//,/ }
do v=${v#*:}
v=${v%%:*}
done
then err_exit '"name=value exec -c ..." not working'
fi
then err_exit 'printf %2$s %1$s not working'
fi
set -- \
while (( $# >= 3 ))
shift 3
ret=$?
else [[ $err ]] && err_exit "$err: printf $fmt $arg failed, error message not expected -- got '$err'"
fi
done
done
((n=0))
for ((i=1; i<=n; i++))
do set -- ${ARGV[$i]}
OPTIND=0
do :
done
fi
done
a|c) [[ $OPTARG ]] && err_exit "getopts $options \$OPTARG for flag $opt failed, expected \"\", got \"$OPTARG\"" ;;
b) [[ $OPTARG == $optarg ]] || err_exit "getopts $options \$OPTARG failed -- \"$optarg\" expected, got \"$OPTARG\"" ;;
esac
done
[[ $($SHELL 2> /dev/null -c 'readonly foo; getopts a: foo -a blah; echo foo') == foo ]] || err_exit 'getopts with readonly variable causes script to abort'
unset a
!
exp=d
read -n3 a <<!
!
#(print -n a;sleep 1; print -n bcde) | { read -N3 a; read -N1 b;}
#[[ $a == $exp ]] || err_exit "read -N3 from pipe failed -- expected '$exp', got '$a'"
#exp=d
#[[ $b == $exp ]] || err_exit "read -N1 from pipe failed -- expected '$exp', got '$b'"
#(print -n a;sleep 1; print -n bcde) | read -n3 a
#exp=a
#[[ $a == $exp ]] || err_exit "read -n3 from pipe failed -- expected '$exp', got '$a'"
# {
# read -u5 -n3 -t2 a || err_exit 'read -n3 from fifo timedout'
# read -u5 -n1 -t2 b || err_exit 'read -n1 from fifo timedout'
# exp=a
# [[ $a == $exp ]] || err_exit "read -n3 from fifo failed -- expected '$exp', got '$a'"
# {
# read -u5 -N3 -t2 a || err_exit 'read -N3 from fifo timed out'
# read -u5 -N1 -t2 b || err_exit 'read -N1 from fifo timedout'
# exp=abc
# [[ $a == $exp ]] || err_exit "read -N3 from fifo failed -- expected '$exp', got '$a'"
# exp=d
# [[ $b == $exp ]] || err_exit "read -N1 from fifo failed -- expected '$exp', got '$b'"
#fi
function longline
{
integer i
for((i=0; i < $1; i++))
do print argument$i
done
}
# test command -x option
then for i in $(command command -x ${SHELL:-ksh} -c 'print $#;[[ $1 != argument0 ]]' count $(longline $n) 2> /dev/null)
done
command -p command -x ${SHELL:-ksh} -c 'print $#;[[ $1 == argument0 ]]' count $(longline $n) > /dev/null 2>&1
fi
# test command -x option with extra arguments
then for i in $(command command -x ${SHELL:-ksh} -c 'print $#;[[ $1 != argument0 ]]' count $(longline $n) one two three) #2> /dev/null)
done
command -p command -x ${SHELL:-ksh} -c 'print $#;[[ $1 == argument0 ]]' count $(longline $n) > /dev/null 2>&1
fi
# test for debug trap
[[ $(typeset -i i=0
while (( i <2))
do (( i++))
done
fi
$SHELL -c 'sleep $(printf "%a" .95)' 2> /dev/null || err_exit "sleep doesn't except %a format constants"
print $'\nprint -r -- "${.sh.file} ${LINENO} ${.sh.lineno}"' > $tmpfile
print -r -- "'xxx" > $tmpfile
[[ $($SHELL -c ". $tmpfile"$'\n print ok' 2> /dev/null) == ok ]] || err_exit 'syntax error in dot command affects next command'
exitval=$?
exec 2>&3-
(( sec > (del - 1) )) || err_exit "ALRM signal causes sleep to terminate prematurely -- expected 3 sec, got $sec"
typeset -r z=3
y=5
done
a=()
do unset $i || print -u2 "err_exit unset $i should not fail"
done
[[ $($SHELL -c 'y=3; unset 123 y;print $?$y') == 1 ]] 2> /dev/null || err_exit 'y is not getting unset with unset 123 y'
[[ $($SHELL -c 'trap foo TERM; (trap;(trap) )') == 'trap -- foo TERM' ]] || err_exit 'traps not getting reset when subshell is last process'
t=$(ulimit -t)
[[ $($SHELL -c 'ulimit -v 15000 2>/dev/null; ulimit -t') == "$t" ]] || err_exit 'ulimit -v changes ulimit -t'
[[ $($SHELL 2> /dev/null -c 'cd "";print hi') != hi ]] && err_exit 'cd "" should not terminate script'
builtin cat
cmp -s <(print -- "$($bincat<( $bincat $out ) )") <(print -- "$(cat <( cat $out ) )") || err_exit "builtin cat differs from $bincat"
[[ $($SHELL -c '{ printf %R "["; print ok;}' 2> /dev/null) == ok ]] || err_exit $'\'printf %R "["\' causes shell to abort'
v=$( $SHELL -c $'
trap \'print "usr1"\' USR1
trap exit USR2
sleep 1 && {
kill -USR1 $$ && sleep 1
} &
sleep 2 | read
echo done
pwd=$PWD
cd ../tmpdir1
cd "$pwd"
cd .. 2> /dev/null || err_exit 'cannot change directory to .. after current directory has been renamed'
cd "$tmp"
pwd=$PWD
cd ../.. 2> /dev/null || err_exit 'cannot change directory to ../.. after current directory has been renamed'
cd "$tmp"
cd /etc
cd ..
cd /etc
cd ../..
cd /etc
cd .././..
cd ../..
cd ..
cd "$tmp"
then (
> real_t1
(
cd ..
)
)
fi
cd "$tmp"
false
exit
!
then [[ $(kill -l HUP) == "$(kill -L HUP)" ]] || err_exit 'kill -l and kill -L are not the same when given a signal name'
[[ $(kill -l 9) == "$(kill -L 9)" ]] || err_exit 'kill -l and kill -L are not the same when given a signal number'
fi
unset ENV
read baz <<< 'foo\\\\bar'
: ~root