Annotation of coherent/b/bin/triptest, revision 1.1

1.1     ! root        1: # A collection of both regular and pathological input for "test"
        !             2: # In order to test out things like -p and -K we need to be root, so those
        !             3: # things are not tested yet. We are more interested in the range of valid
        !             4: # expressions that "test" can parse.
        !             5: 
        !             6: if [ $1 ]
        !             7: then   TEST=$1
        !             8: else   TEST=/bin/test
        !             9: fi
        !            10: 
        !            11: STRING_BINARIES='= != < >'
        !            12: ARITH_BINARIES="-eq -ne -lt -gt -le -ge"
        !            13: NS_FILE_BINARIES="-ef -nt -ot"
        !            14: 
        !            15: STRING_UNARIES="-z -n !"
        !            16: FILE_UNARIES="-r -w -x -t -b -c -d -p -f -g -u -s"
        !            17: NS_FILE_UNARIES="-K -L"
        !            18: 
        !            19: LPAREN="\("
        !            20: RPAREN="\)"
        !            21: 
        !            22: ALL_OPS="$STRING_BINARIES $ARITH_BINARIES $NS_FILE_BINARIES $STRING_UNARIES\
        !            23:        $FILE_UNARIES $NS_FILE_UNARIES $LPAREN $RPAREN"
        !            24: 
        !            25: OLD_FILE=`which test`
        !            26: NEW_FILE=/tmp/newfile
        !            27: 
        !            28: >$NEW_FILE                     # create the new file
        !            29: 
        !            30: xtest () {
        !            31:        $TEST "$@"; A=$?
        !            32:        if [ $# -gt 0 ]; then
        !            33:                $TEST ! \( "$@" \); B="negated as $?"
        !            34:        else    B=
        !            35:        fi
        !            36:        echo test "$@" "-->" $A $B
        !            37: }
        !            38: 
        !            39: echo Testing pathological cases
        !            40: 
        !            41: xtest \( "" \)                 # => ( -n "" )
        !            42: xtest \( -a \) = \)            # => -n ")" -a ( ")" = ")" )
        !            43: xtest \( = \)                  # 0 => ( -n "!=" )
        !            44:                                # 1 => "(" != ")"
        !            45: xtest \( -a = -o \)            # 1 => ( "-a" = "-o" )
        !            46:                                # 0 => -n "(" -a -n "=" -o -n ")"
        !            47: 
        !            48: echo Testing simple predicates
        !            49: 
        !            50: xtest
        !            51: xtest ""
        !            52: xtest "a"
        !            53: xtest "!"
        !            54: 
        !            55: echo Testing file comparisons
        !            56: 
        !            57: for l in $OLD_FILE $NEW_FILE; do
        !            58:        for r in $OLD_FILE $NEW_FILE; do
        !            59:                for op in $NS_FILE_BINARIES; do
        !            60:                        xtest $l $op $r
        !            61:                done
        !            62:        done
        !            63: done
        !            64: 
        !            65: echo Testing precedence and associativity
        !            66: 
        !            67: xtest ! "" -o "a"              # good 0 => ( ! "" ) -o "a"
        !            68:                                #  bad 1 => ! ( "" -o "a" )
        !            69: xtest "" -o ! ""
        !            70: 
        !            71: xtest ! "" -a "a"              # good 0 => ( ! "" ) -a "a"
        !            72:                                #  bad 1 => ! ("" -a "a")
        !            73: xtest "a" -a ! ""
        !            74: 
        !            75: xtest "" -a "" -o "a"          # good 0 => ( "" -a "" ) -o "a"
        !            76:                                #  bad 1 => "" -a ( "" -o "a" )
        !            77: xtest "a" -o "" -a ""
        !            78: 
        !            79: echo Testing simple arithmetic
        !            80: 
        !            81: for l in 1 2; do
        !            82:        for r in 1 2; do
        !            83:                for op in $ARITH_BINARIES; do
        !            84:                        xtest $l $op $r
        !            85:                done
        !            86:        done
        !            87: done
        !            88: 
        !            89: echo Testing simple string operations.
        !            90: 
        !            91: TEST_OPS="$STRING_BINARIES $STRING_UNARIES $LPAREN $RPAREN"
        !            92: 
        !            93: for l in $TEST_OPS; do
        !            94:        for r in $TEST_OPS; do
        !            95:                for op in $STRING_BINARIES; do
        !            96:                        xtest $l $op $r
        !            97:                done
        !            98:        done
        !            99: done

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.