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*4887Schinif [[ 'hi there' != "hi there" ]] 31*4887Schinthen err_exit "single quotes not the same as double quotes" 32*4887Schinfi 33*4887Schinx='hi there' 34*4887Schinif [[ $x != 'hi there' ]] 35*4887Schinthen err_exit "$x not the same as 'hi there'" 36*4887Schinfi 37*4887Schinif [[ $x != "hi there" ]] 38*4887Schinthen err_exit "$x not the same as \"hi there \"" 39*4887Schinfi 40*4887Schinif [[ \a\b\c\*\|\"\ \\ != 'abc*|" \' ]] 41*4887Schinthen err_exit " \\ differs from '' " 42*4887Schinfi 43*4887Schinif [[ "ab\'\"\$(" != 'ab\'\''"$(' ]] 44*4887Schinthen err_exit " \"\" differs from '' " 45*4887Schinfi 46*4887Schinif [[ $(print -r - 'abc*|" \') != 'abc*|" \' ]] 47*4887Schinthen err_exit "\$(print -r - '') differs from ''" 48*4887Schinfi 49*4887Schinif [[ $(print -r - "abc*|\" \\") != 'abc*|" \' ]] 50*4887Schinthen err_exit "\$(print -r - '') differs from ''" 51*4887Schinfi 52*4887Schinif [[ "$(print -r - 'abc*|" \')" != 'abc*|" \' ]] 53*4887Schinthen err_exit "\"\$(print -r - '')\" differs from ''" 54*4887Schinfi 55*4887Schinif [[ "$(print -r - "abc*|\" \\")" != 'abc*|" \' ]] 56*4887Schinthen err_exit "\"\$(print -r - "")\" differs from ''" 57*4887Schinfi 58*4887Schinif [[ $(print -r - $(print -r - 'abc*|" \')) != 'abc*|" \' ]] 59*4887Schinthen err_exit "nested \$(print -r - '') differs from ''" 60*4887Schinfi 61*4887Schinif [[ "$(print -r - $(print -r - 'abc*|" \'))" != 'abc*|" \' ]] 62*4887Schinthen err_exit "\"nested \$(print -r - '')\" differs from ''" 63*4887Schinfi 64*4887Schinif [[ $(print -r - "$(print -r - 'abc*|" \')") != 'abc*|" \' ]] 65*4887Schinthen err_exit "nested \"\$(print -r - '')\" differs from ''" 66*4887Schinfi 67*4887Schinunset x 68*4887Schinif [[ ${x-$(print -r - "abc*|\" \\")} != 'abc*|" \' ]] 69*4887Schinthen err_exit "\${x-\$(print -r - '')} differs from ''" 70*4887Schinfi 71*4887Schinif [[ ${x-$(print -r - "a}c*|\" \\")} != 'a}c*|" \' ]] 72*4887Schinthen err_exit "\${x-\$(print -r - '}')} differs from ''" 73*4887Schinfi 74*4887Schinx=$((echo foo)|(cat)) 75*4887Schinif [[ $x != foo ]] 76*4887Schinthen err_exit "((cmd)|(cmd)) failed" 77*4887Schinfi 78*4887Schinx=$(print -r -- "\"$HOME\"") 79*4887Schinif [[ $x != '"'$HOME'"' ]] 80*4887Schinthen err_exit "nested double quotes failed" 81*4887Schinfi 82*4887Schin: ${z="a{b}c"} 83*4887Schinif [[ $z != 'a{b}c' ]] 84*4887Schinthen err_exit '${z="a{b}c"} not correct' 85*4887Schinfi 86*4887Schinunset z 87*4887Schin: "${z="a{b}c"}" 88*4887Schinif [[ $z != 'a{b}c' ]] 89*4887Schinthen err_exit '"${z="a{b}c"}" not correct' 90*4887Schinfi 91*4887Schinif [[ $(print -r -- "a\*b") != 'a\*b' ]] 92*4887Schinthen err_exit '$(print -r -- "a\*b") differs from a\*b' 93*4887Schinfi 94*4887Schinunset x 95*4887Schinif [[ $(print -r -- "a\*b$x") != 'a\*b' ]] 96*4887Schinthen err_exit '$(print -r -- "a\*b$x") differs from a\*b' 97*4887Schinfi 98*4887Schinx=hello 99*4887Schinset -- ${x+foo bar bam} 100*4887Schinif (( $# !=3 )) 101*4887Schinthen err_exit '${x+foo bar bam} does not yield three arguments' 102*4887Schinfi 103*4887Schinset -- ${x+foo "bar bam"} 104*4887Schinif (( $# !=2 )) 105*4887Schinthen err_exit '${x+foo "bar bam"} does not yield two arguments' 106*4887Schinfi 107*4887Schinset -- ${x+foo 'bar bam'} 108*4887Schinif (( $# !=2 )) 109*4887Schinthen err_exit '${x+foo '\''bar bam'\''} does not yield two arguments' 110*4887Schinfi 111*4887Schinset -- ${x+foo $x bam} 112*4887Schinif (( $# !=3 )) 113*4887Schinthen err_exit '${x+foo $x bam} does not yield three arguments' 114*4887Schinfi 115*4887Schinset -- ${x+foo "$x" bam} 116*4887Schinif (( $# !=3 )) 117*4887Schinthen err_exit '${x+foo "$x" bam} does not yield three arguments' 118*4887Schinfi 119*4887Schinset -- ${x+"foo $x bam"} 120*4887Schinif (( $# !=1 )) 121*4887Schinthen err_exit '${x+"foo $x bam"} does not yield one argument' 122*4887Schinfi 123*4887Schinset -- "${x+foo $x bam}" 124*4887Schinif (( $# !=1 )) 125*4887Schinthen err_exit '"${x+foo $x bam}" does not yield one argument' 126*4887Schinfi 127*4887Schinset -- ${x+foo "$x "bam} 128*4887Schinif (( $# !=2 )) 129*4887Schinthen err_exit '${x+foo "$x "bam} does not yield two arguments' 130*4887Schinfi 131*4887Schinx="ab$'cd" 132*4887Schinif [[ $x != 'ab$'"'cd" ]] 133*4887Schinthen err_exit '$'"' inside double quotes not working" 134*4887Schinfi 135*4887Schinx=`print 'ab$'` 136*4887Schinif [[ $x != 'ab$' ]] 137*4887Schinthen err_exit '$'"' inside `` quotes not working" 138*4887Schinfi 139*4887Schinunset a 140*4887Schinx=$(print -r -- "'\ 141*4887Schin\ 142*4887Schin") 143*4887Schinif [[ $x != "'" ]] 144*4887Schinthen err_exit 'line continuation in double strings not working' 145*4887Schinfi 146*4887Schinx=$(print -r -- "'\ 147*4887Schin$a\ 148*4887Schin") 149*4887Schinif [[ $x != "'" ]] 150*4887Schinthen err_exit 'line continuation in expanded double strings not working' 151*4887Schinfi 152*4887Schinx='\*' 153*4887Schinif [[ $(print -r -- $x) != '\*' ]] 154*4887Schinthen err_exit 'x="\\*";$x != \*' 155*4887Schinfi 156*4887Schinx=' hello world ' 157*4887Schinset -- $x 158*4887Schinif (( $# != 2 )) 159*4887Schinthen err_exit 'field splitting error' 160*4887Schinfi 161*4887Schinx=$(print -r -- '1234567890123456789012345678901234567890123456789012345678901234567890 \ 162*4887Schin1234567890123456789012345678901234567890123456789012345678901234567890 \ 163*4887Schin1234567890123456789012345678901234567890123456789012345678901234567890 \ 164*4887Schin1234567890123456789012345678901234567890123456789012345678901234567890 \ 165*4887Schin1234567890123456789012345678901234567890123456789012345678901234567890 \ 166*4887Schin1234567890123456789012345678901234567890123456789012345678901234567890 \ 167*4887Schin1234567890123456789012345678901234567890123456789012345678901234567890 \ 168*4887Schin1234567890123456789012345678901234567890123456789012345678901234567890 \ 169*4887Schin1234567890123456789012345678901234567890123456789012345678901234567890 \ 170*4887Schin1234567890123456789012345678901234567890123456789012345678901234567890 \ 171*4887Schin1234567890123456789012345678901234567890123456789012345678901234567890 \ 172*4887Schin1234567890123456789012345678901234567890123456789012345678901234567890 \ 173*4887Schin1234567890123456789012345678901234567890123456789012345678901234567890 \ 174*4887Schin1234567890123456789012345678901234567890123456789012345678901234567890 \ 175*4887Schin1234567890123456789012345678901234567890123456789012345678901234567890') 176*4887Schinif (( ${#x} != (15*73-3) )) 177*4887Schinthen err_exit "length of x, ${#x}, is incorrect should be $((15*73-3))" 178*4887Schinfi 179*4887Schinx='$hi' 180*4887Schinif [[ $x\$ != '$hi$' ]] 181*4887Schinthen err_exit ' $x\$, with x=$hi, does not expand to $hi$' 182*4887Schinfi 183*4887Schinif [[ $x$ != '$hi$' ]] 184*4887Schinthen err_exit ' $x$, with x=$hi, does not expand to $hi$' 185*4887Schinfi 186*4887Schinset -- $(/bin/echo foo;sleep 1;/bin/echo bar) 187*4887Schinif [[ $# != 2 ]] 188*4887Schinthen err_exit 'word splitting after command substitution not working' 189*4887Schinfi 190*4887Schinunset q 191*4887Schinif [[ "${q:+'}q${q:+'}" != q ]] 192*4887Schinthen err_exit 'expansion of "{q:+'\''}" not correct when q unset' 193*4887Schinfi 194*4887Schinq=1 195*4887Schinif [[ "${q:+'}q${q:+'}" != "'q'" ]] 196*4887Schinthen err_exit 'expansion of "{q:+'\''}" not correct when q set' 197*4887Schinfi 198*4887Schinx=$'x\' #y' 199*4887Schinif [[ $x != "x' #y" ]] 200*4887Schinthen err_exit "$'x\' #y'" not working 201*4887Schinfi 202*4887Schinx=$q$'x\' #y' 203*4887Schinif [[ $x != "1x' #y" ]] 204*4887Schinthen err_exit "$q$'x\' #y'" not working 205*4887Schinfi 206*4887SchinIFS=, 207*4887Schinx='a,b\,c,d' 208*4887Schinset -- $x 209*4887Schinif [[ $2 != 'b\' ]] 210*4887Schinthen err_exit "field splitting of $x with IFS=$IFS not working" 211*4887Schinfi 212*4887Schinfoo=bar 213*4887Schinbar=$(print -r -- ${foo+\\n\ }) 214*4887Schinif [[ $bar != '\n ' ]] 215*4887Schinthen err_exit '${foo+\\n\ } expansion error' 216*4887Schinfi 217*4887Schinunset bar 218*4887Schinbar=$(print -r -- ${foo+\\n\ $bar}) 219*4887Schinif [[ $bar != '\n ' ]] 220*4887Schinthen err_exit '${foo+\\n\ $bar} expansion error with bar unset' 221*4887Schinfi 222*4887Schinx='\\(..\\)|&\|\|\\&\\|' 223*4887Schinif [[ $(print -r -- $x) != "$x" ]] 224*4887Schinthen err_exit '$x, where x=\\(..\\)|&\|\|\\&\\| not working' 225*4887Schinfi 226*4887Schinx='\\(' 227*4887Schinif [[ $(print -r -- a${x}b) != a"${x}"b ]] 228*4887Schinthen err_exit 'a${x}b, where x=\\( not working' 229*4887Schinfi 230*4887Schinx= 231*4887Schinif [[ $(print -r -- $x'\\1') != '\\1' ]] 232*4887Schinthen err_exit 'backreference inside single quotes broken' 233*4887Schinfi 234*4887Schinset -- '' 235*4887Schinset -- "$@" 236*4887Schinif (( $# != 1 )) 237*4887Schinthen err_exit '"$@" not preserving nulls' 238*4887Schinfi 239*4887Schinx= 240*4887Schinif [[ $(print -r s"!\2${x}\1\a!") != 's!\2\1\a!' ]] 241*4887Schinthen err_exit 'print -r s"!\2${x}\1\a!" not equal s!\2\1\a!' 242*4887Schinfi 243*4887Schinif [[ $(print -r $'foo\n\n\n') != foo ]] 244*4887Schinthen err_exit 'trailing newlines on comsubstitution not removed' 245*4887Schinfi 246*4887Schinunset x 247*4887Schinif [[ ${x:='//'} != '//' ]] 248*4887Schinthen err_exit '${x:='//'} != "//"' 249*4887Schinfi 250*4887Schinif [[ $(print -r "\"hi$\"") != '"hi$"' ]] 251*4887Schinthen err_exit '$\ not correct inside ""' 252*4887Schinfi 253*4887Schinunset x 254*4887Schinif [[ "${x-a\}b}" != 'a}b' ]] 255*4887Schinthen err_exit '"${x-a\}b}" != "a}b"' 256*4887Schinfi 257*4887Schinif [[ "\}\]$x\*\{\[\\" != '\}\]\*\{\[\' ]] 258*4887Schinthen err_exit '"\}\]$x\*\{\[\\" != "\}\]\*\{\[\"' 259*4887Schinfi 260*4887Schinfoo=yes 261*4887Schinif [[ $(print -r -- {\$foo}) != '{$foo}' ]] 262*4887Schinthen err_exit '{\$foo}' not expanded correctly 263*4887Schinfi 264*4887Schin[[ foo == $( 265*4887Schin########################################################### 266*4887Schin########################################################### 267*4887Schin########################################################### 268*4887Schin########################################################### 269*4887Schin########################################################### 270*4887Schin########################################################### 271*4887Schin########################################################### 272*4887Schin########################################################### 273*4887Schin########################################################### 274*4887Schin########################################################### 275*4887Schin########################################################### 276*4887Schin########################################################### 277*4887Schin########################################################### 278*4887Schin########################################################### 279*4887Schin########################################################### 280*4887Schin########################################################### 281*4887Schin########################################################### 282*4887Schin########################################################### 283*4887Schin########################################################### 284*4887Schin########################################################### 285*4887Schin########################################################### 286*4887Schin########################################################### 287*4887Schin########################################################### 288*4887Schin########################################################### 289*4887Schin########################################################### 290*4887Schin########################################################### 291*4887Schin########################################################### 292*4887Schin########################################################### 293*4887Schin########################################################### 294*4887Schin########################################################### 295*4887Schin########################################################### 296*4887Schin########################################################### 297*4887Schin########################################################### 298*4887Schin########################################################### 299*4887Schin########################################################### 300*4887Schin########################################################### 301*4887Schin########################################################### 302*4887Schin########################################################### 303*4887Schinprint foo) ]] || err_exit "command subsitution with long comments broken" 304*4887Schinsubject='some/other/words' 305*4887Schinre='(?*)/(?*)/(?*)' 306*4887Schin[[ ${subject/${re}/\3} != words ]] && err_exit 'string replacement with \3 not working' 307*4887Schin[[ ${subject/${re}/'\3'} != '\3' ]] && err_exit 'string replacement with '"'\3'"' not working' 308*4887Schin[[ ${subject/${re}/"\\3"} != '\3' ]] && err_exit 'string replacement with "\\3" not working' 309*4887Schin[[ ${subject/${re}/"\3"} != '\3' ]] && err_exit 'string replacement with "\3" not working' 310*4887Schinstring='\3' 311*4887Schin[[ ${subject/${re}/${string}} != words ]] && err_exit 'string replacement with $string not working with string=\3' 312*4887Schin[[ $(print -r "${subject/${re}/${string}}") != words ]] && err_exit 'string replacement with $string not working with string=\3 using print' 313*4887Schin[[ ${subject/${re}/"${string}"} != '\3' ]] && err_exit 'string replacement with "$string" not working with string=\3' 314*4887Schin[[ $(print -r "${subject/${re}/"${string}"}") != '\3' ]] && err_exit 'string replacement with "$string" not working with string=\3 using print' 315*4887Schinstring='\\3' 316*4887Schin[[ ${subject/${re}/${string}} != '\3' ]] && err_exit 'string replacement with $string not working with string=\\3' 317*4887Schin[[ ${subject/${re}/"${string}"} != '\\3' ]] && err_exit 'string replacement with "$string" not working with string=\\3' 318*4887Schin[[ ${subject/${re}/\4} != '\4' ]] && err_exit 'string replacement with \4 not working' 319*4887Schin[[ ${subject/${re}/'\4'} != '\4' ]] && err_exit 'string replacement with '\4' not working' 320*4887Schinstring='\4' 321*4887Schin[[ ${subject/${re}/${string}} != '\4' ]] && err_exit 'string replacement with $string not working with string=\4' 322*4887Schin[[ ${subject/${re}/"${string}"} != '\4' ]] && err_exit 'string replacement with "$string" not working with string=\4' 323*4887Schinstring='&foo' 324*4887Schin[[ ${subject/${re}/${string}} != '&foo' ]] && err_exit 'string replacement with $string not working with string=&foo' 325*4887Schin[[ ${subject/${re}/"${string}"} != '&foo' ]] && err_exit 'string replacement with "$string" not working with string=&foo' 326*4887Schin{ 327*4887Schinx=x 328*4887Schinx=${x:-`id | sed 's/^[^(]*(\([^)]*\)).*/\1/'`} 329*4887Schin} 2> /dev/null || err_exit 'skipping over `` failed' 330*4887Schin[[ $x == x ]] || err_exit 'assignment ${x:=`...`} failed' 331*4887Schinexit $((Errors)) 332