1######################################################################## 2# # 3# This software is part of the ast package # 4# Copyright (c) 1982-2008 AT&T Intellectual Property # 5# and is licensed under the # 6# Common Public License, Version 1.0 # 7# by AT&T Intellectual Property # 8# # 9# A copy of the License is available at # 10# http://www.opensource.org/licenses/cpl1.0.txt # 11# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) # 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 30null='' 31if [[ ! -z $null ]] 32then err_exit "-z: null string should be of zero length" 33fi 34file=/tmp/regresso$$ 35newer_file=/tmp/regressn$$ 36if [[ -z $file ]] 37then err_exit "-z: $file string should not be of zero length" 38fi 39trap "rm -f $file $newer_file" EXIT 40rm -f $file 41if [[ -a $file ]] 42then err_exit "-a: $file shouldn't exist" 43fi 44> $file 45if [[ ! -a $file ]] 46then err_exit "-a: $file should exist" 47fi 48chmod 777 $file 49if [[ ! -r $file ]] 50then err_exit "-r: $file should be readable" 51fi 52if [[ ! -w $file ]] 53then err_exit "-w: $file should be writable" 54fi 55if [[ ! -w $file ]] 56then err_exit "-x: $file should be executable" 57fi 58if [[ ! -w $file || ! -r $file ]] 59then err_exit "-rw: $file should be readable/writable" 60fi 61if [[ -s $file ]] 62then err_exit "-s: $file should be of zero size" 63fi 64if [[ ! -f $file ]] 65then err_exit "-f: $file should be an ordinary file" 66fi 67if [[ -d $file ]] 68then err_exit "-f: $file should not be a directory file" 69fi 70if [[ ! -d . ]] 71then err_exit "-d: . should not be a directory file" 72fi 73if [[ -f /dev/null ]] 74then err_exit "-f: /dev/null should not be an ordinary file" 75fi 76chmod 000 $file 77if [[ -r $file ]] 78then err_exit "-r: $file should not be readable" 79fi 80if [[ ! -O $file ]] 81then err_exit "-r: $file should be owned by me" 82fi 83if [[ -w $file ]] 84then err_exit "-w: $file should not be writable" 85fi 86if [[ -w $file ]] 87then err_exit "-x: $file should not be executable" 88fi 89if [[ -w $file || -r $file ]] 90then err_exit "-rw: $file should not be readable/writable" 91fi 92if [[ -z x && -z x || ! -z x ]] 93then : 94else err_exit " wrong precedence" 95fi 96if [[ -z x && (-z x || ! -z x) ]] 97then err_exit " () grouping not working" 98fi 99if [[ foo < bar ]] 100then err_exit "foo comes before bar" 101fi 102[[ . -ef $(pwd) ]] || err_exit ". is not $PWD" 103set -o allexport 104[[ -o allexport ]] || err_exit '-o: did not set allexport option' 105if [[ -n $null ]] 106then err_exit "'$null' has non-zero length" 107fi 108if [[ ! -r /dev/fd/0 ]] 109then err_exit "/dev/fd/0 not open for reading" 110fi 111if [[ ! -w /dev/fd/2 ]] 112then err_exit "/dev/fd/2 not open for writing" 113fi 114sleep 1 115> $newer_file 116if [[ ! $file -ot $newer_file ]] 117then err_exit "$file should be older than $newer_file" 118fi 119if [[ $file -nt $newer_file ]] 120then err_exit "$newer_file should be newer than $file" 121fi 122if [[ $file != /tmp/* ]] 123then err_exit "$file should match /tmp/*" 124fi 125if [[ $file = '/tmp/*' ]] 126then err_exit "$file should not equal /tmp/*" 127fi 128[[ ! ( ! -z $null && ! -z x) ]] || err_exit "negation and grouping" 129[[ -z '' || -z '' || -z '' ]] || err_exit "three ors not working" 130[[ -z '' && -z '' && -z '' ]] || err_exit "three ors not working" 131(exit 8) 132if [[ $? -ne 8 || $? -ne 8 ]] 133then err_exit 'value $? within [[...]]' 134fi 135x='(x' 136if [[ '(x' != '('* ]] 137then err_exit " '(x' does not match '('* within [[...]]" 138fi 139if [[ '(x' != "("* ]] 140then err_exit ' "(x" does not match "("* within [[...]]' 141fi 142if [[ '(x' != \(* ]] 143then err_exit ' "(x" does not match \(* within [[...]]' 144fi 145if [[ 'x(' != *'(' ]] 146then err_exit " 'x(' does not match '('* within [[...]]" 147fi 148if [[ 'x&' != *'&' ]] 149then err_exit " 'x&' does not match '&'* within [[...]]" 150fi 151if [[ 'xy' = *'*' ]] 152then err_exit " 'xy' matches *'*' within [[...]]" 153fi 154if [[ 3 > 4 ]] 155then err_exit '3 < 4' 156fi 157if [[ 4 < 3 ]] 158then err_exit '3 > 4' 159fi 160if [[ 3x > 4x ]] 161then err_exit '3x < 4x' 162fi 163x='bin|dev|?' 164cd / 165if [[ $(print $x) != "$x" ]] 166then err_exit 'extended pattern matching on command arguments' 167fi 168if [[ dev != $x ]] 169then err_exit 'extended pattern matching not working on variables' 170fi 171if [[ -u $SHELL ]] 172then err_exit "setuid on $SHELL" 173fi 174if [[ -g $SHELL ]] 175then err_exit "setgid on $SHELL" 176fi 177test -d . -a '(' ! -f . ')' || err_exit 'test not working' 178if [[ '!' != ! ]] 179then err_exit 'quoting unary operator not working' 180fi 181test \( -n x \) -o \( -n y \) 2> /dev/null || err_exit 'test ( -n x ) -o ( -n y) not working' 182test \( -n x \) -o -n y 2> /dev/null || err_exit 'test ( -n x ) -o -n y not working' 183chmod 600 $file 184exec 4> $file 185print -u4 foobar 186if [[ ! -s $file ]] 187then err_exit "-s: $file should be non-zero" 188fi 189exec 4>&- 190if [[ 011 -ne 11 ]] 191then err_exit "leading zeros in arithmetic compares not ignored" 192fi 193{ 194 set -x 195 [[ foo > bar ]] 196} 2> /dev/null || { set +x; err_exit "foo<bar with -x enabled" ;} 197set +x 198( 199 eval "[[ (a) ]]" 200) 2> /dev/null || err_exit "[[ (a) ]] not working" 201> $file 202chmod 4755 "$file" 203if test -u $file && test ! -u $file 204then err_exit "test ! -u suidfile not working" 205fi 206for i in '(' ')' '[' ']' 207do [[ $i == $i ]] || err_exit "[[ $i != $i ]]" 208done 209( 210 [[ aaaa == {4}(a) ]] || err_exit 'aaaa != {4}(a)' 211 [[ aaaa == {2,5}(a) ]] || err_exit 'aaaa != {2,4}(a)' 212 [[ abcdcdabcd == {3,6}(ab|cd) ]] || err_exit 'abcdcdabcd == {3,4}(ab|cd)' 213 [[ abcdcdabcde == {5}(ab|cd)e ]] || err_exit 'abcdcdabcd == {5}(ab|cd)e' 214) || err_exit 'Errors with {..}(...) patterns' 215[[ D290.2003.02.16.temp == D290.+(2003.02.16).temp* ]] || err_exit 'pattern match bug with +(...)' 216rm -rf $file 217{ 218[[ -N $file ]] && err_exit 'test -N /tmp/*: st_mtime>st_atime after creat' 219sleep 2 220print 'hello world' 221[[ -N $file ]] || err_exit 'test -N /tmp/*: st_mtime<=st_atime after write' 222sleep 2 223read 224[[ -N $file ]] && err_exit 'test -N /tmp/*: st_mtime>st_atime after read' 225} > $file < $file 226if rm -rf "$file" && ln -s / "$file" 227then [[ -L "$file" ]] || err_exit '-L not working' 228 [[ -L "$file"/ ]] && err_exit '-L with file/ not working' 229fi 230$SHELL -c 't=1234567890; [[ $t == @({10}(\d)) ]]' 2> /dev/null || err_exit ' @({10}(\d)) pattern not working' 231$SHELL -c '[[ att_ == ~(E)(att|cus)_.* ]]' 2> /dev/null || err_exit ' ~(E)(att|cus)_* pattern not working' 232$SHELL -c '[[ att_ =~ (att|cus)_.* ]]' 2> /dev/null || err_exit ' =~ ere not working' 233$SHELL -c '[[ abc =~ a(b)c ]]' 2> /dev/null || err_exit '[[ abc =~ a(b)c ]] fails' 234$SHELL -xc '[[ abc =~ \babc\b ]]' 2> /dev/null || err_exit '[[ abc =~ \babc\b ]] fails' 235[[ abc == ~(E)\babc\b ]] || err_exit '\b not preserved for ere when not in ()' 236[[ abc == ~(iEi)\babc\b ]] || err_exit '\b not preserved for ~(iEi) when not in ()' 237 238e=$($SHELL -c '[ -z "" -a -z "" ]' 2>&1) 239[[ $e ]] && err_exit "[ ... ] compatibility check failed -- $e" 240i=hell 241[[ hell0 == $i[0] ]] || err_exit 'pattern $i[0] interpreded as array ref' 242test '(' = ')' && err_exit '"test ( = )" should not be true' 243[[ $($SHELL -c 'case F in ~(Eilr)[a-z0-9#]) print ok;;esac' 2> /dev/null) == ok ]] || err_exit '~(Eilr) not working in case command' 244[[ $($SHELL -c "case Q in ~(Fi)q | \$'\E') print ok;;esac" 2> /dev/null) == ok ]] || err_exit '~(Fi)q | \E not working in case command' 245exit $((Errors)) 246