14887Schin######################################################################## 24887Schin# # 34887Schin# This software is part of the ast package # 4*10898Sroland.mainz@nrubsig.org# Copyright (c) 1982-2009 AT&T Intellectual Property # 54887Schin# and is licensed under the # 64887Schin# Common Public License, Version 1.0 # 78462SApril.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 30*10898Sroland.mainz@nrubsig.org 31*10898Sroland.mainz@nrubsig.orgtmp=$(mktemp -dt) || { err_exit mktemp -dt failed; exit 1; } 32*10898Sroland.mainz@nrubsig.orgtrap "cd /; rm -rf $tmp" EXIT 33*10898Sroland.mainz@nrubsig.org 344887Schinnull='' 354887Schinif [[ ! -z $null ]] 364887Schinthen err_exit "-z: null string should be of zero length" 374887Schinfi 38*10898Sroland.mainz@nrubsig.orgfile=$tmp/original 39*10898Sroland.mainz@nrubsig.orgnewer_file=$tmp/newer 404887Schinif [[ -z $file ]] 414887Schinthen err_exit "-z: $file string should not be of zero length" 424887Schinfi 434887Schinif [[ -a $file ]] 444887Schinthen err_exit "-a: $file shouldn't exist" 454887Schinfi 464887Schin> $file 474887Schinif [[ ! -a $file ]] 484887Schinthen err_exit "-a: $file should exist" 494887Schinfi 504887Schinchmod 777 $file 514887Schinif [[ ! -r $file ]] 524887Schinthen err_exit "-r: $file should be readable" 534887Schinfi 544887Schinif [[ ! -w $file ]] 554887Schinthen err_exit "-w: $file should be writable" 564887Schinfi 574887Schinif [[ ! -w $file ]] 584887Schinthen err_exit "-x: $file should be executable" 594887Schinfi 604887Schinif [[ ! -w $file || ! -r $file ]] 614887Schinthen err_exit "-rw: $file should be readable/writable" 624887Schinfi 634887Schinif [[ -s $file ]] 644887Schinthen err_exit "-s: $file should be of zero size" 654887Schinfi 664887Schinif [[ ! -f $file ]] 674887Schinthen err_exit "-f: $file should be an ordinary file" 684887Schinfi 694887Schinif [[ -d $file ]] 704887Schinthen err_exit "-f: $file should not be a directory file" 714887Schinfi 724887Schinif [[ ! -d . ]] 734887Schinthen err_exit "-d: . should not be a directory file" 744887Schinfi 754887Schinif [[ -f /dev/null ]] 764887Schinthen err_exit "-f: /dev/null should not be an ordinary file" 774887Schinfi 784887Schinchmod 000 $file 794887Schinif [[ -r $file ]] 804887Schinthen err_exit "-r: $file should not be readable" 814887Schinfi 824887Schinif [[ ! -O $file ]] 834887Schinthen err_exit "-r: $file should be owned by me" 844887Schinfi 854887Schinif [[ -w $file ]] 864887Schinthen err_exit "-w: $file should not be writable" 874887Schinfi 884887Schinif [[ -w $file ]] 894887Schinthen err_exit "-x: $file should not be executable" 904887Schinfi 914887Schinif [[ -w $file || -r $file ]] 924887Schinthen err_exit "-rw: $file should not be readable/writable" 934887Schinfi 944887Schinif [[ -z x && -z x || ! -z x ]] 954887Schinthen : 964887Schinelse err_exit " wrong precedence" 974887Schinfi 984887Schinif [[ -z x && (-z x || ! -z x) ]] 994887Schinthen err_exit " () grouping not working" 1004887Schinfi 1014887Schinif [[ foo < bar ]] 1024887Schinthen err_exit "foo comes before bar" 1034887Schinfi 1044887Schin[[ . -ef $(pwd) ]] || err_exit ". is not $PWD" 1054887Schinset -o allexport 1064887Schin[[ -o allexport ]] || err_exit '-o: did not set allexport option' 1074887Schinif [[ -n $null ]] 1084887Schinthen err_exit "'$null' has non-zero length" 1094887Schinfi 1104887Schinif [[ ! -r /dev/fd/0 ]] 1114887Schinthen err_exit "/dev/fd/0 not open for reading" 1124887Schinfi 1134887Schinif [[ ! -w /dev/fd/2 ]] 1144887Schinthen err_exit "/dev/fd/2 not open for writing" 1154887Schinfi 1164887Schinsleep 1 1178462SApril.Chin@Sun.COM> $newer_file 1188462SApril.Chin@Sun.COMif [[ ! $file -ot $newer_file ]] 1198462SApril.Chin@Sun.COMthen err_exit "$file should be older than $newer_file" 1204887Schinfi 1218462SApril.Chin@Sun.COMif [[ $file -nt $newer_file ]] 1228462SApril.Chin@Sun.COMthen err_exit "$newer_file should be newer than $file" 1234887Schinfi 124*10898Sroland.mainz@nrubsig.orgif [[ $file != $tmp/* ]] 125*10898Sroland.mainz@nrubsig.orgthen err_exit "$file should match $tmp/*" 1264887Schinfi 127*10898Sroland.mainz@nrubsig.orgif [[ $file = $tmp'/*' ]] 128*10898Sroland.mainz@nrubsig.orgthen err_exit "$file should not equal $tmp'/*'" 1294887Schinfi 1304887Schin[[ ! ( ! -z $null && ! -z x) ]] || err_exit "negation and grouping" 1314887Schin[[ -z '' || -z '' || -z '' ]] || err_exit "three ors not working" 1324887Schin[[ -z '' && -z '' && -z '' ]] || err_exit "three ors not working" 1334887Schin(exit 8) 1344887Schinif [[ $? -ne 8 || $? -ne 8 ]] 1354887Schinthen err_exit 'value $? within [[...]]' 1364887Schinfi 1374887Schinx='(x' 1384887Schinif [[ '(x' != '('* ]] 1394887Schinthen err_exit " '(x' does not match '('* within [[...]]" 1404887Schinfi 1414887Schinif [[ '(x' != "("* ]] 1424887Schinthen err_exit ' "(x" does not match "("* within [[...]]' 1434887Schinfi 1444887Schinif [[ '(x' != \(* ]] 1454887Schinthen err_exit ' "(x" does not match \(* within [[...]]' 1464887Schinfi 1474887Schinif [[ 'x(' != *'(' ]] 1484887Schinthen err_exit " 'x(' does not match '('* within [[...]]" 1494887Schinfi 1504887Schinif [[ 'x&' != *'&' ]] 1514887Schinthen err_exit " 'x&' does not match '&'* within [[...]]" 1524887Schinfi 1534887Schinif [[ 'xy' = *'*' ]] 1544887Schinthen err_exit " 'xy' matches *'*' within [[...]]" 1554887Schinfi 1564887Schinif [[ 3 > 4 ]] 1574887Schinthen err_exit '3 < 4' 1584887Schinfi 1594887Schinif [[ 4 < 3 ]] 1604887Schinthen err_exit '3 > 4' 1614887Schinfi 1624887Schinif [[ 3x > 4x ]] 1634887Schinthen err_exit '3x < 4x' 1644887Schinfi 1654887Schinx='bin|dev|?' 1664887Schincd / 1674887Schinif [[ $(print $x) != "$x" ]] 1684887Schinthen err_exit 'extended pattern matching on command arguments' 1694887Schinfi 1704887Schinif [[ dev != $x ]] 1714887Schinthen err_exit 'extended pattern matching not working on variables' 1724887Schinfi 1734887Schinif [[ -u $SHELL ]] 1744887Schinthen err_exit "setuid on $SHELL" 1754887Schinfi 1764887Schinif [[ -g $SHELL ]] 1774887Schinthen err_exit "setgid on $SHELL" 1784887Schinfi 1794887Schintest -d . -a '(' ! -f . ')' || err_exit 'test not working' 1804887Schinif [[ '!' != ! ]] 1814887Schinthen err_exit 'quoting unary operator not working' 1824887Schinfi 1838462SApril.Chin@Sun.COMtest \( -n x \) -o \( -n y \) 2> /dev/null || err_exit 'test ( -n x ) -o ( -n y) not working' 1848462SApril.Chin@Sun.COMtest \( -n x \) -o -n y 2> /dev/null || err_exit 'test ( -n x ) -o -n y not working' 1854887Schinchmod 600 $file 1864887Schinexec 4> $file 1874887Schinprint -u4 foobar 1884887Schinif [[ ! -s $file ]] 1894887Schinthen err_exit "-s: $file should be non-zero" 1904887Schinfi 1914887Schinexec 4>&- 1924887Schinif [[ 011 -ne 11 ]] 1934887Schinthen err_exit "leading zeros in arithmetic compares not ignored" 1944887Schinfi 1954887Schin{ 1964887Schin set -x 1974887Schin [[ foo > bar ]] 1984887Schin} 2> /dev/null || { set +x; err_exit "foo<bar with -x enabled" ;} 1994887Schinset +x 2004887Schin( 2014887Schin eval "[[ (a) ]]" 2024887Schin) 2> /dev/null || err_exit "[[ (a) ]] not working" 2034887Schin> $file 2044887Schinchmod 4755 "$file" 2054887Schinif test -u $file && test ! -u $file 2064887Schinthen err_exit "test ! -u suidfile not working" 2074887Schinfi 2084887Schinfor i in '(' ')' '[' ']' 2094887Schindo [[ $i == $i ]] || err_exit "[[ $i != $i ]]" 2104887Schindone 2114887Schin( 2124887Schin [[ aaaa == {4}(a) ]] || err_exit 'aaaa != {4}(a)' 2134887Schin [[ aaaa == {2,5}(a) ]] || err_exit 'aaaa != {2,4}(a)' 2144887Schin [[ abcdcdabcd == {3,6}(ab|cd) ]] || err_exit 'abcdcdabcd == {3,4}(ab|cd)' 2154887Schin [[ abcdcdabcde == {5}(ab|cd)e ]] || err_exit 'abcdcdabcd == {5}(ab|cd)e' 216*10898Sroland.mainz@nrubsig.org) || err_exit 'errors with {..}(...) patterns' 2174887Schin[[ D290.2003.02.16.temp == D290.+(2003.02.16).temp* ]] || err_exit 'pattern match bug with +(...)' 2184887Schinrm -rf $file 2194887Schin{ 220*10898Sroland.mainz@nrubsig.org[[ -N $file ]] && err_exit 'test -N $tmp/*: st_mtime>st_atime after creat' 2214887Schinsleep 2 2224887Schinprint 'hello world' 223*10898Sroland.mainz@nrubsig.org[[ -N $file ]] || err_exit 'test -N $tmp/*: st_mtime<=st_atime after write' 2244887Schinsleep 2 2254887Schinread 226*10898Sroland.mainz@nrubsig.org[[ -N $file ]] && err_exit 'test -N $tmp/*: st_mtime>st_atime after read' 2274887Schin} > $file < $file 2284887Schinif rm -rf "$file" && ln -s / "$file" 2294887Schinthen [[ -L "$file" ]] || err_exit '-L not working' 2304887Schin [[ -L "$file"/ ]] && err_exit '-L with file/ not working' 2314887Schinfi 2324887Schin$SHELL -c 't=1234567890; [[ $t == @({10}(\d)) ]]' 2> /dev/null || err_exit ' @({10}(\d)) pattern not working' 2334887Schin$SHELL -c '[[ att_ == ~(E)(att|cus)_.* ]]' 2> /dev/null || err_exit ' ~(E)(att|cus)_* pattern not working' 2344887Schin$SHELL -c '[[ att_ =~ (att|cus)_.* ]]' 2> /dev/null || err_exit ' =~ ere not working' 2354887Schin$SHELL -c '[[ abc =~ a(b)c ]]' 2> /dev/null || err_exit '[[ abc =~ a(b)c ]] fails' 2364887Schin$SHELL -xc '[[ abc =~ \babc\b ]]' 2> /dev/null || err_exit '[[ abc =~ \babc\b ]] fails' 2374887Schin[[ abc == ~(E)\babc\b ]] || err_exit '\b not preserved for ere when not in ()' 2384887Schin[[ abc == ~(iEi)\babc\b ]] || err_exit '\b not preserved for ~(iEi) when not in ()' 2398462SApril.Chin@Sun.COM 2408462SApril.Chin@Sun.COMe=$($SHELL -c '[ -z "" -a -z "" ]' 2>&1) 2418462SApril.Chin@Sun.COM[[ $e ]] && err_exit "[ ... ] compatibility check failed -- $e" 2428462SApril.Chin@Sun.COMi=hell 2438462SApril.Chin@Sun.COM[[ hell0 == $i[0] ]] || err_exit 'pattern $i[0] interpreded as array ref' 2448462SApril.Chin@Sun.COMtest '(' = ')' && err_exit '"test ( = )" should not be true' 2458462SApril.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' 2468462SApril.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' 247*10898Sroland.mainz@nrubsig.org 248*10898Sroland.mainz@nrubsig.orgfor l in C en_US.ISO8859-15 249*10898Sroland.mainz@nrubsig.orgdo [[ $($SHELL -c "LC_COLLATE=$l" 2>&1) ]] && continue 250*10898Sroland.mainz@nrubsig.org export LC_COLLATE=$l 251*10898Sroland.mainz@nrubsig.org set -- \ 252*10898Sroland.mainz@nrubsig.org 'A' 0 1 1 0 1 1 1 0 0 1 0 0 \ 253*10898Sroland.mainz@nrubsig.org 'Z' 0 1 1 0 1 1 1 0 0 1 0 0 \ 254*10898Sroland.mainz@nrubsig.org '/' 0 0 0 0 0 0 1 1 1 1 1 1 \ 255*10898Sroland.mainz@nrubsig.org '.' 0 0 0 0 0 0 1 1 1 1 1 1 \ 256*10898Sroland.mainz@nrubsig.org '_' 0 0 0 0 0 0 1 1 1 1 1 1 \ 257*10898Sroland.mainz@nrubsig.org '-' 1 1 1 1 1 1 0 0 0 0 0 0 \ 258*10898Sroland.mainz@nrubsig.org '%' 0 0 0 0 0 0 1 1 1 1 1 1 \ 259*10898Sroland.mainz@nrubsig.org '@' 0 0 0 0 0 0 1 1 1 1 1 1 \ 260*10898Sroland.mainz@nrubsig.org '!' 0 0 0 0 0 0 1 1 1 1 1 1 \ 261*10898Sroland.mainz@nrubsig.org '^' 0 0 0 0 0 0 1 1 1 1 1 1 \ 262*10898Sroland.mainz@nrubsig.org # retain this line # 263*10898Sroland.mainz@nrubsig.org while (( $# >= 13 )) 264*10898Sroland.mainz@nrubsig.org do c=$1 265*10898Sroland.mainz@nrubsig.org shift 266*10898Sroland.mainz@nrubsig.org for p in \ 267*10898Sroland.mainz@nrubsig.org '[![.-.]]' \ 268*10898Sroland.mainz@nrubsig.org '[![.-.][:upper:]]' \ 269*10898Sroland.mainz@nrubsig.org '[![.-.]A-Z]' \ 270*10898Sroland.mainz@nrubsig.org '[!-]' \ 271*10898Sroland.mainz@nrubsig.org '[!-[:upper:]]' \ 272*10898Sroland.mainz@nrubsig.org '[!-A-Z]' \ 273*10898Sroland.mainz@nrubsig.org '[[.-.]]' \ 274*10898Sroland.mainz@nrubsig.org '[[.-.][:upper:]]' \ 275*10898Sroland.mainz@nrubsig.org '[[.-.]A-Z]' \ 276*10898Sroland.mainz@nrubsig.org '[-]' \ 277*10898Sroland.mainz@nrubsig.org '[-[:upper:]]' \ 278*10898Sroland.mainz@nrubsig.org '[-A-Z]' \ 279*10898Sroland.mainz@nrubsig.org # retain this line # 280*10898Sroland.mainz@nrubsig.org do e=$1 281*10898Sroland.mainz@nrubsig.org shift 282*10898Sroland.mainz@nrubsig.org [[ $c == $p ]] 283*10898Sroland.mainz@nrubsig.org g=$? 284*10898Sroland.mainz@nrubsig.org [[ $g == $e ]] || err_exit "[[ '$c' == $p ]] for LC_COLLATE=$l failed -- expected $e, got $g" 285*10898Sroland.mainz@nrubsig.org done 286*10898Sroland.mainz@nrubsig.org done 287*10898Sroland.mainz@nrubsig.orgdone 288*10898Sroland.mainz@nrubsig.orginteger n 289*10898Sroland.mainz@nrubsig.orgif ( : < /dev/tty ) 2>/dev/null && exec {n}< /dev/tty 290*10898Sroland.mainz@nrubsig.orgthen [[ -t $n ]] || err_exit "[[ -t n ]] fails when n > 9" 291*10898Sroland.mainz@nrubsig.orgfi 292*10898Sroland.mainz@nrubsig.orgfoo=([1]=a [2]=b [3]=c) 293*10898Sroland.mainz@nrubsig.org[[ -v foo[1] ]] || err_exit 'foo[1] should be set' 294*10898Sroland.mainz@nrubsig.org[[ ${foo[1]+x} ]] || err_exit '${foo[1]+x} should be x' 295*10898Sroland.mainz@nrubsig.org[[ ${foo[@]+x} ]] || err_exit '${foo[@]+x} should be x' 296*10898Sroland.mainz@nrubsig.orgunset foo[1] 297*10898Sroland.mainz@nrubsig.org[[ -v foo[1] ]] && err_exit 'foo[1] should not be set' 298*10898Sroland.mainz@nrubsig.org[[ ${foo[1]+x} ]] && err_exit '${foo[1]+x} should be empty' 299*10898Sroland.mainz@nrubsig.orgbar=(a b c) 300*10898Sroland.mainz@nrubsig.org[[ -v bar[1] ]] || err_exit 'bar[1] should be set' 301*10898Sroland.mainz@nrubsig.org[[ ${bar[1]+x} ]] || err_exit '${foo[1]+x} should be x' 302*10898Sroland.mainz@nrubsig.orgunset bar[1] 303*10898Sroland.mainz@nrubsig.org[[ ${bar[1]+x} ]] && err_exit '${foo[1]+x} should be empty' 304*10898Sroland.mainz@nrubsig.org[[ -v bar ]] || err_exit 'bar should be set' 305*10898Sroland.mainz@nrubsig.org[[ -v bar[1] ]] && err_exit 'bar[1] should not be set' 306*10898Sroland.mainz@nrubsig.orginteger z=( 1 2 4) 307*10898Sroland.mainz@nrubsig.org[[ -v z[1] ]] || err_exit 'z[1] should be set' 308*10898Sroland.mainz@nrubsig.orgunset z[1] 309*10898Sroland.mainz@nrubsig.org[[ -v z[1] ]] && err_exit 'z[1] should not be set' 310*10898Sroland.mainz@nrubsig.orgtypeset -si y=( 1 2 4) 311*10898Sroland.mainz@nrubsig.org[[ -v y[6] ]] && err_exit 'y[6] should not be set' 312*10898Sroland.mainz@nrubsig.org[[ -v y[1] ]] || err_exit 'y[1] should be set' 313*10898Sroland.mainz@nrubsig.orgunset y[1] 314*10898Sroland.mainz@nrubsig.org[[ -v y[1] ]] && err_exit 'y[1] should not be set' 315*10898Sroland.mainz@nrubsig.orgx=abc 316*10898Sroland.mainz@nrubsig.org[[ -v x[0] ]] || err_exit 'x[0] should be set' 317*10898Sroland.mainz@nrubsig.org[[ ${x[0]+x} ]] || err_exit print '${x[0]+x} should be x' 318*10898Sroland.mainz@nrubsig.org[[ -v x[3] ]] && err_exit 'x[3] should not be set' 319*10898Sroland.mainz@nrubsig.org[[ ${x[3]+x} ]] && err_exit '${x[0]+x} should be Empty' 320*10898Sroland.mainz@nrubsig.orgunset x 321*10898Sroland.mainz@nrubsig.org[[ ${x[@]+x} ]] && err_exit '${x[@]+x} should be Empty' 322*10898Sroland.mainz@nrubsig.orgunset x y z foo bar 3234887Schinexit $((Errors)) 324