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