1######################################################################## 2# # 3# This software is part of the ast package # 4# Copyright (c) 1982-2011 AT&T Intellectual Property # 5# and is licensed under the # 6# Eclipse Public License, Version 1.0 # 7# by AT&T Intellectual Property # 8# # 9# A copy of the License is available at # 10# http://www.eclipse.org/org/documents/epl-v10.html # 11# (with md5 checksum b35adb5213ca9657e911e9befb180842) # 12# # 13# Information and Software Systems Research # 14# AT&T Research # 15# Florham Park NJ # 16# # 17# David Korn <dgk@research.att.com> # 18# # 19######################################################################## 20function err_exit 21{ 22 print -u2 -n "\t" 23 print -u2 -r ${Command}[$1]: "${@:2}" 24 let Errors+=1 25} 26alias err_exit='err_exit $LINENO' 27 28Command=${0##*/} 29integer Errors=0 30set -o noglob 31if [[ 'hi there' != "hi there" ]] 32then err_exit "single quotes not the same as double quotes" 33fi 34x='hi there' 35if [[ $x != 'hi there' ]] 36then err_exit "$x not the same as 'hi there'" 37fi 38if [[ $x != "hi there" ]] 39then err_exit "$x not the same as \"hi there \"" 40fi 41if [[ \a\b\c\*\|\"\ \\ != 'abc*|" \' ]] 42then err_exit " \\ differs from '' " 43fi 44if [[ "ab\'\"\$(" != 'ab\'\''"$(' ]] 45then err_exit " \"\" differs from '' " 46fi 47if [[ $(print -r - 'abc*|" \') != 'abc*|" \' ]] 48then err_exit "\$(print -r - '') differs from ''" 49fi 50if [[ $(print -r - "abc*|\" \\") != 'abc*|" \' ]] 51then err_exit "\$(print -r - '') differs from ''" 52fi 53if [[ "$(print -r - 'abc*|" \')" != 'abc*|" \' ]] 54then err_exit "\"\$(print -r - '')\" differs from ''" 55fi 56if [[ "$(print -r - "abc*|\" \\")" != 'abc*|" \' ]] 57then err_exit "\"\$(print -r - "")\" differs from ''" 58fi 59if [[ $(print -r - "$(print -r - 'abc*|" \')") != 'abc*|" \' ]] 60then err_exit "nested \$(print -r - '') differs from ''" 61fi 62if [[ "$(print -r - $(print -r - 'abc*|" \'))" != 'abc*|" \' ]] 63then err_exit "\"nested \$(print -r - '')\" differs from ''" 64fi 65if [[ $(print -r - "$(print -r - 'abc*|" \')") != 'abc*|" \' ]] 66then err_exit "nested \"\$(print -r - '')\" differs from ''" 67fi 68unset x 69if [[ ${x-$(print -r - "abc*|\" \\")} != 'abc*|" \' ]] 70then err_exit "\${x-\$(print -r - '')} differs from ''" 71fi 72if [[ ${x-$(print -r - "a}c*|\" \\")} != 'a}c*|" \' ]] 73then err_exit "\${x-\$(print -r - '}')} differs from ''" 74fi 75x=$((echo foo)|(cat)) 76if [[ $x != foo ]] 77then err_exit "((cmd)|(cmd)) failed" 78fi 79x=$(print -r -- "\"$HOME\"") 80if [[ $x != '"'$HOME'"' ]] 81then err_exit "nested double quotes failed" 82fi 83unset z 84: ${z="a{b}c"} 85if [[ $z != 'a{b}c' ]] 86then err_exit '${z="a{b}c"} not correct' 87fi 88unset z 89: "${z="a{b}c"}" 90if [[ $z != 'a{b}c' ]] 91then err_exit '"${z="a{b}c"}" not correct' 92fi 93if [[ $(print -r -- "a\*b") != 'a\*b' ]] 94then err_exit '$(print -r -- "a\*b") differs from a\*b' 95fi 96unset x 97if [[ $(print -r -- "a\*b$x") != 'a\*b' ]] 98then err_exit '$(print -r -- "a\*b$x") differs from a\*b' 99fi 100x=hello 101set -- ${x+foo bar bam} 102if (( $# !=3 )) 103then err_exit '${x+foo bar bam} does not yield three arguments' 104fi 105set -- ${x+foo "bar bam"} 106if (( $# !=2 )) 107then err_exit '${x+foo "bar bam"} does not yield two arguments' 108fi 109set -- ${x+foo 'bar bam'} 110if (( $# !=2 )) 111then err_exit '${x+foo '\''bar bam'\''} does not yield two arguments' 112fi 113set -- ${x+foo $x bam} 114if (( $# !=3 )) 115then err_exit '${x+foo $x bam} does not yield three arguments' 116fi 117set -- ${x+foo "$x" bam} 118if (( $# !=3 )) 119then err_exit '${x+foo "$x" bam} does not yield three arguments' 120fi 121set -- ${x+"foo $x bam"} 122if (( $# !=1 )) 123then err_exit '${x+"foo $x bam"} does not yield one argument' 124fi 125set -- "${x+foo $x bam}" 126if (( $# !=1 )) 127then err_exit '"${x+foo $x bam}" does not yield one argument' 128fi 129set -- ${x+foo "$x "bam} 130if (( $# !=2 )) 131then err_exit '${x+foo "$x "bam} does not yield two arguments' 132fi 133x="ab$'cd" 134if [[ $x != 'ab$'"'cd" ]] 135then err_exit '$'"' inside double quotes not working" 136fi 137x=`print 'ab$'` 138if [[ $x != 'ab$' ]] 139then err_exit '$'"' inside `` quotes not working" 140fi 141unset a 142x=$(print -r -- "'\ 143\ 144") 145if [[ $x != "'" ]] 146then err_exit 'line continuation in double strings not working' 147fi 148x=$(print -r -- "'\ 149$a\ 150") 151if [[ $x != "'" ]] 152then err_exit 'line continuation in expanded double strings not working' 153fi 154x='\*' 155if [[ $(print -r -- $x) != '\*' ]] 156then err_exit 'x="\\*";$x != \*' 157fi 158if [[ $(print -r -- "\}" ) != '\}' ]] 159then err_exit '(print -r -- "\}"' not working 160fi 161if [[ $(print -r -- "\{" ) != '\{' ]] 162then err_exit 'print -r -- "\{"' not working 163fi 164# The following caused a syntax error on earlier versions 165foo=foo x=- 166if [[ `eval print \\${foo$x}` != foo* ]] 167then err_exit '`eval print \\${foo$x}`' not working 168fi 169if [[ "`eval print \\${foo$x}`" != foo* ]] 170then err_exit '"`eval print \\${foo$x}`"' not working 171fi 172if ( [[ $() != '' ]] ) 173then err_exit '$() not working' 174fi 175x=a:b:c 176set -- $( IFS=:; print $x) 177if (( $# != 3)) 178then err_exit 'IFS not working correctly with command substitution' 179fi 180$SHELL -n 2> /dev/null << \! || err_exit '$(...) bug with ( in comment' 181y=$( 182 # ( this line is a bug fix 183 print hi 184) 185! 186x= 187for j in glob noglob 188do for i in 'a\*b' 'a\ b' 'a\bc' 'a\*b' 'a\"b' 189 do eval [[ '$('print -r -- \'$i\'\$x')' != "'$i'" ]] && err_exit "quoting of $i\$x with $j enabled failed" 190 eval [[ '$('print -r -- \'$i\'\${x%*}')' != "'$i'" ]] && err_exit "quoting of $i\${x%*} with $j enabled failed" 191 if [[ $j == noglob ]] 192 then eval [[ '$('print -r -- \'$i\'\${x:-*}')' != "'$i''*'" ]] && err_exit "quoting of $i\${x:-*} with $j enabled failed" 193 fi 194 done 195 set -f 196done 197foo=foo 198[[ "$" == '$' ]] || err_exit '"$" != $' 199[[ "${foo}$" == 'foo$' ]] || err_exit 'foo=foo;"${foo}$" != foo$' 200[[ "${foo}${foo}$" == 'foofoo$' ]] || err_exit 'foo=foo;"${foo}${foo}$" != foofoo$' 201foo='$ ' 202[[ "$foo" == ~(Elr)(\\\$|#)\ ]] || err_exit $'\'$ \' not matching RE \\\\\\$|#\'' 203[[ "$foo" == ~(Elr)('\$'|#)\ ]] || err_exit $'\'$ \' not matching RE \'\\$\'|#\'' 204foo='# ' 205[[ "$foo" == ~(Elr)(\\\$|#)\ ]] || err_exit $'\'# \' not matching RE \\'\$|#\'' 206[[ "$foo" == ~(Elr)('\$'|#)\ ]] || err_exit $'\'# \' not matching RE \'\\$\'|#\'' 207[[ '\$' == '\$'* ]] || err_exit $'\'\\$\' not matching \'\\$\'*' 208[[ a+a == ~(E)a\+a ]] || err_exit '~(E)a\+a not matching a+a' 209[[ a+a =~ a\+a ]] || err_exit 'RE a\+a not matching a+a' 210 211exp='ac' 212got=$'a\0b'c 213[[ $got == "$exp" ]] || err_exit "\$'a\\0b'c expansion failed -- expected '$exp', got '$got'" 214 215exit $((Errors<125?Errors:125)) 216