14887Schin######################################################################## 24887Schin# # 34887Schin# This software is part of the ast package # 4*12068SRoger.Faulkner@Oracle.COM# Copyright (c) 1982-2010 AT&T Intellectual Property # 54887Schin# and is licensed under the # 64887Schin# Common Public License, Version 1.0 # 78462SApril.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 3010898Sroland.mainz@nrubsig.org 3110898Sroland.mainz@nrubsig.orgtmp=$(mktemp -dt) || { err_exit mktemp -dt failed; exit 1; } 3210898Sroland.mainz@nrubsig.orgtrap "cd /; rm -rf $tmp" EXIT 3310898Sroland.mainz@nrubsig.org 344887Schinalias foo='print hello' 354887Schinif [[ $(foo) != hello ]] 364887Schinthen err_exit 'foo, where foo is alias for "print hello" failed' 374887Schinfi 384887Schinif [[ $(foo world) != 'hello world' ]] 394887Schinthen err_exit 'foo world, where foo is alias for "print hello" failed' 404887Schinfi 414887Schinalias foo='print hello ' 424887Schinalias bar=world 434887Schinif [[ $(foo bar) != 'hello world' ]] 444887Schinthen err_exit 'foo bar, where foo is alias for "print hello " failed' 454887Schinfi 464887Schinif [[ $(foo \bar) != 'hello bar' ]] 474887Schinthen err_exit 'foo \bar, where foo is alias for "print hello " failed' 484887Schinfi 494887Schinalias bar='foo world' 504887Schinif [[ $(bar) != 'hello world' ]] 514887Schinthen err_exit 'bar, where bar is alias for "foo world" failed' 524887Schinfi 534887Schinif [[ $(alias bar) != "bar='foo world'" ]] 544887Schinthen err_exit 'alias bar, where bar is alias for "foo world" failed' 554887Schinfi 564887Schinunalias foo || err_exit "unalias foo failed" 574887Schinalias foo 2> /dev/null && err_exit "alias for non-existent alias foo returns true" 584887Schinunset bar 594887Schinalias bar="print foo$bar" 604887Schinbar=bar 614887Schinif [[ $(bar) != foo ]] 624887Schinthen err_exit 'alias bar, where bar is alias for "print foo$bar" failed' 634887Schinfi 644887Schinunset bar 654887Schinalias bar='print hello' 664887Schinif [[ $bar != '' ]] 674887Schinthen err_exit 'alias bar cause variable bar to be set' 684887Schinfi 694887Schinalias !!=print 704887Schinif [[ $(!! hello 2>/dev/null) != hello ]] 714887Schinthen err_exit 'alias for !!=print not working' 724887Schinfi 7310898Sroland.mainz@nrubsig.orgalias foo=echo 744887Schinif [[ $(print "$(foo bar)" ) != bar ]] 754887Schinthen err_exit 'alias in command substitution not working' 764887Schinfi 774887Schin( unalias foo) 784887Schinif [[ $(foo bar 2> /dev/null) != bar ]] 794887Schinthen err_exit 'alias not working after unalias in subshell' 804887Schinfi 814887Schinbuiltin -d rm 2> /dev/null 824887Schinif whence rm > /dev/null 834887Schinthen [[ ! $(alias -t | grep rm= ) ]] && err_exit 'tracked alias not set' 844887Schin PATH=$PATH 858462SApril.Chin@Sun.COM [[ $(alias -t | grep rm= ) ]] && err_exit 'tracked alias not cleared' 864887Schinfi 878462SApril.Chin@Sun.COMif hash -r 2>/dev/null && [[ ! $(hash) ]] 8810898Sroland.mainz@nrubsig.orgthen PATH=$tmp:/bin:/usr/bin 898462SApril.Chin@Sun.COM for i in foo -foo -- 9010898Sroland.mainz@nrubsig.org do print ':' > $tmp/$i 9110898Sroland.mainz@nrubsig.org chmod +x $tmp/$i 928462SApril.Chin@Sun.COM hash -r -- $i 2>/dev/null || err_exit "hash -r -- $i failed" 9310898Sroland.mainz@nrubsig.org [[ $(hash) == $i=$tmp/$i ]] || err_exit "hash -r -- $i failed, expected $i=$tmp/$i, got $(hash)" 948462SApril.Chin@Sun.COM done 958462SApril.Chin@Sun.COMelse err_exit 'hash -r failed' 968462SApril.Chin@Sun.COMfi 978462SApril.Chin@Sun.COM( alias :pr=print) 2> /dev/null || err_exit 'alias beginning with : fails' 988462SApril.Chin@Sun.COM( alias p:r=print) 2> /dev/null || err_exit 'alias with : in name fails' 994887Schinexit $((Errors)) 100