legacy_test.sh revision 16491
1#!/bin/sh 2# (c) Wolfram Schneider, Berlin. June 1996. Public domain. 3# 4# TEST.sh - check if test(1) or builtin test works 5# 6# $Id: $ 7 8# force a specified test program, e.g. `env test=/bin/test sh TEST.sh' 9: ${test=test} 10 11ERROR=0 FAILED=0 12 13t () 14{ 15 # $1 -> exit code 16 # $2 -> $test expression 17 18 echo -n "$test $2 " 19 20 # check for syntax errors 21 syntax="`eval $test $2 2>&1`" 22 if test -z "$syntax"; then 23 24 case $1 in 25 0) if eval $test $2; then echo " OK"; else failed;fi;; 26 1) if eval $test $2; then failed; else echo " OK";fi;; 27 esac 28 29 else 30 error 31 fi 32} 33 34error () 35{ 36 echo ""; echo " $syntax" 37 ERROR=`expr $ERROR + 1` 38} 39 40failed () 41{ 42 echo ""; echo " failed" 43 FAILED=`expr $FAILED + 1` 44} 45 46 47t 0 'b = b' 48t 1 'b != b' 49t 0 '\( b = b \)' 50t 1 '! \( b = b \)' 51t 1 '! -f /etc/passwd' 52 53t 0 '-h = -h' 54t 0 '-o = -o' 55 56t 1 '-f = h' 57t 1 '-h = f' 58t 1 '-o = f' 59t 1 'f = -o' 60t 0 '\( -h = -h \)' 61t 1 '\( a = -h \)' 62t 1 '\( -f = h \)' 63 64 65t 1 '\( -f = h \)' 66 67t 0 '-h = -h -o a' 68t 0 '\( -h = -h \) -o 1' 69 70t 0 '-h = -h -o -h = -h' 71t 0 '\( -h = -h \) -o \( -h = -h \)' 72 73t 0 '-d /' 74t 0 '-d / -a a != b' 75t 1 '-z "-z"' 76t 0 '-n -n' 77t 0 '0 -eq 0' 78t 0 '\( 0 -eq 0 \)' 79t 1 '1 -eq 0 -o a = a -a 1 -eq 0 -o a = aa' 80 81t 0 '0' 82t 0 '\( 0 \)' 83t 0 '-E' 84t 0 '-X -a -X' 85t 0 '-XXX' 86t 0 '\( -E \)' 87t 0 'true -o X' 88t 0 'true -o -X' 89t 0 '\( \( \( a = a \) -o 1 \) -a 1 \) -a true' 90t 1 '-h /' 91t 0 '-r /' 92t 1 '-w /' 93t 0 '-x /bin/sh' 94t 0 '-c /dev/null' 95t 0 '-b /dev/fd0a -o -b /dev/rfd0a -o true' 96t 0 '-f /etc/passwd' 97t 0 '-s /etc/passwd' 98t 1 '! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)' 99t 0 '100 -eq 100' 100t 0 '100 -lt 200' 101t 1 '1000 -lt 200' 102t 0 '1000 -gt 200' 103t 0 '1000 -ge 200' 104t 0 '1000 -ge 1000' 105t 1 '2 -ne 2' 106 107echo "" 108echo "Syntax errors: $ERROR Failed: $FAILED" 109 110