116491Swosch#!/bin/sh
2139969Simp
3139969Simp#-
417849Swosch# Copyright (c) June 1996 Wolfram Schneider <wosch@FreeBSD.org>. Berlin.
5289969Sngie# All rights reserved.
617849Swosch#
717849Swosch# Redistribution and use in source and binary forms, with or without
817849Swosch# modification, are permitted provided that the following conditions
917849Swosch# are met:
1017849Swosch# 1. Redistributions of source code must retain the above copyright
1117849Swosch#    notice, this list of conditions and the following disclaimer.
1217849Swosch# 2. Redistributions in binary form must reproduce the above copyright
1317849Swosch#    notice, this list of conditions and the following disclaimer in the
1417849Swosch#    documentation and/or other materials provided with the distribution.
1517849Swosch#
1617849Swosch# THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1717849Swosch# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1817849Swosch# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1917849Swosch# ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
2017849Swosch# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2117849Swosch# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2217849Swosch# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2317849Swosch# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2417849Swosch# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2517849Swosch# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2617849Swosch# SUCH DAMAGE.
27139969Simp
2817849Swosch#
2916491Swosch# TEST.sh - check if test(1) or builtin test works
3016491Swosch#
3150471Speter# $FreeBSD$
3216491Swosch
33215022Sjilles# force a specified test program, e.g. `env test=/bin/test sh regress.sh'
34289969Sngie: ${test=test}
3516491Swosch
3616491Swoscht ()
3716491Swosch{
3816491Swosch	# $1 -> exit code
3916491Swosch	# $2 -> $test expression
4016491Swosch
41215022Sjilles	count=$((count+1))
4216491Swosch	# check for syntax errors
4316491Swosch	syntax="`eval $test $2 2>&1`"
44215022Sjilles	ret=$?
45215022Sjilles	if test -n "$syntax"; then
46215022Sjilles		printf "not ok %s - (syntax error)\n" "$count $2"
47215022Sjilles	elif [ "$ret" != "$1" ]; then
48215022Sjilles		printf "not ok %s - (got $ret, expected $1)\n" "$count $2"
4916491Swosch	else
50215022Sjilles		printf "ok %s\n" "$count $2"
5116491Swosch	fi
5216491Swosch}
5316491Swosch
54215022Sjillescount=0
55251208Sjillesecho "1..130"
5616491Swosch
57289969Sngiet 0 'b = b'
58289969Sngiet 0 'b == b'
59289969Sngiet 1 'b != b'
60289969Sngiet 0 '\( b = b \)'
61289969Sngiet 0 '\( b == b \)'
62289969Sngiet 1 '! \( b = b \)'
63289969Sngiet 1 '! \( b == b \)'
6416491Swoscht 1 '! -f /etc/passwd'
6516491Swosch
6616491Swoscht 0 '-h = -h'
6716491Swoscht 0 '-o = -o'
6816491Swoscht 1 '-f = h'
6916491Swoscht 1 '-h = f'
7016491Swoscht 1 '-o = f'
7116491Swoscht 1 'f = -o'
7216491Swoscht 0 '\( -h = -h \)'
7316491Swoscht 1 '\( a = -h \)'
7416491Swoscht 1 '\( -f = h \)'
7516491Swoscht 0 '-h = -h -o a'
7616491Swoscht 0 '\( -h = -h \) -o 1'
7716491Swoscht 0 '-h = -h -o -h = -h'
7816491Swoscht 0 '\( -h = -h \) -o \( -h = -h \)'
7920970Swoscht 0 'roedelheim = roedelheim'
8020970Swoscht 1 'potsdam = berlin-dahlem'
8116491Swosch
8216491Swoscht 0 '-d /'
8316491Swoscht 0 '-d / -a a != b'
8416491Swoscht 1 '-z "-z"'
8516491Swoscht 0 '-n -n'
8616491Swosch
8716491Swoscht 0 '0'
8816491Swoscht 0 '\( 0 \)'
8916491Swoscht 0 '-E'
9016491Swoscht 0 '-X -a -X'
9116491Swoscht 0 '-XXX'
9216491Swoscht 0 '\( -E \)'
9316491Swoscht 0 'true -o X'
9416491Swoscht 0 'true -o -X'
9516491Swoscht 0 '\( \( \( a = a \) -o 1 \) -a 1 \) -a true'
9616491Swoscht 1 '-h /'
9716491Swoscht 0 '-r /'
9816491Swoscht 1 '-w /'
9916491Swoscht 0 '-x /bin/sh'
10016491Swoscht 0 '-c /dev/null'
10116491Swoscht 0 '-f /etc/passwd'
10216491Swoscht 0 '-s /etc/passwd'
10320970Swosch
10416491Swoscht 1 '! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)'
10516491Swoscht 0 '100 -eq 100'
10616491Swoscht 0 '100 -lt 200'
10716491Swoscht 1 '1000 -lt 200'
10816491Swoscht 0 '1000 -gt 200'
10916491Swoscht 0 '1000 -ge 200'
11016491Swoscht 0 '1000 -ge 1000'
11116491Swoscht 1 '2 -ne 2'
11220970Swoscht 0 '0 -eq 0'
11320970Swoscht 1 '-5 -eq 5'
11420970Swoscht 0 '\( 0 -eq 0 \)'
11520970Swoscht 1 '1 -eq 0 -o a = a -a 1 -eq 0 -o a = aa'
11616491Swosch
11720970Swoscht 1 '"" -o ""'
11820970Swoscht 1 '"" -a ""'
11920970Swoscht 1 '"a" -a ""'
12020970Swoscht 0 '"a" -a ! ""'
12120970Swoscht 1 '""'
12220970Swoscht 0 '! ""'
12320970Swosch
124192862Sjillest 0 '!'
125192862Sjillest 0 '\('
126192862Sjillest 0 '\)'
127192862Sjilles
128192862Sjillest 1 '\( = \)'
129192862Sjillest 0 '\( != \)'
130192862Sjillest 0 '\( ! \)'
131192862Sjillest 0 '\( \( \)'
132192862Sjillest 0 '\( \) \)'
133192862Sjillest 0 '! = !'
134192862Sjillest 1 '! != !'
135192862Sjillest 1 '-n = \)'
136192862Sjillest 0 '! != \)'
137192862Sjillest 1 '! = a'
138192862Sjillest 0 '! != -n'
139192862Sjillest 0 '! -c /etc/passwd'
140192862Sjilles
141192862Sjillest 1 '! = = ='
142192862Sjillest 0 '! = = \)'
143192862Sjillest 0 '! "" -o ""'
144192862Sjillest 1 '! "x" -o ""'
145192862Sjillest 1 '! "" -o "x"'
146192862Sjillest 1 '! "x" -o "x"'
147192862Sjillest 0 '\( -f /etc/passwd \)'
148192862Sjillest 0 '\( ! "" \)'
149192862Sjillest 1 '\( ! -e \)'
150192862Sjilles
151192862Sjillest 0 '0 -eq 0 -a -d /'
152192862Sjillest 0 '-s = "" -o "" = ""'
153192862Sjillest 0 '"" = "" -o -s = ""'
154192862Sjillest 1 '-s = "" -o -s = ""'
155192862Sjillest 0 '-z x -o x = "#" -o x = x'
156192862Sjillest 1 '-z y -o y = "#" -o y = x'
157192862Sjillest 0 '0 -ne 0 -o ! -f /'
158192862Sjillest 0 '1 -ne 0 -o ! -f /etc/passwd'
159192862Sjillest 1 '0 -ne 0 -o ! -f /etc/passwd'
160228109Sjilles
161228109Sjillest 0 '-n ='
162228109Sjillest 1 '-z ='
163228109Sjillest 1 '! ='
164228109Sjillest 0 '-n -eq'
165228109Sjillest 1 '-z -eq'
166228109Sjillest 1 '! -eq'
167228109Sjillest 0 '-n -a'
168228109Sjillest 1 '-z -a'
169228109Sjillest 1 '! -a'
170228109Sjillest 0 '-n -o'
171228109Sjillest 1 '-z -o'
172228109Sjillest 1 '! -o'
173228109Sjillest 1 '! -n ='
174228109Sjillest 0 '! -z ='
175228109Sjillest 0 '! ! ='
176228109Sjillest 1 '! -n -eq'
177228109Sjillest 0 '! -z -eq'
178228109Sjillest 0 '! ! -eq'
179228109Sjillest 1 '! -n -a'
180228109Sjillest 0 '! -z -a'
181228109Sjillest 0 '! ! -a'
182228109Sjillest 1 '! -n -o'
183228109Sjillest 0 '! -z -o'
184228109Sjillest 0 '! ! -o'
185228109Sjillest 0 '\( -n = \)'
186228109Sjillest 1 '\( -z = \)'
187228109Sjillest 1 '\( ! = \)'
188228109Sjillest 0 '\( -n -eq \)'
189228109Sjillest 1 '\( -z -eq \)'
190228109Sjillest 1 '\( ! -eq \)'
191228109Sjillest 0 '\( -n -a \)'
192228109Sjillest 1 '\( -z -a \)'
193228109Sjillest 1 '\( ! -a \)'
194228109Sjillest 0 '\( -n -o \)'
195228109Sjillest 1 '\( -z -o \)'
196228109Sjillest 1 '\( ! -o \)'
197