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*4887Schinnull=''
31*4887Schinif	[[ ! -z $null ]]
32*4887Schinthen	err_exit "-z: null string should be of zero length"
33*4887Schinfi
34*4887Schinfile=/tmp/regress$$
35*4887Schinif	[[ -z $file ]]
36*4887Schinthen	err_exit "-z: $file string should not be of zero length"
37*4887Schinfi
38*4887Schintrap "rm -f $file" EXIT
39*4887Schinrm -f $file
40*4887Schinif	[[ -a $file ]]
41*4887Schinthen	err_exit "-a: $file shouldn't exist"
42*4887Schinfi
43*4887Schin> $file
44*4887Schinif	[[ ! -a $file ]]
45*4887Schinthen	err_exit "-a: $file should exist"
46*4887Schinfi
47*4887Schinchmod 777 $file
48*4887Schinif	[[ ! -r $file ]]
49*4887Schinthen	err_exit "-r: $file should be readable"
50*4887Schinfi
51*4887Schinif	[[ ! -w $file ]]
52*4887Schinthen	err_exit "-w: $file should be writable"
53*4887Schinfi
54*4887Schinif	[[ ! -w $file ]]
55*4887Schinthen	err_exit "-x: $file should be executable"
56*4887Schinfi
57*4887Schinif	[[ ! -w $file || ! -r $file ]]
58*4887Schinthen	err_exit "-rw: $file should be readable/writable"
59*4887Schinfi
60*4887Schinif	[[ -s $file ]]
61*4887Schinthen	err_exit "-s: $file should be of zero size"
62*4887Schinfi
63*4887Schinif	[[ ! -f $file ]]
64*4887Schinthen	err_exit "-f: $file should be an ordinary file"
65*4887Schinfi
66*4887Schinif	[[  -d $file ]]
67*4887Schinthen	err_exit "-f: $file should not be a directory file"
68*4887Schinfi
69*4887Schinif	[[  ! -d . ]]
70*4887Schinthen	err_exit "-d: . should not be a directory file"
71*4887Schinfi
72*4887Schinif	[[  -f /dev/null ]]
73*4887Schinthen	err_exit "-f: /dev/null  should not be an ordinary file"
74*4887Schinfi
75*4887Schinchmod 000 $file
76*4887Schinif	[[ -r $file ]]
77*4887Schinthen	err_exit "-r: $file should not be readable"
78*4887Schinfi
79*4887Schinif	[[ ! -O $file ]]
80*4887Schinthen	err_exit "-r: $file should be owned by me"
81*4887Schinfi
82*4887Schinif	[[ -w $file ]]
83*4887Schinthen	err_exit "-w: $file should not be writable"
84*4887Schinfi
85*4887Schinif	[[ -w $file ]]
86*4887Schinthen	err_exit "-x: $file should not be executable"
87*4887Schinfi
88*4887Schinif	[[ -w $file || -r $file ]]
89*4887Schinthen	err_exit "-rw: $file should not be readable/writable"
90*4887Schinfi
91*4887Schinif	[[   -z x &&  -z x || ! -z x ]]
92*4887Schinthen	:
93*4887Schinelse	err_exit " wrong precedence"
94*4887Schinfi
95*4887Schinif	[[   -z x &&  (-z x || ! -z x) ]]
96*4887Schinthen	err_exit " () grouping not working"
97*4887Schinfi
98*4887Schinif	[[ foo < bar ]]
99*4887Schinthen	err_exit "foo comes before bar"
100*4887Schinfi
101*4887Schin[[ . -ef $(pwd) ]] || err_exit ". is not $PWD"
102*4887Schinset -o allexport
103*4887Schin[[ -o allexport ]] || err_exit '-o: did not set allexport option'
104*4887Schinif	[[ -n  $null ]]
105*4887Schinthen	err_exit "'$null' has non-zero length"
106*4887Schinfi
107*4887Schinif	[[ ! -r /dev/fd/0 ]]
108*4887Schinthen	err_exit "/dev/fd/0 not open for reading"
109*4887Schinfi
110*4887Schinif	[[ ! -w /dev/fd/2 ]]
111*4887Schinthen	err_exit "/dev/fd/2 not open for writing"
112*4887Schinfi
113*4887Schinsleep 1
114*4887Schinif	[[ ! . -ot $file ]]
115*4887Schinthen	err_exit ". should be older than $file"
116*4887Schinfi
117*4887Schinif	[[ /bin -nt $file ]]
118*4887Schinthen	err_exit "$file should be newer than /bin"
119*4887Schinfi
120*4887Schinif	[[ $file != /tmp/* ]]
121*4887Schinthen	err_exit "$file should match /tmp/*"
122*4887Schinfi
123*4887Schinif	[[ $file = '/tmp/*' ]]
124*4887Schinthen	err_exit "$file should not equal /tmp/*"
125*4887Schinfi
126*4887Schin[[ ! ( ! -z $null && ! -z x) ]]	|| err_exit "negation and grouping"
127*4887Schin[[ -z '' || -z '' || -z '' ]]	|| err_exit "three ors not working"
128*4887Schin[[ -z '' &&  -z '' && -z '' ]]	|| err_exit "three ors not working"
129*4887Schin(exit 8)
130*4887Schinif	[[ $? -ne 8 || $? -ne 8 ]]
131*4887Schinthen	err_exit 'value $? within [[...]]'
132*4887Schinfi
133*4887Schinx='(x'
134*4887Schinif	[[ '(x' != '('* ]]
135*4887Schinthen	err_exit " '(x' does not match '('* within [[...]]"
136*4887Schinfi
137*4887Schinif	[[ '(x' != "("* ]]
138*4887Schinthen	err_exit ' "(x" does not match "("* within [[...]]'
139*4887Schinfi
140*4887Schinif	[[ '(x' != \(* ]]
141*4887Schinthen	err_exit ' "(x" does not match \(* within [[...]]'
142*4887Schinfi
143*4887Schinif	[[ 'x(' != *'(' ]]
144*4887Schinthen	err_exit " 'x(' does not match '('* within [[...]]"
145*4887Schinfi
146*4887Schinif	[[ 'x&' != *'&' ]]
147*4887Schinthen	err_exit " 'x&' does not match '&'* within [[...]]"
148*4887Schinfi
149*4887Schinif	[[ 'xy' = *'*' ]]
150*4887Schinthen	err_exit " 'xy' matches *'*' within [[...]]"
151*4887Schinfi
152*4887Schinif	[[ 3 > 4 ]]
153*4887Schinthen	err_exit '3 < 4'
154*4887Schinfi
155*4887Schinif	[[ 4 < 3 ]]
156*4887Schinthen	err_exit '3 > 4'
157*4887Schinfi
158*4887Schinif	[[ 3x > 4x ]]
159*4887Schinthen	err_exit '3x < 4x'
160*4887Schinfi
161*4887Schinx='bin|dev|?'
162*4887Schincd /
163*4887Schinif	[[ $(print $x) != "$x" ]]
164*4887Schinthen	err_exit 'extended pattern matching on command arguments'
165*4887Schinfi
166*4887Schinif	[[ dev != $x ]]
167*4887Schinthen	err_exit 'extended pattern matching not working on variables'
168*4887Schinfi
169*4887Schinif	[[ -u $SHELL ]]
170*4887Schinthen	err_exit "setuid on $SHELL"
171*4887Schinfi
172*4887Schinif	[[ -g $SHELL ]]
173*4887Schinthen	err_exit "setgid on $SHELL"
174*4887Schinfi
175*4887Schintest -d .  -a '(' ! -f . ')' || err_exit 'test not working'
176*4887Schinif	[[ '!' != ! ]]
177*4887Schinthen	err_exit 'quoting unary operator not working'
178*4887Schinfi
179*4887Schinchmod 600 $file
180*4887Schinexec 4> $file
181*4887Schinprint -u4 foobar
182*4887Schinif	[[ ! -s $file ]]
183*4887Schinthen	err_exit "-s: $file should be non-zero"
184*4887Schinfi
185*4887Schinexec 4>&-
186*4887Schinif	[[ 011 -ne 11 ]]
187*4887Schinthen	err_exit "leading zeros in arithmetic compares not ignored"
188*4887Schinfi
189*4887Schin{
190*4887Schin	set -x
191*4887Schin	[[ foo > bar ]]
192*4887Schin} 2> /dev/null || { set +x; err_exit "foo<bar with -x enabled" ;}
193*4887Schinset +x
194*4887Schin(
195*4887Schin	eval "[[ (a) ]]"
196*4887Schin) 2> /dev/null || err_exit "[[ (a) ]] not working"
197*4887Schin> $file
198*4887Schinchmod 4755 "$file"
199*4887Schinif	test -u $file && test ! -u $file
200*4887Schinthen	err_exit "test ! -u suidfile not working"
201*4887Schinfi
202*4887Schinfor i in '(' ')' '[' ']'
203*4887Schindo	[[ $i == $i ]] || err_exit "[[ $i != $i ]]"
204*4887Schindone
205*4887Schin(
206*4887Schin	[[ aaaa == {4}(a) ]] || err_exit 'aaaa != {4}(a)'
207*4887Schin	[[ aaaa == {2,5}(a) ]] || err_exit 'aaaa != {2,4}(a)'
208*4887Schin	[[ abcdcdabcd == {3,6}(ab|cd) ]] || err_exit 'abcdcdabcd == {3,4}(ab|cd)'
209*4887Schin	[[ abcdcdabcde == {5}(ab|cd)e ]] || err_exit 'abcdcdabcd == {5}(ab|cd)e'
210*4887Schin) || err_exit 'Errors with {..}(...) patterns'
211*4887Schin[[ D290.2003.02.16.temp == D290.+(2003.02.16).temp* ]] || err_exit 'pattern match bug with +(...)'
212*4887Schinrm -rf $file
213*4887Schin{
214*4887Schin[[ -N $file ]] && err_exit 'test -N /tmp/*: st_mtime>st_atime after creat'
215*4887Schinsleep 2
216*4887Schinprint 'hello world'
217*4887Schin[[ -N $file ]] || err_exit 'test -N /tmp/*: st_mtime<=st_atime after write'
218*4887Schinsleep 2
219*4887Schinread
220*4887Schin[[ -N $file ]] && err_exit 'test -N /tmp/*: st_mtime>st_atime after read'
221*4887Schin} > $file < $file
222*4887Schinif	rm -rf "$file" && ln -s / "$file"
223*4887Schinthen	[[ -L "$file" ]] || err_exit '-L not working'
224*4887Schin	[[ -L "$file"/ ]] && err_exit '-L with file/ not working'
225*4887Schinfi
226*4887Schin$SHELL -c 't=1234567890; [[ $t == @({10}(\d)) ]]' 2> /dev/null || err_exit ' @({10}(\d)) pattern not working'
227*4887Schin$SHELL -c '[[ att_ == ~(E)(att|cus)_.* ]]' 2> /dev/null || err_exit ' ~(E)(att|cus)_* pattern not working'
228*4887Schin$SHELL -c '[[ att_ =~ (att|cus)_.* ]]' 2> /dev/null || err_exit ' =~ ere not working'
229*4887Schin$SHELL -c '[[ abc =~ a(b)c ]]' 2> /dev/null || err_exit '[[ abc =~ a(b)c ]] fails'
230*4887Schin$SHELL -xc '[[ abc =~  \babc\b ]]' 2> /dev/null || err_exit '[[ abc =~ \babc\b ]] fails'
231*4887Schin[[ abc == ~(E)\babc\b ]] || err_exit '\b not preserved for ere when not in ()'
232*4887Schin[[ abc == ~(iEi)\babc\b ]] || err_exit '\b not preserved for ~(iEi) when not in ()'
233*4887Schinexit $((Errors))
234