1 #!/bin/bash 2 3 [ -f testing.sh ] && . testing.sh 4 5 #testing "name" "command" "result" "infile" "stdin" 6 7 # TODO: Should also have device and socket files 8 9 mkdir d 10 touch f 11 ln -s /dev/null L 12 echo nonempty > s 13 mkfifo p 14 15 type_test() 16 { 17 result="" 18 for i in d f L s p n 19 do 20 if test $* $i 21 then 22 result=$result$i 23 fi 24 done 25 printf "%s" $result 26 } 27 28 testing "test -b" "type_test -b" "" "" "" 29 testing "test -c" "type_test -c" "L" "" "" 30 testing "test -d" "type_test -d" "d" "" "" 31 testing "test -f" "type_test -f" "fs" "" "" 32 testing "test -h" "type_test -h" "L" "" "" 33 testing "test -L" "type_test -L" "L" "" "" 34 testing "test -s" "type_test -s" "ds" "" "" 35 testing "test -S" "type_test -S" "" "" "" 36 testing "test -p" "type_test -p" "p" "" "" 37 testing "test -e" "type_test -e" "dfLsp" "" "" 38 testing "test ! -e" "type_test ! -e" "n" "" "" 39 40 rm f L s p 41 rmdir d 42 43 # TODO: Test rwx gu t 44 45 testing "test" "test "" || test a && echo yes" "yes\n" "" "" 46 testing "test -n" "test -n "" || test -n a && echo yes" "yes\n" "" "" 47 testing "test -z" "test -n a || test -n "" && echo yes" "yes\n" "" "" 48 testing "test a = b" "test a = b || test "" = "" && echo yes" "yes\n" "" "" 49 testing "test a != b" "test "" != "" || test a = b && echo yes" "yes\n" "" "" 50 51 arith_test() 52 { 53 test -1 $1 1 && echo l 54 test 0 $1 0 && echo e 55 test -3 $1 -5 && echo g 56 } 57 58 testing "test -eq" "arith_test -eq" "e\n" "" "" 59 testing "test -ne" "arith_test -ne" "l\ng\n" "" "" 60 testing "test -gt" "arith_test -gt" "g\n" "" "" 61 testing "test -ge" "arith_test -ge" "e\ng\n" "" "" 62 testing "test -lt" "arith_test -lt" "l\n" "" "" 63 testing "test -le" "arith_test -le" "l\ne\n" "" "" 64 65 # test ! = -o a 66 # test ! \( = -o a \) 67 # test \( ! = \) -o a 68