xref: /freebsd/bin/test/tests/legacy_test.sh (revision d0b2dbfa)
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
32# force a specified test program, e.g. `env test=/bin/test sh regress.sh'
33: ${test=test}
34
35t ()
36{
37	# $1 -> exit code
38	# $2 -> $test expression
39
40	count=$((count+1))
41	# check for syntax errors
42	syntax="`eval $test $2 2>&1`"
43	ret=$?
44	if test -n "$syntax"; then
45		printf "not ok %s - (syntax error)\n" "$count $2"
46	elif [ "$ret" != "$1" ]; then
47		printf "not ok %s - (got $ret, expected $1)\n" "$count $2"
48	else
49		printf "ok %s\n" "$count $2"
50	fi
51}
52
53count=0
54echo "1..130"
55
56t 0 'b = b'
57t 0 'b == b'
58t 1 'b != b'
59t 0 '\( b = b \)'
60t 0 '\( b == b \)'
61t 1 '! \( b = b \)'
62t 1 '! \( b == b \)'
63t 1 '! -f /etc/passwd'
64
65t 0 '-h = -h'
66t 0 '-o = -o'
67t 1 '-f = h'
68t 1 '-h = f'
69t 1 '-o = f'
70t 1 'f = -o'
71t 0 '\( -h = -h \)'
72t 1 '\( a = -h \)'
73t 1 '\( -f = h \)'
74t 0 '-h = -h -o a'
75t 0 '\( -h = -h \) -o 1'
76t 0 '-h = -h -o -h = -h'
77t 0 '\( -h = -h \) -o \( -h = -h \)'
78t 0 'roedelheim = roedelheim'
79t 1 'potsdam = berlin-dahlem'
80
81t 0 '-d /'
82t 0 '-d / -a a != b'
83t 1 '-z "-z"'
84t 0 '-n -n'
85
86t 0 '0'
87t 0 '\( 0 \)'
88t 0 '-E'
89t 0 '-X -a -X'
90t 0 '-XXX'
91t 0 '\( -E \)'
92t 0 'true -o X'
93t 0 'true -o -X'
94t 0 '\( \( \( a = a \) -o 1 \) -a 1 \) -a true'
95t 1 '-h /'
96t 0 '-r /'
97t 1 '-w /'
98t 0 '-x /bin/sh'
99t 0 '-c /dev/null'
100t 0 '-f /etc/passwd'
101t 0 '-s /etc/passwd'
102
103t 1 '! \( 700 -le 1000 -a -n "1" -a "20" = "20" \)'
104t 0 '100 -eq 100'
105t 0 '100 -lt 200'
106t 1 '1000 -lt 200'
107t 0 '1000 -gt 200'
108t 0 '1000 -ge 200'
109t 0 '1000 -ge 1000'
110t 1 '2 -ne 2'
111t 0 '0 -eq 0'
112t 1 '-5 -eq 5'
113t 0 '\( 0 -eq 0 \)'
114t 1 '1 -eq 0 -o a = a -a 1 -eq 0 -o a = aa'
115
116t 1 '"" -o ""'
117t 1 '"" -a ""'
118t 1 '"a" -a ""'
119t 0 '"a" -a ! ""'
120t 1 '""'
121t 0 '! ""'
122
123t 0 '!'
124t 0 '\('
125t 0 '\)'
126
127t 1 '\( = \)'
128t 0 '\( != \)'
129t 0 '\( ! \)'
130t 0 '\( \( \)'
131t 0 '\( \) \)'
132t 0 '! = !'
133t 1 '! != !'
134t 1 '-n = \)'
135t 0 '! != \)'
136t 1 '! = a'
137t 0 '! != -n'
138t 0 '! -c /etc/passwd'
139
140t 1 '! = = ='
141t 0 '! = = \)'
142t 0 '! "" -o ""'
143t 1 '! "x" -o ""'
144t 1 '! "" -o "x"'
145t 1 '! "x" -o "x"'
146t 0 '\( -f /etc/passwd \)'
147t 0 '\( ! "" \)'
148t 1 '\( ! -e \)'
149
150t 0 '0 -eq 0 -a -d /'
151t 0 '-s = "" -o "" = ""'
152t 0 '"" = "" -o -s = ""'
153t 1 '-s = "" -o -s = ""'
154t 0 '-z x -o x = "#" -o x = x'
155t 1 '-z y -o y = "#" -o y = x'
156t 0 '0 -ne 0 -o ! -f /'
157t 0 '1 -ne 0 -o ! -f /etc/passwd'
158t 1 '0 -ne 0 -o ! -f /etc/passwd'
159
160t 0 '-n ='
161t 1 '-z ='
162t 1 '! ='
163t 0 '-n -eq'
164t 1 '-z -eq'
165t 1 '! -eq'
166t 0 '-n -a'
167t 1 '-z -a'
168t 1 '! -a'
169t 0 '-n -o'
170t 1 '-z -o'
171t 1 '! -o'
172t 1 '! -n ='
173t 0 '! -z ='
174t 0 '! ! ='
175t 1 '! -n -eq'
176t 0 '! -z -eq'
177t 0 '! ! -eq'
178t 1 '! -n -a'
179t 0 '! -z -a'
180t 0 '! ! -a'
181t 1 '! -n -o'
182t 0 '! -z -o'
183t 0 '! ! -o'
184t 0 '\( -n = \)'
185t 1 '\( -z = \)'
186t 1 '\( ! = \)'
187t 0 '\( -n -eq \)'
188t 1 '\( -z -eq \)'
189t 1 '\( ! -eq \)'
190t 0 '\( -n -a \)'
191t 1 '\( -z -a \)'
192t 1 '\( ! -a \)'
193t 0 '\( -n -o \)'
194t 1 '\( -z -o \)'
195t 1 '\( ! -o \)'
196