######################################################################## # # # 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 # # http://www.opensource.org/licenses/cpl1.0.txt # # (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) # # # # Information and Software Systems Research # # AT&T Research # # Florham Park NJ # # # # David Korn # # # ######################################################################## proc err_exit { print -u2 -n "\t" print -u2 -r ${Command}[$1]: ${@:2} let Errors+=1 } alias err_exit='err_exit $LINENO' setvar Command = ${0##*/} integer Errors=0 setvar tmp = $(mktemp -dt) || do { err_exit mktemp -dt failed; exit 1; } trap "cd /; rm -rf $tmp" EXIT alias foo='print hello' if [[ $(foo) != hello ]] { err_exit 'foo, where foo is alias for "print hello" failed' } if [[ $(foo world) != 'hello world' ]] { err_exit 'foo world, where foo is alias for "print hello" failed' } alias foo='print hello ' alias bar=world if [[ $(foo bar) != 'hello world' ]] { err_exit 'foo bar, where foo is alias for "print hello " failed' } if [[ $(foo \bar) != 'hello bar' ]] { err_exit 'foo \bar, where foo is alias for "print hello " failed' } alias bar='foo world' if [[ $(bar) != 'hello world' ]] { err_exit 'bar, where bar is alias for "foo world" failed' } if [[ $(alias bar) != "bar='foo world'" ]] { err_exit 'alias bar, where bar is alias for "foo world" failed' } unalias foo || err_exit "unalias foo failed" alias foo 2> /dev/null && err_exit "alias for non-existent alias foo returns true" unset bar alias bar="print foo$bar" setvar bar = 'bar' if [[ $(bar) != foo ]] { err_exit 'alias bar, where bar is alias for "print foo$bar" failed' } unset bar alias bar='print hello' if [[ $bar != '' ]] { err_exit 'alias bar cause variable bar to be set' } alias !!=print if [[ $(!! hello 2>/dev/null) != hello ]] { err_exit 'alias for !!=print not working' } alias foo=echo if [[ $(print "$(foo bar)" ) != bar ]] { err_exit 'alias in command substitution not working' } shell { unalias foo} if [[ $(foo bar 2> /dev/null) != bar ]] { err_exit 'alias not working after unalias in subshell' } builtin -d rm 2> /dev/null if whence rm > /dev/null { [[ ! $(alias -t | grep rm= ) ]] && err_exit 'tracked alias not set' setvar PATH = "$PATH" [[ $(alias -t | grep rm= ) ]] && err_exit 'tracked alias not cleared' } if hash -r 2>/dev/null && [[ ! $(hash) ]] { setvar PATH = "$tmp:/bin:/usr/bin" for i in [foo -foo --] { print ':' > $tmp/$i chmod +x $tmp/$i hash -r -- $i 2>/dev/null || err_exit "hash -r -- $i failed" [[ $(hash) == $i=$tmp/$i ]] || err_exit "hash -r -- $i failed, expected $i=$tmp/$i, got $(hash)" } } else { err_exit 'hash -r failed' } shell { alias :pr=print} 2> /dev/null || err_exit 'alias beginning with : fails' shell { alias p:r=print} 2> /dev/null || err_exit 'alias with : in name fails' exit $((Errors))