1#!/bin/sh 2 3#- 4# Copyright (c) June 1996 Wolfram Schneider <wosch@FreeBSD.org>. Berlin. 5# All rights reserved. 6# 7# Redistribution and use in source and binary forms, with or without 8# modification, are permitted provided that the following conditions 9# are met: 10# 1. Redistributions of source code must retain the above copyright 11# notice, this list of conditions and the following disclaimer. 12# 2. Redistributions in binary form must reproduce the above copyright 13# notice, this list of conditions and the following disclaimer in the 14# documentation and/or other materials provided with the distribution. 15# 16# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 17# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 18# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 19# ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 20# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 21# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 22# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 23# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 24# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 25# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 26# SUCH DAMAGE. 27 28# 29# TEST.sh - check if test(1) or builtin test works 30# 31# $FreeBSD$ 32 33# force a specified test program, e.g. `env test=/bin/test sh regress.sh' 34: ${test=test} 35 36t () 37{ 38 # $1 -> exit code 39 # $2 -> $test expression 40 41 count=$((count+1)) 42 # check for syntax errors 43 syntax="`eval $test $2 2>&1`" 44 ret=$? 45 if test -n "$syntax"; then 46 printf "not ok %s - (syntax error)\n" "$count $2" 47 elif [ "$ret" != "$1" ]; then 48 printf "not ok %s - (got $ret, expected $1)\n" "$count $2" 49 else 50 printf "ok %s\n" "$count $2" 51 fi 52} 53 54count=0 55echo "1..130" 56 57t 0 'b = b' 58t 0 'b == b' 59t 1 'b != b' 60t 0 '\( b = b \)' 61t 0 '\( b == b \)' 62t 1 '! \( b = b \)' 63t 1 '! \( b == b \)' 64t 1 '! -f /etc/passwd' 65 66t 0 '-h = -h' 67t 0 '-o = -o' 68t 1 '-f = h' 69t 1 '-h = f' 70t 1 '-o = f' 71t 1 'f = -o' 72t 0 '\( -h = -h \)' 73t 1 '\( a = -h \)' 74t 1 '\( -f = h \)' 75t 0 '-h = -h -o a' 76t 0 '\( -h = -h \) -o 1' 77t 0 '-h = -h -o -h = -h' 78t 0 '\( -h = -h \) -o \( -h = -h \)' 79t 0 'roedelheim = roedelheim' 80t 1 'potsdam = berlin-dahlem' 81 82t 0 '-d /' 83t 0 '-d / -a a != b' 84t 1 '-z "-z"' 85t 0 '-n -n' 86 87t 0 '0' 88t 0 '\( 0 \)' 89t 0 '-E' 90t 0 '-X -a -X' 91t 0 '-XXX' 92t 0 '\( -E \)' 93t 0 'true -o X' 94t 0 'true -o -X' 95t 0 '\( \( \( a = a \) -o 1 \) -a 1 \) -a true' 96t 1 '-h /' 97t 0 '-r /' 98t 1 '-w /' 99t 0 '-x /bin/sh' 100t 0 '-c /dev/null' 101t 0 '-f /etc/passwd' 102t 0 '-s /etc/passwd' 103 104t 1 '! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)' 105t 0 '100 -eq 100' 106t 0 '100 -lt 200' 107t 1 '1000 -lt 200' 108t 0 '1000 -gt 200' 109t 0 '1000 -ge 200' 110t 0 '1000 -ge 1000' 111t 1 '2 -ne 2' 112t 0 '0 -eq 0' 113t 1 '-5 -eq 5' 114t 0 '\( 0 -eq 0 \)' 115t 1 '1 -eq 0 -o a = a -a 1 -eq 0 -o a = aa' 116 117t 1 '"" -o ""' 118t 1 '"" -a ""' 119t 1 '"a" -a ""' 120t 0 '"a" -a ! ""' 121t 1 '""' 122t 0 '! ""' 123 124t 0 '!' 125t 0 '\(' 126t 0 '\)' 127 128t 1 '\( = \)' 129t 0 '\( != \)' 130t 0 '\( ! \)' 131t 0 '\( \( \)' 132t 0 '\( \) \)' 133t 0 '! = !' 134t 1 '! != !' 135t 1 '-n = \)' 136t 0 '! != \)' 137t 1 '! = a' 138t 0 '! != -n' 139t 0 '! -c /etc/passwd' 140 141t 1 '! = = =' 142t 0 '! = = \)' 143t 0 '! "" -o ""' 144t 1 '! "x" -o ""' 145t 1 '! "" -o "x"' 146t 1 '! "x" -o "x"' 147t 0 '\( -f /etc/passwd \)' 148t 0 '\( ! "" \)' 149t 1 '\( ! -e \)' 150 151t 0 '0 -eq 0 -a -d /' 152t 0 '-s = "" -o "" = ""' 153t 0 '"" = "" -o -s = ""' 154t 1 '-s = "" -o -s = ""' 155t 0 '-z x -o x = "#" -o x = x' 156t 1 '-z y -o y = "#" -o y = x' 157t 0 '0 -ne 0 -o ! -f /' 158t 0 '1 -ne 0 -o ! -f /etc/passwd' 159t 1 '0 -ne 0 -o ! -f /etc/passwd' 160 161t 0 '-n =' 162t 1 '-z =' 163t 1 '! =' 164t 0 '-n -eq' 165t 1 '-z -eq' 166t 1 '! -eq' 167t 0 '-n -a' 168t 1 '-z -a' 169t 1 '! -a' 170t 0 '-n -o' 171t 1 '-z -o' 172t 1 '! -o' 173t 1 '! -n =' 174t 0 '! -z =' 175t 0 '! ! =' 176t 1 '! -n -eq' 177t 0 '! -z -eq' 178t 0 '! ! -eq' 179t 1 '! -n -a' 180t 0 '! -z -a' 181t 0 '! ! -a' 182t 1 '! -n -o' 183t 0 '! -z -o' 184t 0 '! ! -o' 185t 0 '\( -n = \)' 186t 1 '\( -z = \)' 187t 1 '\( ! = \)' 188t 0 '\( -n -eq \)' 189t 1 '\( -z -eq \)' 190t 1 '\( ! -eq \)' 191t 0 '\( -n -a \)' 192t 1 '\( -z -a \)' 193t 1 '\( ! -a \)' 194t 0 '\( -n -o \)' 195t 1 '\( -z -o \)' 196t 1 '\( ! -o \)' 197