14887Schin######################################################################## 24887Schin# # 34887Schin# This software is part of the ast package # 4*8462SApril.Chin@Sun.COM# Copyright (c) 1982-2008 AT&T Intellectual Property # 54887Schin# and is licensed under the # 64887Schin# Common Public License, Version 1.0 # 7*8462SApril.Chin@Sun.COM# by AT&T Intellectual Property # 84887Schin# # 94887Schin# A copy of the License is available at # 104887Schin# http://www.opensource.org/licenses/cpl1.0.txt # 114887Schin# (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) # 124887Schin# # 134887Schin# Information and Software Systems Research # 144887Schin# AT&T Research # 154887Schin# Florham Park NJ # 164887Schin# # 174887Schin# David Korn <dgk@research.att.com> # 184887Schin# # 194887Schin######################################################################## 204887Schinfunction err_exit 214887Schin{ 224887Schin print -u2 -n "\t" 234887Schin print -u2 -r ${Command}[$1]: "${@:2}" 244887Schin let Errors+=1 254887Schin} 264887Schinalias err_exit='err_exit $LINENO' 274887Schin 284887SchinCommand=${0##*/} 294887Schininteger Errors=0 304887Schinnull='' 314887Schinif [[ ! -z $null ]] 324887Schinthen err_exit "-z: null string should be of zero length" 334887Schinfi 34*8462SApril.Chin@Sun.COMfile=/tmp/regresso$$ 35*8462SApril.Chin@Sun.COMnewer_file=/tmp/regressn$$ 364887Schinif [[ -z $file ]] 374887Schinthen err_exit "-z: $file string should not be of zero length" 384887Schinfi 39*8462SApril.Chin@Sun.COMtrap "rm -f $file $newer_file" EXIT 404887Schinrm -f $file 414887Schinif [[ -a $file ]] 424887Schinthen err_exit "-a: $file shouldn't exist" 434887Schinfi 444887Schin> $file 454887Schinif [[ ! -a $file ]] 464887Schinthen err_exit "-a: $file should exist" 474887Schinfi 484887Schinchmod 777 $file 494887Schinif [[ ! -r $file ]] 504887Schinthen err_exit "-r: $file should be readable" 514887Schinfi 524887Schinif [[ ! -w $file ]] 534887Schinthen err_exit "-w: $file should be writable" 544887Schinfi 554887Schinif [[ ! -w $file ]] 564887Schinthen err_exit "-x: $file should be executable" 574887Schinfi 584887Schinif [[ ! -w $file || ! -r $file ]] 594887Schinthen err_exit "-rw: $file should be readable/writable" 604887Schinfi 614887Schinif [[ -s $file ]] 624887Schinthen err_exit "-s: $file should be of zero size" 634887Schinfi 644887Schinif [[ ! -f $file ]] 654887Schinthen err_exit "-f: $file should be an ordinary file" 664887Schinfi 674887Schinif [[ -d $file ]] 684887Schinthen err_exit "-f: $file should not be a directory file" 694887Schinfi 704887Schinif [[ ! -d . ]] 714887Schinthen err_exit "-d: . should not be a directory file" 724887Schinfi 734887Schinif [[ -f /dev/null ]] 744887Schinthen err_exit "-f: /dev/null should not be an ordinary file" 754887Schinfi 764887Schinchmod 000 $file 774887Schinif [[ -r $file ]] 784887Schinthen err_exit "-r: $file should not be readable" 794887Schinfi 804887Schinif [[ ! -O $file ]] 814887Schinthen err_exit "-r: $file should be owned by me" 824887Schinfi 834887Schinif [[ -w $file ]] 844887Schinthen err_exit "-w: $file should not be writable" 854887Schinfi 864887Schinif [[ -w $file ]] 874887Schinthen err_exit "-x: $file should not be executable" 884887Schinfi 894887Schinif [[ -w $file || -r $file ]] 904887Schinthen err_exit "-rw: $file should not be readable/writable" 914887Schinfi 924887Schinif [[ -z x && -z x || ! -z x ]] 934887Schinthen : 944887Schinelse err_exit " wrong precedence" 954887Schinfi 964887Schinif [[ -z x && (-z x || ! -z x) ]] 974887Schinthen err_exit " () grouping not working" 984887Schinfi 994887Schinif [[ foo < bar ]] 1004887Schinthen err_exit "foo comes before bar" 1014887Schinfi 1024887Schin[[ . -ef $(pwd) ]] || err_exit ". is not $PWD" 1034887Schinset -o allexport 1044887Schin[[ -o allexport ]] || err_exit '-o: did not set allexport option' 1054887Schinif [[ -n $null ]] 1064887Schinthen err_exit "'$null' has non-zero length" 1074887Schinfi 1084887Schinif [[ ! -r /dev/fd/0 ]] 1094887Schinthen err_exit "/dev/fd/0 not open for reading" 1104887Schinfi 1114887Schinif [[ ! -w /dev/fd/2 ]] 1124887Schinthen err_exit "/dev/fd/2 not open for writing" 1134887Schinfi 1144887Schinsleep 1 115*8462SApril.Chin@Sun.COM> $newer_file 116*8462SApril.Chin@Sun.COMif [[ ! $file -ot $newer_file ]] 117*8462SApril.Chin@Sun.COMthen err_exit "$file should be older than $newer_file" 1184887Schinfi 119*8462SApril.Chin@Sun.COMif [[ $file -nt $newer_file ]] 120*8462SApril.Chin@Sun.COMthen err_exit "$newer_file should be newer than $file" 1214887Schinfi 1224887Schinif [[ $file != /tmp/* ]] 1234887Schinthen err_exit "$file should match /tmp/*" 1244887Schinfi 1254887Schinif [[ $file = '/tmp/*' ]] 1264887Schinthen err_exit "$file should not equal /tmp/*" 1274887Schinfi 1284887Schin[[ ! ( ! -z $null && ! -z x) ]] || err_exit "negation and grouping" 1294887Schin[[ -z '' || -z '' || -z '' ]] || err_exit "three ors not working" 1304887Schin[[ -z '' && -z '' && -z '' ]] || err_exit "three ors not working" 1314887Schin(exit 8) 1324887Schinif [[ $? -ne 8 || $? -ne 8 ]] 1334887Schinthen err_exit 'value $? within [[...]]' 1344887Schinfi 1354887Schinx='(x' 1364887Schinif [[ '(x' != '('* ]] 1374887Schinthen err_exit " '(x' does not match '('* within [[...]]" 1384887Schinfi 1394887Schinif [[ '(x' != "("* ]] 1404887Schinthen err_exit ' "(x" does not match "("* within [[...]]' 1414887Schinfi 1424887Schinif [[ '(x' != \(* ]] 1434887Schinthen err_exit ' "(x" does not match \(* within [[...]]' 1444887Schinfi 1454887Schinif [[ 'x(' != *'(' ]] 1464887Schinthen err_exit " 'x(' does not match '('* within [[...]]" 1474887Schinfi 1484887Schinif [[ 'x&' != *'&' ]] 1494887Schinthen err_exit " 'x&' does not match '&'* within [[...]]" 1504887Schinfi 1514887Schinif [[ 'xy' = *'*' ]] 1524887Schinthen err_exit " 'xy' matches *'*' within [[...]]" 1534887Schinfi 1544887Schinif [[ 3 > 4 ]] 1554887Schinthen err_exit '3 < 4' 1564887Schinfi 1574887Schinif [[ 4 < 3 ]] 1584887Schinthen err_exit '3 > 4' 1594887Schinfi 1604887Schinif [[ 3x > 4x ]] 1614887Schinthen err_exit '3x < 4x' 1624887Schinfi 1634887Schinx='bin|dev|?' 1644887Schincd / 1654887Schinif [[ $(print $x) != "$x" ]] 1664887Schinthen err_exit 'extended pattern matching on command arguments' 1674887Schinfi 1684887Schinif [[ dev != $x ]] 1694887Schinthen err_exit 'extended pattern matching not working on variables' 1704887Schinfi 1714887Schinif [[ -u $SHELL ]] 1724887Schinthen err_exit "setuid on $SHELL" 1734887Schinfi 1744887Schinif [[ -g $SHELL ]] 1754887Schinthen err_exit "setgid on $SHELL" 1764887Schinfi 1774887Schintest -d . -a '(' ! -f . ')' || err_exit 'test not working' 1784887Schinif [[ '!' != ! ]] 1794887Schinthen err_exit 'quoting unary operator not working' 1804887Schinfi 181*8462SApril.Chin@Sun.COMtest \( -n x \) -o \( -n y \) 2> /dev/null || err_exit 'test ( -n x ) -o ( -n y) not working' 182*8462SApril.Chin@Sun.COMtest \( -n x \) -o -n y 2> /dev/null || err_exit 'test ( -n x ) -o -n y not working' 1834887Schinchmod 600 $file 1844887Schinexec 4> $file 1854887Schinprint -u4 foobar 1864887Schinif [[ ! -s $file ]] 1874887Schinthen err_exit "-s: $file should be non-zero" 1884887Schinfi 1894887Schinexec 4>&- 1904887Schinif [[ 011 -ne 11 ]] 1914887Schinthen err_exit "leading zeros in arithmetic compares not ignored" 1924887Schinfi 1934887Schin{ 1944887Schin set -x 1954887Schin [[ foo > bar ]] 1964887Schin} 2> /dev/null || { set +x; err_exit "foo<bar with -x enabled" ;} 1974887Schinset +x 1984887Schin( 1994887Schin eval "[[ (a) ]]" 2004887Schin) 2> /dev/null || err_exit "[[ (a) ]] not working" 2014887Schin> $file 2024887Schinchmod 4755 "$file" 2034887Schinif test -u $file && test ! -u $file 2044887Schinthen err_exit "test ! -u suidfile not working" 2054887Schinfi 2064887Schinfor i in '(' ')' '[' ']' 2074887Schindo [[ $i == $i ]] || err_exit "[[ $i != $i ]]" 2084887Schindone 2094887Schin( 2104887Schin [[ aaaa == {4}(a) ]] || err_exit 'aaaa != {4}(a)' 2114887Schin [[ aaaa == {2,5}(a) ]] || err_exit 'aaaa != {2,4}(a)' 2124887Schin [[ abcdcdabcd == {3,6}(ab|cd) ]] || err_exit 'abcdcdabcd == {3,4}(ab|cd)' 2134887Schin [[ abcdcdabcde == {5}(ab|cd)e ]] || err_exit 'abcdcdabcd == {5}(ab|cd)e' 2144887Schin) || err_exit 'Errors with {..}(...) patterns' 2154887Schin[[ D290.2003.02.16.temp == D290.+(2003.02.16).temp* ]] || err_exit 'pattern match bug with +(...)' 2164887Schinrm -rf $file 2174887Schin{ 2184887Schin[[ -N $file ]] && err_exit 'test -N /tmp/*: st_mtime>st_atime after creat' 2194887Schinsleep 2 2204887Schinprint 'hello world' 2214887Schin[[ -N $file ]] || err_exit 'test -N /tmp/*: st_mtime<=st_atime after write' 2224887Schinsleep 2 2234887Schinread 2244887Schin[[ -N $file ]] && err_exit 'test -N /tmp/*: st_mtime>st_atime after read' 2254887Schin} > $file < $file 2264887Schinif rm -rf "$file" && ln -s / "$file" 2274887Schinthen [[ -L "$file" ]] || err_exit '-L not working' 2284887Schin [[ -L "$file"/ ]] && err_exit '-L with file/ not working' 2294887Schinfi 2304887Schin$SHELL -c 't=1234567890; [[ $t == @({10}(\d)) ]]' 2> /dev/null || err_exit ' @({10}(\d)) pattern not working' 2314887Schin$SHELL -c '[[ att_ == ~(E)(att|cus)_.* ]]' 2> /dev/null || err_exit ' ~(E)(att|cus)_* pattern not working' 2324887Schin$SHELL -c '[[ att_ =~ (att|cus)_.* ]]' 2> /dev/null || err_exit ' =~ ere not working' 2334887Schin$SHELL -c '[[ abc =~ a(b)c ]]' 2> /dev/null || err_exit '[[ abc =~ a(b)c ]] fails' 2344887Schin$SHELL -xc '[[ abc =~ \babc\b ]]' 2> /dev/null || err_exit '[[ abc =~ \babc\b ]] fails' 2354887Schin[[ abc == ~(E)\babc\b ]] || err_exit '\b not preserved for ere when not in ()' 2364887Schin[[ abc == ~(iEi)\babc\b ]] || err_exit '\b not preserved for ~(iEi) when not in ()' 237*8462SApril.Chin@Sun.COM 238*8462SApril.Chin@Sun.COMe=$($SHELL -c '[ -z "" -a -z "" ]' 2>&1) 239*8462SApril.Chin@Sun.COM[[ $e ]] && err_exit "[ ... ] compatibility check failed -- $e" 240*8462SApril.Chin@Sun.COMi=hell 241*8462SApril.Chin@Sun.COM[[ hell0 == $i[0] ]] || err_exit 'pattern $i[0] interpreded as array ref' 242*8462SApril.Chin@Sun.COMtest '(' = ')' && err_exit '"test ( = )" should not be true' 243*8462SApril.Chin@Sun.COM[[ $($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*8462SApril.Chin@Sun.COM[[ $($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' 2454887Schinexit $((Errors)) 246