da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin########################################################################
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# This software is part of the ast package #
3e14f97f673e8a630f076077de35afdd43dc1587Roger A. Faulkner# Copyright (c) 1982-2010 AT&T Intellectual Property #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# and is licensed under the #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Common Public License, Version 1.0 #
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# by AT&T Intellectual Property #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# A copy of the License is available at #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Information and Software Systems Research #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# AT&T Research #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# Florham Park NJ #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# David Korn <dgk@research.att.com> #
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin########################################################################
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainztmp=$(mktemp -dt) || { err_exit mktemp -dt failed; exit 1; }
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ -s out1 ]] && err_exit 'type should not write on stdout for not found case'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ -s out2 ]] || err_exit 'type should write on stderr for not found case'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ $( foobar) == foobar1 ]] || err_exit 'foobar should output foobar1'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ $(foobar) == foobar2 ]] || err_exit 'foobar should output foobar2'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ $(foobar) == foobar1 ]] || err_exit 'foobar should output foobar1 again'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ ${ foobar;} == foobar2 ]] || err_exit 'foobar should output foobar2 with ${}'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ ${ dir2;} == dir2 ]] || err_exit 'should be dir2'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ ${ dir1;} == dir1 ]] 2> /dev/null && err_exit 'should not be be dir1'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ ${ foobar;} == foobar1 ]] || err_exit 'foobar should output foobar1 with ${}'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ ${ dir1;} == dir1 ]] || err_exit 'should be dir1'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ ${ dir2;} == dir2 ]] 2> /dev/null && err_exit 'should not be be dir2'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ ${ foobar;} == foobar2 ]] || err_exit 'foobar should output foobar2 with ${} again'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $($SHELL -c 'print -r -- "$PATH"') == "$PATH" ]] || err_exit 'export PATH lost in subshell'
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz print print ok > $tmp/ok
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz /bin/chmod 755 $tmp/ok
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin function a
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz typeset -x PATH=$tmp
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin unset PATH
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[[ $($SHELL ./bug1 2>/dev/null) == ok ]] || err_exit "PATH in function not working"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin($SHELL ./bug1) 2> /dev/null || err_exit "path_delete bug"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit "$SHELL name not executing version in current directory"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinif [[ $(ls -d . 2>/dev/null) == . && $(PATH=/bin:/usr/bin:$PATH ls -d . 2>/dev/null) != . ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit 'PATH export in command substitution not working'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# get rid of leading and trailing : and trailing :.
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinfor PATH in $path :$path $path: .:$path $path: $path:. $PWD::$path $PWD:.:$path $path:$PWD $path:.:$PWD
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# print path=$PATH $(whence date)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin# print path=$PATH $(whence "$cmd")
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if [[ ! -x noexec ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin then noexec > /dev/null 2>&1
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin else exit 126
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $status == 126 ]] || err_exit "exit status of non-executable is $status -- 126 expected"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz got=$($SHELL -c "unset FPATH; PATH=/dev/null; $cmd" 2>&1)
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz [[ $got == $exp ]] && err_exit "$cmd as last command should not find ./$cmd with PATH=/dev/null"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz got=$($SHELL -c "unset FPATH; PATH=/dev/null; $cmd" 2>&1)
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz [[ $got == $exp ]] && err_exit "$cmd should not find ./$cmd with PATH=/dev/null"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz got=$(unset FPATH; PATH=/dev/null; whence ./$cmd)
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz [[ $got == $exp ]] || err_exit "whence $cmd should find ./$cmd with PATH=/dev/null"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz got=$(unset FPATH; PATH=/dev/null; whence $PWD/$cmd)
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz [[ $got == $exp ]] || err_exit "whence \$PWD/$cmd should find ./$cmd with PATH=/dev/null"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzgot=$($SHELL -c "unset FPATH; PATH=/dev/null; whence ./notfound" 2>&1)
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[[ $got == $exp ]] || err_exit "whence ./$cmd failed -- expected '$exp', got '$got'"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzgot=$($SHELL -c "unset FPATH; PATH=/dev/null; whence $PWD/notfound" 2>&1)
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[[ $got == $exp ]] || err_exit "whence \$PWD/$cmd failed -- expected '$exp', got '$got'"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz [[ $got == $exp ]] && err_exit "$cmd as last command should not find ./$cmd with PATH=/dev/null"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz [[ $got == $exp ]] && err_exit "$cmd should not find ./$cmd with PATH=/dev/null"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz [[ $got == $exp ]] || err_exit "whence ./$cmd should find ./$cmd with PATH=/dev/null"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz [[ $got == $exp ]] || err_exit "whence \$PWD/$cmd should find ./$cmd with PATH=/dev/null"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[[ $got == $exp ]] || err_exit "whence ./$cmd failed -- expected '$exp', got '$got'"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainz[[ $got == $exp ]] || err_exit "whence \$PWD/$cmd failed -- expected '$exp', got '$got'"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinthen err_exit '(PATH=$PWD/bin foo) does not find $PWD/bin/foo'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin if [[ $(whence rm) ]]
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinx=$(whence rm)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chiny=$(whence rm)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $x != "$y" ]] && err_exit 'PATH not restored after command substitution'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinwhence getconf > /dev/null && err_exit 'getconf should not be found'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinx=$(whence ls)
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $(whence ls) == "$x" ]] || err_exit 'PATH search bug when .:$PWD in path'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $(whence ls) == "$x" ]] || err_exit 'PATH search bug when :$PWD:. in path'
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chincd "${x%/ls}"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $(whence ls) == /* ]] || err_exit 'whence not generating absolute pathname'
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzstatus=$($SHELL -c $'trap \'print $?\' EXIT;/xxx/a/b/c/d/e 2> /dev/null')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $status == 127 ]] || err_exit "not found command exit status $status -- expected 127"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatus=$($SHELL -c $'trap \'print $?\' EXIT;/dev/null 2> /dev/null')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $status == 126 ]] || err_exit "non executable command exit status $status -- expected 126"
34f9b3eef6fdadbda0a846aa4d68691ac40eace5Roland Mainzstatus=$($SHELL -c $'trap \'print $?\' ERR;/xxx/a/b/c/d/e 2> /dev/null')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $status == 127 ]] || err_exit "not found command with ERR trap exit status $status -- expected 127"
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chinstatus=$($SHELL -c $'trap \'print $?\' ERR;/dev/null 2> /dev/null')
da2e3ebdc1edfbc5028edf1354e7dd2fa69a7968chin[[ $status == 126 ]] || err_exit "non executable command ERR trap exit status $status -- expected 126"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin# universe via PATH
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chingetconf UNIVERSE - att # override sticky default 'UNIVERSE = foo'
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ $(PATH=/usr/ucb/bin:/usr/bin echo -n ucb) == 'ucb' ]] || err_exit "ucb universe echo ignores -n option"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ $(PATH=/usr/xpg/bin:/usr/bin echo -n att) == '-n att' ]] || err_exit "att universe echo does not ignore -n option"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$got" == "$exp" ]] || err_exit "unreadable empty script should fail -- expected $exp, got $got"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$got" == "$exp" ]] || err_exit "command of unreadable empty script should fail -- expected $exp, got $got"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$(:; $scr; print $?)" == "$exp" ]] 2>/dev/null || err_exit "unreadable empty script in [[ ... ]] should fail -- expected $exp"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$(:; command $scr; print $?)" == "$exp" ]] 2>/dev/null || err_exit "command unreadable empty script in [[ ... ]] should fail -- expected $exp"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$got" == "$exp" ]] || err_exit "\$SHELL -c of unreadable empty script should fail -- expected $exp, got" $got
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chingot=$($SHELL -c "command $scr; print \$?" 2>/dev/null)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$got" == "$exp" ]] || err_exit "\$SHELL -c of command of unreadable empty script should fail -- expected $exp, got" $got
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$got" == "$exp" ]] || err_exit "unreadable non-empty script should fail -- expected $exp, got $got"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$got" == "$exp" ]] || err_exit "command of unreadable non-empty script should fail -- expected $exp, got $got"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$(:; $scr; print $?)" == "$exp" ]] 2>/dev/null || err_exit "unreadable non-empty script in [[ ... ]] should fail -- expected $exp"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$(:; command $scr; print $?)" == "$exp" ]] 2>/dev/null || err_exit "command unreadable non-empty script in [[ ... ]] should fail -- expected $exp"
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$got" == "$exp" ]] || err_exit "\$SHELL -c of unreadable non-empty script should fail -- expected $exp, got" $got
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chingot=$($SHELL -c "command $scr; print \$?" 2>/dev/null)
7c2fbfb345896881c631598ee3852ce9ce33fb07April Chin[[ "$got" == "$exp" ]] || err_exit "\$SHELL -c of command of unreadable non-empty script should fail -- expected $exp, got" $got