######################################################################## # # # This software is part of the ast package # # Copyright (c) 1982-2007 AT&T Knowledge Ventures # # and is licensed under the # # Common Public License, Version 1.0 # # by AT&T Knowledge Ventures # # # # A copy of the License is available at # # http://www.opensource.org/licenses/cpl1.0.txt # # (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) # # # # Information and Software Systems Research # # AT&T Research # # Florham Park NJ # # # # David Korn # # # ######################################################################## function err_exit { print -u2 -n "\t" print -u2 -r ${Command}[$1]: "${@:2}" ((errors++)) } alias err_exit='err_exit $LINENO' integer aware=0 contrary=0 ignorant=0 function test_glob { typeset lineno expected drop arg got sep op val add del if [[ $1 == --* ]] then del=${1#--} shift fi if [[ $1 == ++* ]] then add=${1#++} shift fi lineno=$1 expected=$2 shift 2 if (( contrary )) then if [[ $expected == " "* ]] then expected=${expected#" "} expected="$expected " fi if [[ $expected == *" "* ]] then expected=${expected/" "/" "} fi fi for arg do got="$got$sep<$arg>" sep=" " done if (( ignorant && aware )) then if [[ $del ]] then got="<$del> $got" fi if [[ $add ]] then expected="<$add> $expected" fi fi if [[ $got != "$expected" ]] then err_exit $lineno "glob: got '$got' expected '$expected'" fi } function test_case { typeset lineno expected subject pattern got lineno=$1 expected=$2 subject=$3 pattern=$4 eval " case $subject in $pattern) got='' ;; *) got='' ;; esac " if [[ $got != "$expected" ]] then err_exit $lineno "case $subject in $pattern) got '$got' expected '$expected'" fi } Command=${0##*/} tmp=/tmp/ksh$$ integer errors=0 unset undefined export LC_COLLATE=C mkdir $tmp || err_exit $LINENO "mkdir $tmp failed" trap "cd /; rm -rf $tmp" EXIT cd $tmp || err_exit $LINENO "cd $tmp failed" rm -rf * touch B b set -- * case $* in 'b B') contrary=1 ;; b|B) ignorant=1 ;; esac set -- $(/bin/sh -c 'echo [a-c]') case $* in B) aware=1 ;; esac rm -rf * touch a b c d abc abd abe bb bcd ca cb dd de Beware mkdir bdir test_glob $LINENO ' ' a* X* test_glob $LINENO ' ' \a* if ( set --nullglob ) 2>/dev/null then set --nullglob test_glob $LINENO ' ' a* X* set --nonullglob fi if ( set --failglob ) 2>/dev/null then set --failglob mkdir tmp touch tmp/l1 tmp/l2 tmp/l3 test_glob $LINENO '' tmp/l[12] tmp/*4 tmp/*3 test_glob $LINENO '' tmp/l[12] tmp/*4 tmp/*3 rm -r tmp set --nofailglob fi test_glob $LINENO '' b*/ test_glob $LINENO '<*>' \* test_glob $LINENO '' 'a*' test_glob $LINENO '' a\* test_glob $LINENO ' <*q*>' c* a\* *q* test_glob $LINENO '<**>' "*"* test_glob $LINENO '<**>' \** test_glob $LINENO '<\.\./*/>' "\.\./*/" test_glob $LINENO '' 's/\..*//' test_glob $LINENO '' "/^root:/{s/^[!:]*:[!:]*:\([!:]*\).*"'$'"/\1/" test_glob $LINENO ' ' [a-c]b* test_glob ++Beware $LINENO '
' [a-y]*[!c] test_glob $LINENO ' ' a*[!c] touch a-b aXb test_glob $LINENO ' ' a[X-]b touch .x .y test_glob --Beware $LINENO '
' [!a-c]* if mkdir a\*b 2>/dev/null then touch a\*b/ooo test_glob $LINENO '' a\*b/* test_glob $LINENO '' a\*?/* test_case $LINENO '' '!7' '*\!*' test_case $LINENO '' 'r.*' '*.\*' test_glob $LINENO '' a[b]c test_glob $LINENO '' a["b"]c test_glob $LINENO '' a[\b]c test_glob $LINENO '' a?c test_case $LINENO '' 'abc' 'a"b"c' test_case $LINENO '' 'abc' 'a*c' test_case $LINENO '' 'abc' '"a?c"' test_case $LINENO '' 'abc' 'a\*c' test_case $LINENO '' 'abc' 'a\[b]c' test_case $LINENO '' '"$undefined"' '""' test_case $LINENO '' 'abc' 'a["\b"]c' rm -rf mkdir a\*b fi mkdir man mkdir man/man1 touch man/man1/sh.1 test_glob $LINENO '' */man*/sh.* test_glob $LINENO '' $(echo */man*/sh.*) test_glob $LINENO '' "$(echo */man*/sh.*)" test_case $LINENO '' 'abc' 'a***c' test_case $LINENO '' 'abc' 'a*****?c' test_case $LINENO '' 'abc' '?*****??' test_case $LINENO '' 'abc' '*****??' test_case $LINENO '' 'abc' '*****??c' test_case $LINENO '' 'abc' '?*****?c' test_case $LINENO '' 'abc' '?***?****c' test_case $LINENO '' 'abc' '?***?****?' test_case $LINENO '' 'abc' '?***?****' test_case $LINENO '' 'abc' '*******c' test_case $LINENO '' 'abc' '*******?' test_case $LINENO '' 'abcdecdhjk' 'a*cd**?**??k' test_case $LINENO '' 'abcdecdhjk' 'a**?**cd**?**??k' test_case $LINENO '' 'abcdecdhjk' 'a**?**cd**?**??k***' test_case $LINENO '' 'abcdecdhjk' 'a**?**cd**?**??***k' test_case $LINENO '' 'abcdecdhjk' 'a**?**cd**?**??***k**' test_case $LINENO '' 'abcdecdhjk' 'a****c**?**??*****' test_case $LINENO '' "'-'" '[-abc]' test_case $LINENO '' "'-'" '[abc-]' test_case $LINENO '' "'\\'" '\\' test_case $LINENO '' "'\\'" '[\\]' test_case $LINENO '' "'\\'" "'\\'" test_case $LINENO '' "'['" '[[]' test_case $LINENO '' '[' '[[]' test_case $LINENO '' "'['" '[' test_case $LINENO '' '[' '[' test_case $LINENO '' "'[abc'" "'['*" test_case $LINENO '' "'[abc'" '[*' test_case $LINENO '' '[abc' "'['*" test_case $LINENO '' '[abc' '[*' test_case $LINENO '' 'abd' "a[b/c]d" test_case $LINENO '' 'a/d' "a[b/c]d" test_case $LINENO '' 'acd' "a[b/c]d" test_case $LINENO '' "']'" '[]]' test_case $LINENO '' "'-'" '[]-]' test_case $LINENO '' 'p' '[a-\z]' test_case $LINENO '' '"/tmp"' '[/\\]*' test_case $LINENO '' 'abc' '??**********?****?' test_case $LINENO '' 'abc' '??**********?****c' test_case $LINENO '' 'abc' '?************c****?****' test_case $LINENO '' 'abc' '*c*?**' test_case $LINENO '' 'abc' 'a*****c*?**' test_case $LINENO '' 'abc' 'a********???*******' test_case $LINENO '' "'a'" '[]' test_case $LINENO '' 'a' '[]' test_case $LINENO '' "'['" '[abc' test_case $LINENO '' '[' '[abc' test_glob ++Beware $LINENO ' ' b* test_glob $LINENO ' ' [bB]* if ( set --nocaseglob ) 2>/dev/null then set --nocaseglob test_glob $LINENO ' ' b* test_glob $LINENO ' ' [b]* test_glob $LINENO ' ' [bB]* set --nonocaseglob fi if ( set -f ) 2>/dev/null then set -f test_glob $LINENO '<*>' * set +f fi if ( set --noglob ) 2>/dev/null then set --noglob test_glob $LINENO '<*>' * set --glob fi FIGNORE='.*|*' test_glob $LINENO '<*>' * FIGNORE='.*|*c|*e|?' test_glob $LINENO '
' * FIGNORE='.*|*b|*d|?' test_glob $LINENO ' ' * FIGNORE= test_glob $LINENO '' */man*/sh.* unset FIGNORE test_glob $LINENO '
' ?? test_glob $LINENO '' */man*/sh.* GLOBIGNORE='.*:*' set -- * if [[ $1 == '*' ]] then GLOBIGNORE='.*:*c:*e:?' test_glob $LINENO '<>' * GLOBIGNORE='.*:*b:*d:?' test_glob $LINENO '<>' * unset GLOBIGNORE test_glob $LINENO '<>' * test_glob $LINENO '' */man*/sh.* GLOBIGNORE= test_glob $LINENO '' */man*/sh.* fi exit $errors