14887Schin######################################################################## 24887Schin# # 34887Schin# This software is part of the ast package # 4*8462SApril.Chin@Sun.COM# Copyright (c) 1982-2008 AT&T Intellectual Property # 54887Schin# and is licensed under the # 64887Schin# Common Public License, Version 1.0 # 7*8462SApril.Chin@Sun.COM# by AT&T Intellectual Property # 84887Schin# # 94887Schin# A copy of the License is available at # 104887Schin# http://www.opensource.org/licenses/cpl1.0.txt # 114887Schin# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) # 124887Schin# # 134887Schin# Information and Software Systems Research # 144887Schin# AT&T Research # 154887Schin# Florham Park NJ # 164887Schin# # 174887Schin# David Korn <dgk@research.att.com> # 184887Schin# # 194887Schin######################################################################## 204887Schinfunction err_exit 214887Schin{ 224887Schin print -u2 -n "\t" 234887Schin print -u2 -r ${Command}[$1]: "${@:2}" 244887Schin let Errors+=1 254887Schin} 264887Schinalias err_exit='err_exit $LINENO' 274887Schin 284887SchinCommand=${0##*/} 294887Schininteger Errors=0 304887Schinalias foo='print hello' 314887Schinif [[ $(foo) != hello ]] 324887Schinthen err_exit 'foo, where foo is alias for "print hello" failed' 334887Schinfi 344887Schinif [[ $(foo world) != 'hello world' ]] 354887Schinthen err_exit 'foo world, where foo is alias for "print hello" failed' 364887Schinfi 374887Schinalias foo='print hello ' 384887Schinalias bar=world 394887Schinif [[ $(foo bar) != 'hello world' ]] 404887Schinthen err_exit 'foo bar, where foo is alias for "print hello " failed' 414887Schinfi 424887Schinif [[ $(foo \bar) != 'hello bar' ]] 434887Schinthen err_exit 'foo \bar, where foo is alias for "print hello " failed' 444887Schinfi 454887Schinalias bar='foo world' 464887Schinif [[ $(bar) != 'hello world' ]] 474887Schinthen err_exit 'bar, where bar is alias for "foo world" failed' 484887Schinfi 494887Schinif [[ $(alias bar) != "bar='foo world'" ]] 504887Schinthen err_exit 'alias bar, where bar is alias for "foo world" failed' 514887Schinfi 524887Schinunalias foo || err_exit "unalias foo failed" 534887Schinalias foo 2> /dev/null && err_exit "alias for non-existent alias foo returns true" 544887Schinunset bar 554887Schinalias bar="print foo$bar" 564887Schinbar=bar 574887Schinif [[ $(bar) != foo ]] 584887Schinthen err_exit 'alias bar, where bar is alias for "print foo$bar" failed' 594887Schinfi 604887Schinunset bar 614887Schinalias bar='print hello' 624887Schinif [[ $bar != '' ]] 634887Schinthen err_exit 'alias bar cause variable bar to be set' 644887Schinfi 654887Schinalias !!=print 664887Schinif [[ $(!! hello 2>/dev/null) != hello ]] 674887Schinthen err_exit 'alias for !!=print not working' 684887Schinfi 694887Schinalias foo=echo 704887Schinif [[ $(print "$(foo bar)" ) != bar ]] 714887Schinthen err_exit 'alias in command substitution not working' 724887Schinfi 734887Schin( unalias foo) 744887Schinif [[ $(foo bar 2> /dev/null) != bar ]] 754887Schinthen err_exit 'alias not working after unalias in subshell' 764887Schinfi 774887Schinbuiltin -d rm 2> /dev/null 784887Schinif whence rm > /dev/null 794887Schinthen [[ ! $(alias -t | grep rm= ) ]] && err_exit 'tracked alias not set' 804887Schin PATH=$PATH 81*8462SApril.Chin@Sun.COM [[ $(alias -t | grep rm= ) ]] && err_exit 'tracked alias not cleared' 824887Schinfi 83*8462SApril.Chin@Sun.COMif hash -r 2>/dev/null && [[ ! $(hash) ]] 84*8462SApril.Chin@Sun.COMthen mkdir /tmp/ksh$$ || err_exit "mkdir /tmp/ksh$$ failed" 85*8462SApril.Chin@Sun.COM trap "cd /; rm -rf /tmp/ksh$$" EXIT 86*8462SApril.Chin@Sun.COM PATH=/tmp/ksh$$:/bin:/usr/bin 87*8462SApril.Chin@Sun.COM for i in foo -foo -- 88*8462SApril.Chin@Sun.COM do print ':' > /tmp/ksh$$/$i 89*8462SApril.Chin@Sun.COM chmod +x /tmp/ksh$$/$i 90*8462SApril.Chin@Sun.COM hash -r -- $i 2>/dev/null || err_exit "hash -r -- $i failed" 91*8462SApril.Chin@Sun.COM [[ $(hash) == $i=/tmp/ksh$$/$i ]] || err_exit "hash -r -- $i failed, expected $i=/tmp/ksh$$/$i, got $(hash)" 92*8462SApril.Chin@Sun.COM done 93*8462SApril.Chin@Sun.COMelse err_exit 'hash -r failed' 94*8462SApril.Chin@Sun.COMfi 95*8462SApril.Chin@Sun.COM( alias :pr=print) 2> /dev/null || err_exit 'alias beginning with : fails' 96*8462SApril.Chin@Sun.COM( alias p:r=print) 2> /dev/null || err_exit 'alias with : in name fails' 974887Schinexit $((Errors)) 98