1*b30d1939SAndy Fiddaman########################################################################
2*b30d1939SAndy Fiddaman#                                                                      #
3*b30d1939SAndy Fiddaman#               This software is part of the ast package               #
4*b30d1939SAndy Fiddaman#          Copyright (c) 1982-2012 AT&T Intellectual Property          #
5*b30d1939SAndy Fiddaman#                      and is licensed under the                       #
6*b30d1939SAndy Fiddaman#                 Eclipse Public License, Version 1.0                  #
7*b30d1939SAndy Fiddaman#                    by AT&T Intellectual Property                     #
8*b30d1939SAndy Fiddaman#                                                                      #
9*b30d1939SAndy Fiddaman#                A copy of the License is available at                 #
10*b30d1939SAndy Fiddaman#          http://www.eclipse.org/org/documents/epl-v10.html           #
11*b30d1939SAndy Fiddaman#         (with md5 checksum b35adb5213ca9657e911e9befb180842)         #
12*b30d1939SAndy Fiddaman#                                                                      #
13*b30d1939SAndy Fiddaman#              Information and Software Systems Research               #
14*b30d1939SAndy Fiddaman#                            AT&T Research                             #
15*b30d1939SAndy Fiddaman#                           Florham Park NJ                            #
16*b30d1939SAndy Fiddaman#                                                                      #
17*b30d1939SAndy Fiddaman#                  David Korn <dgk@research.att.com>                   #
18*b30d1939SAndy Fiddaman#                                                                      #
19*b30d1939SAndy Fiddaman########################################################################
20*b30d1939SAndy Fiddamanfunction err_exit
21*b30d1939SAndy Fiddaman{
22*b30d1939SAndy Fiddaman	print -u2 -n "\t"
23*b30d1939SAndy Fiddaman	print -u2 -r ${Command}[$1]: "${@:2}"
24*b30d1939SAndy Fiddaman	let Errors+=1
25*b30d1939SAndy Fiddaman}
26*b30d1939SAndy Fiddamanalias err_exit='err_exit $LINENO'
27*b30d1939SAndy Fiddaman
28*b30d1939SAndy FiddamanCommand=${0##*/}
29*b30d1939SAndy Fiddamaninteger Errors=0
30*b30d1939SAndy Fiddaman
31*b30d1939SAndy Fiddamantmp=$(mktemp -dt) || { err_exit mktemp -dt failed; exit 1; }
32*b30d1939SAndy Fiddamantrap "cd /; rm -rf $tmp" EXIT
33*b30d1939SAndy Fiddaman
34*b30d1939SAndy Fiddamannull=''
35*b30d1939SAndy Fiddamanif	[[ ! -z $null ]]
36*b30d1939SAndy Fiddamanthen	err_exit "-z: null string should be of zero length"
37*b30d1939SAndy Fiddamanfi
38*b30d1939SAndy Fiddamanfile=$tmp/original
39*b30d1939SAndy Fiddamannewer_file=$tmp/newer
40*b30d1939SAndy Fiddamanif	[[ -z $file ]]
41*b30d1939SAndy Fiddamanthen	err_exit "-z: $file string should not be of zero length"
42*b30d1939SAndy Fiddamanfi
43*b30d1939SAndy Fiddamanif	[[ -a $file ]]
44*b30d1939SAndy Fiddamanthen	err_exit "-a: $file shouldn't exist"
45*b30d1939SAndy Fiddamanfi
46*b30d1939SAndy Fiddamanif	[[ -e $file ]]
47*b30d1939SAndy Fiddamanthen	err_exit "-e: $file shouldn't exist"
48*b30d1939SAndy Fiddamanfi
49*b30d1939SAndy Fiddaman> $file
50*b30d1939SAndy Fiddamanif	[[ ! -a $file ]]
51*b30d1939SAndy Fiddamanthen	err_exit "-a: $file should exist"
52*b30d1939SAndy Fiddamanfi
53*b30d1939SAndy Fiddamanif	[[ ! -e $file ]]
54*b30d1939SAndy Fiddamanthen	err_exit "-e: $file should exist"
55*b30d1939SAndy Fiddamanfi
56*b30d1939SAndy Fiddamanchmod 777 $file
57*b30d1939SAndy Fiddamanif	[[ ! -r $file ]]
58*b30d1939SAndy Fiddamanthen	err_exit "-r: $file should be readable"
59*b30d1939SAndy Fiddamanfi
60*b30d1939SAndy Fiddamanif	[[ ! -w $file ]]
61*b30d1939SAndy Fiddamanthen	err_exit "-w: $file should be writable"
62*b30d1939SAndy Fiddamanfi
63*b30d1939SAndy Fiddamanif	[[ ! -w $file ]]
64*b30d1939SAndy Fiddamanthen	err_exit "-x: $file should be executable"
65*b30d1939SAndy Fiddamanfi
66*b30d1939SAndy Fiddamanif	[[ ! -w $file || ! -r $file ]]
67*b30d1939SAndy Fiddamanthen	err_exit "-rw: $file should be readable/writable"
68*b30d1939SAndy Fiddamanfi
69*b30d1939SAndy Fiddamanif	[[ -s $file ]]
70*b30d1939SAndy Fiddamanthen	err_exit "-s: $file should be of zero size"
71*b30d1939SAndy Fiddamanfi
72*b30d1939SAndy Fiddamanif	[[ ! -f $file ]]
73*b30d1939SAndy Fiddamanthen	err_exit "-f: $file should be an ordinary file"
74*b30d1939SAndy Fiddamanfi
75*b30d1939SAndy Fiddamanif	[[  -d $file ]]
76*b30d1939SAndy Fiddamanthen	err_exit "-f: $file should not be a directory file"
77*b30d1939SAndy Fiddamanfi
78*b30d1939SAndy Fiddamanif	[[  ! -d . ]]
79*b30d1939SAndy Fiddamanthen	err_exit "-d: . should not be a directory file"
80*b30d1939SAndy Fiddamanfi
81*b30d1939SAndy Fiddamanif	[[  -f /dev/null ]]
82*b30d1939SAndy Fiddamanthen	err_exit "-f: /dev/null  should not be an ordinary file"
83*b30d1939SAndy Fiddamanfi
84*b30d1939SAndy Fiddamanchmod 000 $file
85*b30d1939SAndy Fiddamanif	[[ -r $file ]]
86*b30d1939SAndy Fiddamanthen	err_exit "-r: $file should not be readable"
87*b30d1939SAndy Fiddamanfi
88*b30d1939SAndy Fiddamanif	[[ ! -O $file ]]
89*b30d1939SAndy Fiddamanthen	err_exit "-r: $file should be owned by me"
90*b30d1939SAndy Fiddamanfi
91*b30d1939SAndy Fiddamanif	[[ -w $file ]]
92*b30d1939SAndy Fiddamanthen	err_exit "-w: $file should not be writable"
93*b30d1939SAndy Fiddamanfi
94*b30d1939SAndy Fiddamanif	[[ -w $file ]]
95*b30d1939SAndy Fiddamanthen	err_exit "-x: $file should not be executable"
96*b30d1939SAndy Fiddamanfi
97*b30d1939SAndy Fiddamanif	[[ -w $file || -r $file ]]
98*b30d1939SAndy Fiddamanthen	err_exit "-rw: $file should not be readable/writable"
99*b30d1939SAndy Fiddamanfi
100*b30d1939SAndy Fiddamanif	[[   -z x &&  -z x || ! -z x ]]
101*b30d1939SAndy Fiddamanthen	:
102*b30d1939SAndy Fiddamanelse	err_exit " wrong precedence"
103*b30d1939SAndy Fiddamanfi
104*b30d1939SAndy Fiddamanif	[[   -z x &&  (-z x || ! -z x) ]]
105*b30d1939SAndy Fiddamanthen	err_exit " () grouping not working"
106*b30d1939SAndy Fiddamanfi
107*b30d1939SAndy Fiddamanif	[[ foo < bar ]]
108*b30d1939SAndy Fiddamanthen	err_exit "foo comes before bar"
109*b30d1939SAndy Fiddamanfi
110*b30d1939SAndy Fiddaman[[ . -ef $(pwd) ]] || err_exit ". is not $PWD"
111*b30d1939SAndy Fiddamanset -o allexport
112*b30d1939SAndy Fiddaman[[ -o allexport ]] || err_exit '-o: did not set allexport option'
113*b30d1939SAndy Fiddamanif	[[ -n  $null ]]
114*b30d1939SAndy Fiddamanthen	err_exit "'$null' has non-zero length"
115*b30d1939SAndy Fiddamanfi
116*b30d1939SAndy Fiddamanif	[[ ! -r /dev/fd/0 ]]
117*b30d1939SAndy Fiddamanthen	err_exit "/dev/fd/0 not open for reading"
118*b30d1939SAndy Fiddamanfi
119*b30d1939SAndy Fiddamanif	[[ ! -w /dev/fd/2 ]]
120*b30d1939SAndy Fiddamanthen	err_exit "/dev/fd/2 not open for writing"
121*b30d1939SAndy Fiddamanfi
122*b30d1939SAndy Fiddamansleep 1
123*b30d1939SAndy Fiddaman> $newer_file
124*b30d1939SAndy Fiddamanif	[[ ! $file -ot $newer_file ]]
125*b30d1939SAndy Fiddamanthen	err_exit "$file should be older than $newer_file"
126*b30d1939SAndy Fiddamanfi
127*b30d1939SAndy Fiddamanif	[[ $file -nt $newer_file ]]
128*b30d1939SAndy Fiddamanthen	err_exit "$newer_file should be newer than $file"
129*b30d1939SAndy Fiddamanfi
130*b30d1939SAndy Fiddamanif	[[ $file != $tmp/* ]]
131*b30d1939SAndy Fiddamanthen	err_exit "$file should match $tmp/*"
132*b30d1939SAndy Fiddamanfi
133*b30d1939SAndy Fiddamanif	[[ $file == $tmp'/*' ]]
134*b30d1939SAndy Fiddamanthen	err_exit "$file should not equal $tmp'/*'"
135*b30d1939SAndy Fiddamanfi
136*b30d1939SAndy Fiddaman[[ ! ( ! -z $null && ! -z x) ]]	|| err_exit "negation and grouping"
137*b30d1939SAndy Fiddaman[[ -z '' || -z '' || -z '' ]]	|| err_exit "three ors not working"
138*b30d1939SAndy Fiddaman[[ -z '' &&  -z '' && -z '' ]]	|| err_exit "three ors not working"
139*b30d1939SAndy Fiddaman(exit 8)
140*b30d1939SAndy Fiddamanif	[[ $? -ne 8 || $? -ne 8 ]]
141*b30d1939SAndy Fiddamanthen	err_exit 'value $? within [[...]]'
142*b30d1939SAndy Fiddamanfi
143*b30d1939SAndy Fiddamanx='(x'
144*b30d1939SAndy Fiddamanif	[[ '(x' != '('* ]]
145*b30d1939SAndy Fiddamanthen	err_exit " '(x' does not match '('* within [[...]]"
146*b30d1939SAndy Fiddamanfi
147*b30d1939SAndy Fiddamanif	[[ '(x' != "("* ]]
148*b30d1939SAndy Fiddamanthen	err_exit ' "(x" does not match "("* within [[...]]'
149*b30d1939SAndy Fiddamanfi
150*b30d1939SAndy Fiddamanif	[[ '(x' != \(* ]]
151*b30d1939SAndy Fiddamanthen	err_exit ' "(x" does not match \(* within [[...]]'
152*b30d1939SAndy Fiddamanfi
153*b30d1939SAndy Fiddamanif	[[ 'x(' != *'(' ]]
154*b30d1939SAndy Fiddamanthen	err_exit " 'x(' does not match '('* within [[...]]"
155*b30d1939SAndy Fiddamanfi
156*b30d1939SAndy Fiddamanif	[[ 'x&' != *'&' ]]
157*b30d1939SAndy Fiddamanthen	err_exit " 'x&' does not match '&'* within [[...]]"
158*b30d1939SAndy Fiddamanfi
159*b30d1939SAndy Fiddamanif	[[ 'xy' == *'*' ]]
160*b30d1939SAndy Fiddamanthen	err_exit " 'xy' matches *'*' within [[...]]"
161*b30d1939SAndy Fiddamanfi
162*b30d1939SAndy Fiddamanif	[[ 3 > 4 ]]
163*b30d1939SAndy Fiddamanthen	err_exit '3 < 4'
164*b30d1939SAndy Fiddamanfi
165*b30d1939SAndy Fiddamanif	[[ 4 < 3 ]]
166*b30d1939SAndy Fiddamanthen	err_exit '3 > 4'
167*b30d1939SAndy Fiddamanfi
168*b30d1939SAndy Fiddamanif	[[ 3x > 4x ]]
169*b30d1939SAndy Fiddamanthen	err_exit '3x < 4x'
170*b30d1939SAndy Fiddamanfi
171*b30d1939SAndy Fiddamanx='@(bin|dev|?)'
172*b30d1939SAndy Fiddamancd /
173*b30d1939SAndy Fiddamanif	[[ $(print $x) != "$x" ]]
174*b30d1939SAndy Fiddamanthen	err_exit 'extended pattern matching on command arguments'
175*b30d1939SAndy Fiddamanfi
176*b30d1939SAndy Fiddamanif	[[ dev != $x ]]
177*b30d1939SAndy Fiddamanthen	err_exit 'extended pattern matching not working on variables'
178*b30d1939SAndy Fiddamanfi
179*b30d1939SAndy Fiddamanif	[[ -u $SHELL ]]
180*b30d1939SAndy Fiddamanthen	err_exit "setuid on $SHELL"
181*b30d1939SAndy Fiddamanfi
182*b30d1939SAndy Fiddamanif	[[ -g $SHELL ]]
183*b30d1939SAndy Fiddamanthen	err_exit "setgid on $SHELL"
184*b30d1939SAndy Fiddamanfi
185*b30d1939SAndy Fiddamantest -d .  -a '(' ! -f . ')' || err_exit 'test not working'
186*b30d1939SAndy Fiddamanif	[[ '!' != ! ]]
187*b30d1939SAndy Fiddamanthen	err_exit 'quoting unary operator not working'
188*b30d1939SAndy Fiddamanfi
189*b30d1939SAndy Fiddamantest \( -n x \) -o \( -n y \) 2> /dev/null || err_exit 'test ( -n x ) -o ( -n y) not working'
190*b30d1939SAndy Fiddamantest \( -n x \) -o -n y 2> /dev/null || err_exit 'test ( -n x ) -o -n y not working'
191*b30d1939SAndy Fiddamanchmod 600 $file
192*b30d1939SAndy Fiddamanexec 4> $file
193*b30d1939SAndy Fiddamanprint -u4 foobar
194*b30d1939SAndy Fiddamanif	[[ ! -s $file ]]
195*b30d1939SAndy Fiddamanthen	err_exit "-s: $file should be non-zero"
196*b30d1939SAndy Fiddamanfi
197*b30d1939SAndy Fiddamanexec 4>&-
198*b30d1939SAndy Fiddamanif	[[ 011 -ne 11 ]]
199*b30d1939SAndy Fiddamanthen	err_exit "leading zeros in arithmetic compares not ignored"
200*b30d1939SAndy Fiddamanfi
201*b30d1939SAndy Fiddaman{
202*b30d1939SAndy Fiddaman	set -x
203*b30d1939SAndy Fiddaman	[[ foo > bar ]]
204*b30d1939SAndy Fiddaman} 2> /dev/null || { set +x; err_exit "foo<bar with -x enabled" ;}
205*b30d1939SAndy Fiddamanset +x
206*b30d1939SAndy Fiddaman(
207*b30d1939SAndy Fiddaman	eval "[[ (a) ]]"
208*b30d1939SAndy Fiddaman) 2> /dev/null || err_exit "[[ (a) ]] not working"
209*b30d1939SAndy Fiddaman> $file
210*b30d1939SAndy Fiddamanchmod 4755 "$file"
211*b30d1939SAndy Fiddamanif	test -u $file && test ! -u $file
212*b30d1939SAndy Fiddamanthen	err_exit "test ! -u suidfile not working"
213*b30d1939SAndy Fiddamanfi
214*b30d1939SAndy Fiddamanfor i in '(' ')' '[' ']'
215*b30d1939SAndy Fiddamando	[[ $i == $i ]] || err_exit "[[ $i != $i ]]"
216*b30d1939SAndy Fiddamandone
217*b30d1939SAndy Fiddaman(
218*b30d1939SAndy Fiddaman	[[ aaaa == {4}(a) ]] || err_exit 'aaaa != {4}(a)'
219*b30d1939SAndy Fiddaman	[[ aaaa == {2,5}(a) ]] || err_exit 'aaaa != {2,4}(a)'
220*b30d1939SAndy Fiddaman	[[ abcdcdabcd == {3,6}(ab|cd) ]] || err_exit 'abcdcdabcd == {3,4}(ab|cd)'
221*b30d1939SAndy Fiddaman	[[ abcdcdabcde == {5}(ab|cd)e ]] || err_exit 'abcdcdabcd == {5}(ab|cd)e'
222*b30d1939SAndy Fiddaman) || err_exit 'errors with {..}(...) patterns'
223*b30d1939SAndy Fiddaman[[ D290.2003.02.16.temp == D290.+(2003.02.16).temp* ]] || err_exit 'pattern match bug with +(...)'
224*b30d1939SAndy Fiddamanrm -rf $file
225*b30d1939SAndy Fiddaman{
226*b30d1939SAndy Fiddaman[[ -N $file ]] && err_exit 'test -N $tmp/*: st_mtime>st_atime after creat'
227*b30d1939SAndy Fiddamansleep 2
228*b30d1939SAndy Fiddamanprint 'hello world'
229*b30d1939SAndy Fiddaman[[ -N $file ]] || err_exit 'test -N $tmp/*: st_mtime<=st_atime after write'
230*b30d1939SAndy Fiddamansleep 2
231*b30d1939SAndy Fiddamanread
232*b30d1939SAndy Fiddaman[[ -N $file ]] && err_exit 'test -N $tmp/*: st_mtime>st_atime after read'
233*b30d1939SAndy Fiddaman} > $file < $file
234*b30d1939SAndy Fiddamanif	rm -rf "$file" && ln -s / "$file"
235*b30d1939SAndy Fiddamanthen	[[ -L "$file" ]] || err_exit '-L not working'
236*b30d1939SAndy Fiddaman	[[ -L "$file"/ ]] && err_exit '-L with file/ not working'
237*b30d1939SAndy Fiddamanfi
238*b30d1939SAndy Fiddaman$SHELL -c 't=1234567890; [[ $t == @({10}(\d)) ]]' 2> /dev/null || err_exit ' @({10}(\d)) pattern not working'
239*b30d1939SAndy Fiddaman$SHELL -c '[[ att_ == ~(E)(att|cus)_.* ]]' 2> /dev/null || err_exit ' ~(E)(att|cus)_* pattern not working'
240*b30d1939SAndy Fiddaman$SHELL -c '[[ att_ =~ (att|cus)_.* ]]' 2> /dev/null || err_exit ' =~ ere not working'
241*b30d1939SAndy Fiddaman$SHELL -c '[[ abc =~ a(b)c ]]' 2> /dev/null || err_exit '[[ abc =~ a(b)c ]] fails'
242*b30d1939SAndy Fiddaman$SHELL -xc '[[ abc =~  \babc\b ]]' 2> /dev/null || err_exit '[[ abc =~ \babc\b ]] fails'
243*b30d1939SAndy Fiddaman[[ abc == ~(E)\babc\b ]] || err_exit '\b not preserved for ere when not in ()'
244*b30d1939SAndy Fiddaman[[ abc == ~(iEi)\babc\b ]] || err_exit '\b not preserved for ~(iEi) when not in ()'
245*b30d1939SAndy Fiddaman
246*b30d1939SAndy Fiddamane=$($SHELL -c '[ -z "" -a -z "" ]' 2>&1)
247*b30d1939SAndy Fiddaman[[ $e ]] && err_exit "[ ... ] compatibility check failed -- $e"
248*b30d1939SAndy Fiddamani=hell
249*b30d1939SAndy Fiddaman[[ hell0 == $i[0] ]]  ||  err_exit 'pattern $i[0] interpreded as array ref'
250*b30d1939SAndy Fiddamantest '(' = ')' && err_exit '"test ( = )" should not be true'
251*b30d1939SAndy Fiddaman[[ $($SHELL -c 'case  F in ~(Eilr)[a-z0-9#]) print ok;;esac' 2> /dev/null) == ok ]] || err_exit '~(Eilr) not working in case command'
252*b30d1939SAndy Fiddaman[[ $($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'
253*b30d1939SAndy Fiddaman
254*b30d1939SAndy Fiddamanfor l in C en_US.ISO8859-15
255*b30d1939SAndy Fiddamando	[[ $($SHELL -c "LC_COLLATE=$l" 2>&1) ]] && continue
256*b30d1939SAndy Fiddaman	export LC_COLLATE=$l
257*b30d1939SAndy Fiddaman	set -- \
258*b30d1939SAndy Fiddaman		'A'   0 1 1   0 1 1      1 0 0   1 0 0   \
259*b30d1939SAndy Fiddaman		'Z'   0 1 1   0 1 1      1 0 0   1 0 0   \
260*b30d1939SAndy Fiddaman		'/'   0 0 0   0 0 0      1 1 1   1 1 1   \
261*b30d1939SAndy Fiddaman		'.'   0 0 0   0 0 0      1 1 1   1 1 1   \
262*b30d1939SAndy Fiddaman		'_'   0 0 0   0 0 0      1 1 1   1 1 1   \
263*b30d1939SAndy Fiddaman		'-'   1 1 1   1 1 1      0 0 0   0 0 0   \
264*b30d1939SAndy Fiddaman		'%'   0 0 0   0 0 0      1 1 1   1 1 1   \
265*b30d1939SAndy Fiddaman		'@'   0 0 0   0 0 0      1 1 1   1 1 1   \
266*b30d1939SAndy Fiddaman		'!'   0 0 0   0 0 0      1 1 1   1 1 1   \
267*b30d1939SAndy Fiddaman		'^'   0 0 0   0 0 0      1 1 1   1 1 1   \
268*b30d1939SAndy Fiddaman		# retain this line #
269*b30d1939SAndy Fiddaman	while	(( $# >= 13 ))
270*b30d1939SAndy Fiddaman	do	c=$1
271*b30d1939SAndy Fiddaman		shift
272*b30d1939SAndy Fiddaman		for p in \
273*b30d1939SAndy Fiddaman			'[![.-.]]' \
274*b30d1939SAndy Fiddaman			'[![.-.][:upper:]]' \
275*b30d1939SAndy Fiddaman			'[![.-.]A-Z]' \
276*b30d1939SAndy Fiddaman			'[!-]' \
277*b30d1939SAndy Fiddaman			'[!-[:upper:]]' \
278*b30d1939SAndy Fiddaman			'[!-A-Z]' \
279*b30d1939SAndy Fiddaman			'[[.-.]]' \
280*b30d1939SAndy Fiddaman			'[[.-.][:upper:]]' \
281*b30d1939SAndy Fiddaman			'[[.-.]A-Z]' \
282*b30d1939SAndy Fiddaman			'[-]' \
283*b30d1939SAndy Fiddaman			'[-[:upper:]]' \
284*b30d1939SAndy Fiddaman			'[-A-Z]' \
285*b30d1939SAndy Fiddaman			# retain this line #
286*b30d1939SAndy Fiddaman		do	e=$1
287*b30d1939SAndy Fiddaman			shift
288*b30d1939SAndy Fiddaman			[[ $c == $p ]]
289*b30d1939SAndy Fiddaman			g=$?
290*b30d1939SAndy Fiddaman			[[ $g == $e ]] || err_exit "[[ '$c' == $p ]] for LC_COLLATE=$l failed -- expected $e, got $g"
291*b30d1939SAndy Fiddaman		done
292*b30d1939SAndy Fiddaman	done
293*b30d1939SAndy Fiddamandone
294*b30d1939SAndy Fiddamaninteger n
295*b30d1939SAndy Fiddamanif	( : < /dev/tty ) 2>/dev/null && exec {n}< /dev/tty
296*b30d1939SAndy Fiddamanthen	[[ -t  $n ]] || err_exit "[[ -t  n ]] fails when n > 9"
297*b30d1939SAndy Fiddamanfi
298*b30d1939SAndy Fiddamanfoo=([1]=a [2]=b [3]=c)
299*b30d1939SAndy Fiddaman[[ -v foo[1] ]] ||  err_exit 'foo[1] should be set'
300*b30d1939SAndy Fiddaman[[ ${foo[1]+x} ]] ||  err_exit '${foo[1]+x} should be x'
301*b30d1939SAndy Fiddaman[[ ${foo[@]+x} ]] ||  err_exit '${foo[@]+x} should be x'
302*b30d1939SAndy Fiddamanunset foo[1]
303*b30d1939SAndy Fiddaman[[ -v foo[1] ]] && err_exit 'foo[1] should not be set'
304*b30d1939SAndy Fiddaman[[ ${foo[1]+x} ]] &&  err_exit '${foo[1]+x} should be empty'
305*b30d1939SAndy Fiddamanbar=(a b c)
306*b30d1939SAndy Fiddaman[[ -v bar[1] ]]  || err_exit 'bar[1] should be set'
307*b30d1939SAndy Fiddaman[[ ${bar[1]+x} ]] ||  err_exit '${foo[1]+x} should be x'
308*b30d1939SAndy Fiddamanunset bar[1]
309*b30d1939SAndy Fiddaman[[ ${bar[1]+x} ]] &&  err_exit '${foo[1]+x} should be empty'
310*b30d1939SAndy Fiddaman[[ -v bar ]] || err_exit 'bar should be set'
311*b30d1939SAndy Fiddaman[[ -v bar[1] ]] && err_exit 'bar[1] should not be set'
312*b30d1939SAndy Fiddamaninteger z=( 1 2 4)
313*b30d1939SAndy Fiddaman[[ -v z[1] ]] || err_exit 'z[1] should be set'
314*b30d1939SAndy Fiddamanunset z[1]
315*b30d1939SAndy Fiddaman[[ -v z[1] ]] && err_exit 'z[1] should not be set'
316*b30d1939SAndy Fiddamantypeset -si y=( 1 2 4)
317*b30d1939SAndy Fiddaman[[ -v y[6] ]] && err_exit 'y[6] should not be set'
318*b30d1939SAndy Fiddaman[[ -v y[1] ]] ||  err_exit  'y[1] should be set'
319*b30d1939SAndy Fiddamanunset y[1]
320*b30d1939SAndy Fiddaman[[ -v y[1] ]] && err_exit 'y[1] should not be set'
321*b30d1939SAndy Fiddamanx=abc
322*b30d1939SAndy Fiddaman[[ -v x[0] ]] || err_exit  'x[0] should be set'
323*b30d1939SAndy Fiddaman[[ ${x[0]+x} ]] || err_exit print  '${x[0]+x} should be x'
324*b30d1939SAndy Fiddaman[[ -v x[3] ]] && err_exit 'x[3] should not be set'
325*b30d1939SAndy Fiddaman[[ ${x[3]+x} ]] && err_exit  '${x[0]+x} should be Empty'
326*b30d1939SAndy Fiddamanunset x
327*b30d1939SAndy Fiddaman[[ ${x[@]+x} ]] && err_exit  '${x[@]+x} should be Empty'
328*b30d1939SAndy Fiddamanunset x y z foo bar
329*b30d1939SAndy Fiddaman
330*b30d1939SAndy Fiddaman{ x=$($SHELL -c '[[ (( $# -eq 0 )) ]] && print ok') 2> /dev/null;}
331*b30d1939SAndy Fiddaman[[ $x == ok ]] || err_exit '((...)) inside [[...]] not treated as nested ()'
332*b30d1939SAndy Fiddaman
333*b30d1939SAndy Fiddaman[[ -e /dev/fd/ ]] || err_exit '/dev/fd/ does not exits'
334*b30d1939SAndy Fiddaman[[ -e /dev/tcp/ ]] || err_exit '/dev/tcp/ does not exist'
335*b30d1939SAndy Fiddaman[[ -e /dev/udp/ ]] || err_exit '/dev/udp/ does not exist'
336*b30d1939SAndy Fiddaman[[ -e /dev/xxx/ ]] &&  err_exit '/dev/xxx/ exists'
337*b30d1939SAndy Fiddaman
338*b30d1939SAndy Fiddaman$SHELL 2> /dev/null -c '[[(-n foo)]]' || err_exit '[[(-n foo)]] should not require space in front of ('
339*b30d1939SAndy Fiddaman
340*b30d1939SAndy Fiddaman$SHELL 2> /dev/null -c '[[ "]" == ~(E)[]] ]]' || err_exit 'pattern "~(E)[]]" does not match "]"'
341*b30d1939SAndy Fiddaman
342*b30d1939SAndy Fiddamanunset var
343*b30d1939SAndy Fiddaman[[ -v var ]] &&  err_exit '[[ -v var ]] should be false after unset var'
344*b30d1939SAndy Fiddamanfloat var
345*b30d1939SAndy Fiddaman[[ -v var ]]  ||  err_exit '[[ -v var ]] should be true after float var'
346*b30d1939SAndy Fiddamanunset var
347*b30d1939SAndy Fiddaman[[ -v var ]] &&  err_exit '[[ -v var ]] should be false after unset var again'
348*b30d1939SAndy Fiddaman
349*b30d1939SAndy Fiddamantest ! ! ! 2> /dev/null || err_exit 'test ! ! ! should return 0'
350*b30d1939SAndy Fiddamantest ! ! x 2> /dev/null || err_exit 'test ! ! x should return 0'
351*b30d1939SAndy Fiddamantest ! ! '' 2> /dev/null && err_exit 'test ! ! "" should return non-zero'
352*b30d1939SAndy Fiddaman
353*b30d1939SAndy Fiddamanexit $((Errors<125?Errors:125))
354